Skip to content
akash4426Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

πŸŽ₯ Video RAG: Semantic Video Search & AI Summarization

GitHub Repo Python License

Transform your videos into searchable, explainable knowledge with AI

Features β€’ Demo β€’ Installation β€’ Usage β€’ How It Works


🌟 Overview

Video RAG is a powerful Retrieval-Augmented Generation system that enables semantic search within videos using natural language. Simply upload a video, ask a question, and get relevant frames with AI-generated summariesβ€”no manual scrubbing required!

🎯 What Makes This Special?

  • πŸ” Natural Language Search: Query videos like "person wearing red jacket" or "car accident"
  • ⚑ Lightning Fast: FAISS-powered similarity search through thousands of frames
  • 🧠 AI Summaries: Context-aware explanations powered by Google's Gemini
  • 🎬 Video Clips: Extract and download specific scenes automatically
  • πŸ’Ύ Smart Caching: Process once, search instantly on subsequent runs

✨ Features

Core Capabilities

Feature Description
🎞️ Multi-Format Support Upload .mp4, .mov, .avi videos
βš™οΈ Configurable Sampling Adjust FPS (0.5-5) for speed vs. accuracy trade-off
πŸ” Semantic Search CLIP-powered understanding of visual content
πŸ“Š Visual Results Storyboard view + individual frames with timestamps
🎬 Clip Extraction Download matched video segments
πŸ’¬ AI Summaries Gemini-generated contextual explanations
πŸ—‚οΈ Smart Caching Skip re-processing for previously analyzed videos
πŸ“ˆ Research Metrics Comprehensive evaluation metrics for academic papers

Advanced Features

  • Batch Processing: Efficient GPU utilization for large videos
  • Progress Tracking: Real-time feedback during processing
  • Multiple Models: Choose between CLIP variants for different use cases
  • Responsive UI: Clean, intuitive interface with sidebar controls
  • Research Evaluation: Calculate Top-K Retrieval %, MAP, MRR, NDCG, Precision@K, Recall@K

πŸ“Š Research Metrics

Video RAG now includes comprehensive retrieval metrics suitable for research papers and academic evaluation:

Available Metrics

Metric Description Use Case
Top-K Retrieval % Percentage of relevant chunks found in top-K results Primary metric for retrieval coverage
Precision@K Fraction of top-K results that are relevant Measures result quality
Recall@K Fraction of all relevant items found in top-K Measures completeness
Mean Average Precision (MAP) Average precision across all relevant positions Overall ranking quality
Mean Reciprocal Rank (MRR) Inverse rank of first relevant item Early precision metric
NDCG@K Normalized Discounted Cumulative Gain Position-aware ranking quality
Avg Similarity Score Mean similarity of top-K results Confidence measure

Using Metrics

  1. Enable Metrics in the sidebar under "πŸ“Š Research Metrics"
  2. Provide Ground Truth (optional): Enter comma-separated frame IDs that are relevant to your query
    • Example: 120,450,780,1200
  3. Run Search as usual
  4. View Metrics in the expandable "πŸ“Š Retrieval Metrics" section
  5. Export Results as JSON or CSV for research papers

Example Usage

# In the UI, enable metrics and provide ground truth
Ground Truth Frame IDs: 120,450,780,1200

# After search, view metrics:
# 🎯 Top-K Retrieval: 75.0%
#   - 3/4 relevant chunks found in top-5
# πŸ“ˆ Precision@5: 0.6000
# πŸ“Š Recall@5: 0.7500
# ⭐ Average Precision: 0.7083
# πŸ” Reciprocal Rank: 1.0000
# πŸ† NDCG@5: 0.8631
# πŸ’― Avg Similarity Score: 0.8543

Export Formats

  • JSON: Detailed metrics with metadata, timestamps
  • CSV: Simple table format for Excel/analysis tools

🎬 Demo

Example Workflow

1. Upload: city_traffic.mp4
2. Query: "red car at intersection"
3. Results: 3 matched frames at [0:45, 1:23, 2:08]
4. Summary: "A red sedan waits at a traffic light during rush hour..."

Screenshots

πŸ“Έ Click to view screenshots

Search Interface Search Interface

Frame Results Frame Results

AI Summary AI Summary

πŸ’‘ Tip: Add actual screenshots to a screenshots/ folder in your repo


πŸš€ Installation

Prerequisites

  • Python 3.10 or higher
  • 4GB+ RAM recommended
  • (Optional) GPU for faster processing

Quick Start

# 1. Clone the repository
git clone https://github.com/akash4426/Video_RAG.git
cd Video_RAG

# 2. Create virtual environment
python -m venv venv

# Activate (macOS/Linux)
source venv/bin/activate

# Activate (Windows)
.\venv\Scripts\activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Run the app
streamlit run app.py

System Dependencies

macOS:

brew install ffmpeg

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install ffmpeg libsm6 libxext6 libgl1

Windows: Download FFmpeg from ffmpeg.org and add to PATH


πŸ”‘ Configuration

Gemini API Setup

  1. Get your API key from Google AI Studio
  2. Add to Streamlit secrets:

Local Development: Create .streamlit/secrets.toml:

GEMINI_API_KEY = "your-api-key-here"

Streamlit Cloud:

  • Go to App Settings β†’ Secrets
  • Add: GEMINI_API_KEY = "your-key"

Environment Variables

# Optional: Set cache directory
export VIDEORAG_CACHE_DIR=/path/to/cache

# Optional: Set device
export TORCH_DEVICE=cuda  # or cpu, mps

πŸ“– Usage

Basic Search

# 1. Upload video through UI
# 2. Enter query: "person walking dog"
# 3. View matched frames + timestamps
# 4. Generate AI summary (optional)

Advanced Options

Setting Description Default
Model CLIP variant clip-vit-base-patch32
Sampling FPS Frames per second 1.0
Batch Size GPU batch processing 16
Top K Number of results 3
Clip Window Context duration (sec) 2.0

Example Queries

  • βœ… "person wearing blue shirt"
  • βœ… "car accident on highway"
  • βœ… "sunset over ocean"
  • βœ… "group of people dancing"
  • ❌ "the color blue" (too abstract)
  • ❌ "video from 2020" (no temporal reasoning)

🧠 How It Works

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Video Input β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Frame Extractionβ”‚  ← OpenCV samples at specified FPS
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ CLIP Embeddings β”‚  ← Convert frames to 512-D vectors
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  FAISS Indexing β”‚  ← Build similarity search index
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Text Query     β”‚  ← User input converted to embedding
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Similarity      β”‚  ← Find nearest neighbors
β”‚ Search          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Gemini Summary  β”‚  ← Generate natural language explanation
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Technologies

1. CLIP (OpenAI)

  • Purpose: Multimodal embeddings (vision + language)
  • How: Contrastive learning on 400M image-text pairs
  • Output: 512-dimensional vectors for both images and text

2. FAISS (Facebook AI)

  • Purpose: Efficient similarity search
  • How: Approximate nearest neighbor algorithms
  • Speed: Sub-millisecond search on millions of vectors

3. Gemini (Google)

  • Purpose: Multimodal AI summarization
  • How: Analyzes multiple frames + text context
  • Output: Natural language descriptions

Performance

Metric Value
1 min video @ 1 FPS ~60 frames, 2-3 sec processing
Search latency < 100ms
Memory usage ~500MB + video size
Cache size ~7MB per hour of video

🧩 Project Structure

Video_RAG/
β”œβ”€β”€ app.py                 # Main Streamlit application
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ packages.txt          # System dependencies
β”œβ”€β”€ runtime.txt           # Python version
β”œβ”€β”€ .streamlit/
β”‚   β”œβ”€β”€ config.toml       # UI configuration
β”‚   └── secrets.toml      # API keys (gitignored)
β”œβ”€β”€ screenshots/          # Demo images
β”œβ”€β”€ README.md
└── LICENSE

πŸ“Š Comparison with Alternatives

Feature Video RAG YouTube Search Manual Scrubbing
Semantic Understanding βœ… ⚠️ Metadata only ❌
Speed βœ… Instant βœ… ❌ Very slow
Offline Support βœ… ❌ βœ…
AI Summaries βœ… ❌ ❌
Custom Videos βœ… ❌ Public only βœ…

πŸ› οΈ Development

Running Tests

# Install dev dependencies
pip install pytest pytest-cov

# Run tests
pytest tests/

# With coverage
pytest --cov=app tests/

Code Quality

# Format code
black app.py

# Lint
flake8 app.py

# Type checking
mypy app.py

🀝 Contributing

Contributions are welcome! Here's how you can help:

Ways to Contribute

  • πŸ› Report bugs via Issues
  • πŸ’‘ Suggest features through Discussions
  • πŸ“ Improve documentation
  • πŸ”§ Submit pull requests

Development Workflow

# 1. Fork the repository
# 2. Create feature branch
git checkout -b feature/amazing-feature

# 3. Make changes and commit
git commit -m "Add amazing feature"

# 4. Push to your fork
git push origin feature/amazing-feature

# 5. Open a Pull Request

πŸ“ Use Cases

πŸŽ“ Education

  • Navigate lecture videos by topic
  • Find specific demonstrations or examples

🎬 Content Creation

  • Locate B-roll footage quickly
  • Find specific scenes for editing

πŸ”’ Security

  • Search surveillance footage by description
  • Incident investigation and analysis

πŸ“Š Research & Academia

  • Analyze video datasets semantically
  • Extract frames for annotation
  • Evaluate retrieval algorithms with comprehensive metrics
  • Benchmark video search systems with Top-K Retrieval %
  • Generate research paper results with exportable metrics (JSON/CSV)
  • Compare different CLIP models using standardized evaluation

🏒 Business

  • Meeting recap and highlight extraction
  • Training video search and organization

🚧 Roadmap

  • Export results as JSON/CSV βœ…
  • Research metrics (Top-K Retrieval %, MAP, MRR, NDCG, etc.) βœ…
  • Multi-video search across video library
  • Object tracking across frames
  • Audio transcription integration (Whisper)
  • OCR for on-screen text
  • Batch evaluation mode for research datasets
  • Docker containerization
  • REST API endpoint
  • Mobile-responsive UI

πŸ“„ License

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


πŸ™ Acknowledgments


πŸ‘€ Author

Akash Karri


⭐ Star History

Star History Chart


πŸ“ˆ Stats

GitHub stars GitHub forks GitHub watchers


Made with ❀️ by Akash Karri

If you found this project helpful, consider giving it a ⭐!

Report Bug β€’ Request Feature

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages