AbrahamKlb/youtube-rag-project
0
Naive RAG YouTube
A Retrieval-Augmented Generation (RAG) application that allows you to chat with the content of YouTube videos using AI.
π― Overview
This project enables you to:
- Enter a YouTube video URL
- Automatically transcribe and index the video content
- Ask questions about the video in natural language
- Get AI-generated answers based on the actual video content
It combines several technologies:
- YouTube Transcript API for video transcription
- Sentence Transformers for text embedding
- Qdrant for vector storage and similarity search
- Groq for fast LLM inference
- Streamlit for the web interface
ποΈ Architecture
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β YouTube URL βββββΆβ Transcript API βββββΆβ Text Chunks β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β User Question βββββΆβ Embedding Model βββββΆβ Similarity β
βββββββββββββββββββ ββββββββββββββββββββ β Search β
ββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β Qdrant DB βββββΆβ Relevant Chunks βββββΆβ Groq LLM β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β AI Answer β
ββββββββββββββββββββπ Project Structure
naive-rag/
βββ main.py # Main CLI entry point
βββ streamlit_app.py # Streamlit web interface
βββ src/
β βββ youtube.py # YouTube URL handling and transcription
β βββ embedding.py # Text chunking and embedding
β βββ qdrant.py # Vector database operations
β βββ retrieve.py # Similarity search in Qdrant
β βββ query.py # LLM query generation
β βββ grok.py # Groq API client
β βββ prompt.py # Prompt templates
β βββ loggings.py # Logging configuration
βββ downloads/ # Temporary storage for transcripts
βββ requirements.txt # Python dependenciesπ Getting Started
Prerequisites
- Python 3.10+
- A Groq API key (free at groq.com)
- A Qdrant Cloud account (free tier available at qdrant.tech)
Installation
- Clone the repository:
git clone https://github.com/yourusername/naive-rag-youtube.git
cd naive-rag-youtube- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables: Create a
.envfile in the project root:
GROQ_API_KEY=your_groq_api_key_here
QDRANT_URL=your_qdrant_cluster_url
QDRANT_API_KEY=your_qdrant_api_keyRunning the Application
CLI Version
python main.pyWeb Interface (Streamlit)
streamlit run streamlit_app.pyπ§ How It Works
1. Video Ingestion
- User provides a YouTube URL
- System extracts the video ID
- Transcript is fetched using
youtube-transcript-api - Text is split into chunks (700 chars with 100 overlap)
- Each chunk is embedded using
sentence-transformers/all-mpnet-base-v2 - Embeddings + metadata are stored in Qdrant
2. Question Answering
- User asks a question in the chat interface
- Question is embedded using the same model
- Similarity search finds top 5 relevant chunks in Qdrant
- Chunks + conversation history are sent to Groq LLM
- LLM generates a contextualized answer
- Answer is displayed to the user
3. Key Features
- Automatic Ingestion: Videos are processed on first query
- Conversation Context: Maintains chat history for coherent responses
- Model Selection: Choose between different Groq models
- Generation Parameters: Adjustable temperature and max tokens
- Multi-language Support: Handles videos in different languages
βοΈ Configuration
Environment Variables
GROQ_API_KEY: Your Groq API key for LLM accessQDRANT_URL: Your Qdrant cluster URLQDRANT_API_KEY: Your Qdrant API key
Available Models
openai/gpt-oss-120bopenai/gpt-oss-20bqwen/qwen3-32b
Adjustable Parameters
- Temperature: Controls randomness (0.0 = deterministic, 1.0 = creative)
- Max Tokens: Maximum length of generated response
π οΈ Development
Main Modules
src/youtube.py
- Extracts video ID from YouTube URLs
- Saves transcripts to text files
src/embedding.py
- Splits text into manageable chunks
- Generates embeddings using Sentence Transformers
- Stores embeddings in Qdrant
src/qdrant.py
- Manages connection to Qdrant vector database
- Creates collections and indexes
- Handles upsert and search operations
src/retrieve.py
- Performs similarity search in Qdrant
- Filters results by video ID
src/query.py
- Formats prompts for the LLM
- Calls Groq API to generate responses
src/grok.py
- Wrapper for Groq API client
- Handles LLM inference
src/prompt.py
- Centralized prompt templates
- Structured prompts for better responses
Logging
All modules use structured logging to *.log files for debugging and monitoring.
π€ Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- youtube-transcript-api for easy transcript retrieval
- Sentence Transformers for powerful embeddings
- Qdrant for the excellent vector database
- Groq for blazing-fast LLM inference
- Streamlit for the simple web framework
π¨ Limitations
- Only works with videos that have transcripts available
- Performance depends on the quality of the original transcript
- Free tiers of Qdrant and Groq have usage limits
- Large videos may take time to process initially
π Privacy
- Video content is processed locally for transcription
- Only text chunks and embeddings are stored in Qdrant
- No personal data is collected or stored by the application
- API keys are stored locally in
.envfile
β οΈ Limitations
YouTube IP Blocking
When deployed on cloud platforms (Streamlit Cloud, Render, etc.), YouTube often blocks requests for transcripts due to their restrictions on cloud server IPs.
This is not a bug in the application but a limitation imposed by YouTube.
Workarounds:
- Use videos that have manually added subtitles (more likely to be accessible)
- Run the application locally on your machine
- Consider alternative data sources for production deployments
