Generative AI Series

Retrieval Augmented Generation(RAG) — Chatbot for Youtube with LlamaIndex

Implement the RAG technique using Langchain, and LlamaIndex for conversational chatbot on YouTube.

A B Vijay Kumar
4 min readFeb 12, 2024


This blog is an ongoing series on GenerativeAI and is a continuation of the previous blog, which talks about the RAG pattern and how RAG is used to augment prompts and enhance the content and context of an LLM, with specific data.

In this blog, we will build a Q&A chatbot for content fetched from YouTube. We will be using the LlamaIndex reader YoutubeTranscriptReader

Please go through the following blogs

  1. Prompt Engineering: Retrieval Augmented Generation(RAG)
  2. Retrieval Augmented Generation(RAG) — Chatbot for documents with LlamaIndex
  3. Retrieval Augmented Generation(RAG) — Chatbot for Database (Text2SQL)
  4. Retrieval Augmented Generation(RAG) — Chatbot for Wikipedia with LlamaIndex

Let’s walk through the code. I won’t be walking through all the code, as it is very similar to what I had published and explained in my previous blogs. I will just call out specific changes made.

The following screenshot shows the requirements.txt. We will be using llama-hub to use the YoutubeTranscriptReader. We will also be using youtube_transcript_api.

The implementation is very simple, using the youtube_transcript_api to extract the transcript from a YouTube video, use that to create the index, and use that for RAG.

We will be using YoutubeTranscriptReader to extract the YouTube transcript. we will be using is_youtube_video to check if the URL that is provided is a valid YouTube URL.

We will build a simple interface using Streamlit. We will have an input text field to get the YouTube URL in the sidebar, and then we will reuse the chat interface we built in previous blogs. The following code shows the sidebar and the main window.



A B Vijay Kumar

IBM Fellow, Master Inventor, Mobile, RPi & Cloud Architect & Full-Stack Programmer