CoolFace
Apppublic

AbrahamKlb/youtube-rag-project

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

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:

  1. 1.Enter a YouTube video URL
  2. 2.Automatically transcribe and index the video content
  3. 3.Ask questions about the video in natural language
  4. 4.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

  1. 1.Clone the repository:
bash
   git clone https://github.com/yourusername/naive-rag-youtube.git
   cd naive-rag-youtube
  1. 1.Create a virtual environment:
bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. 1.Install dependencies:
bash
   pip install -r requirements.txt
  1. 1.Set up environment variables: Create a .env file in the project root:
env
   GROQ_API_KEY=your_groq_api_key_here
   QDRANT_URL=your_qdrant_cluster_url
   QDRANT_API_KEY=your_qdrant_api_key

Running the Application

CLI Version
bash
python main.py
Web Interface (Streamlit)
bash
streamlit run streamlit_app.py

🧠 How It Works

1. Video Ingestion

  1. 1.User provides a YouTube URL
  2. 2.System extracts the video ID
  3. 3.Transcript is fetched using youtube-transcript-api
  4. 4.Text is split into chunks (700 chars with 100 overlap)
  5. 5.Each chunk is embedded using sentence-transformers/all-mpnet-base-v2
  6. 6.Embeddings + metadata are stored in Qdrant

2. Question Answering

  1. 1.User asks a question in the chat interface
  2. 2.Question is embedded using the same model
  3. 3.Similarity search finds top 5 relevant chunks in Qdrant
  4. 4.Chunks + conversation history are sent to Groq LLM
  5. 5.LLM generates a contextualized answer
  6. 6.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 access
  • β€”QDRANT_URL: Your Qdrant cluster URL
  • β€”QDRANT_API_KEY: Your Qdrant API key

Available Models

  • β€”openai/gpt-oss-120b
  • β€”openai/gpt-oss-20b
  • β€”qwen/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

  1. 1.Fork the repository
  2. 2.Create a feature branch (git checkout -b feature/AmazingFeature)
  3. 3.Commit your changes (git commit -m 'Add some AmazingFeature')
  4. 4.Push to the branch (git push origin feature/AmazingFeature)
  5. 5.Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

🚨 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 .env file

⚠️ 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