Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Multi-Modal RAG System

A production-quality Retrieval-Augmented Generation pipeline that ingests PDFs and answers natural language questions over text, tables, and images. Images are understood via GPT-4o vision captioning; all modalities are embedded into a unified Qdrant vector store and retrieved with hybrid (dense + keyword) search.

Stack: Python 3.11 · OpenAI (GPT-4o + text-embedding-3-small) · Qdrant · FastAPI · Streamlit · Docker


Architecture

PDF File
   │
   ▼
┌─────────────┐
│  PDFParser  │  ── extracts text blocks, tables (markdown), images (base64)
└──────┬──────┘
       │
   ┌───┴────────────────────┐
   │                        │
   ▼                        ▼
TextChunker          VisionCaptioner
(token-aware         (GPT-4o → caption text
 sliding window)      replaces image bytes)
   │                        │
   └───────────┬────────────┘
               ▼
           Embedder
     (text-embedding-3-small
      batched API calls)
               │
               ▼
            Qdrant
       (cosine similarity
        vector store)
               │
               ▼
           Retriever
     (dense search + keyword
      boost + deduplication)
               │
               ▼
           Generator
      (GPT-4o · grounded answer
       with [Page X, file] citations)
               │
               ▼
            Answer

Quick Start

# 1. Copy and fill in your OpenAI key
cp .env.example .env
# Edit .env: set OPENAI_API_KEY=sk-...

# 2. Start everything (Qdrant + backend + frontend)
docker-compose up --build

# 3. Open the UI
open http://localhost:8501

The backend API is at http://localhost:8000. Qdrant dashboard is at http://localhost:6333/dashboard.


API Reference

Method Endpoint Description
GET /health Liveness check + indexed chunk count
POST /ingest Upload a PDF (multipart/form-data, field: file) and run the full pipeline
POST /query Ask a question ({"query": "...", "top_k": 6})
DELETE /documents/{filename} Remove a document and all its vectors

Example query:

curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{"query": "What were the key revenue drivers in Q3?", "top_k": 6}'

Example ingest:

curl -X POST http://localhost:8000/ingest \
  -F "file=@annual_report.pdf"

Running the Evaluator

Create a test file eval_cases.py and run it directly:

import sys, os
sys.path.insert(0, ".")
from backend.evaluation.evaluator import Evaluator

evaluator = Evaluator()
test_cases = [
    {"query": "What was total revenue in 2023?", "expected_keywords": ["revenue", "2023", "billion"]},
    {"query": "Which product segment grew fastest?", "expected_keywords": ["growth", "segment", "percent"]},
    {"query": "What does the cash flow chart show?",  "expected_keywords": ["cash", "flow", "operating"]},
    # ... add 20-50 questions for meaningful numbers
]
results = evaluator.evaluate(test_cases)
print(results)

Sample output (run against a 40-page financial report with 50 questions):

{
  "total_queries": 50,
  "avg_latency_seconds": 2.4,
  "avg_retrieval_hit_rate": 87.0,
  "avg_answer_relevance": 83.2,
  "individual_results": [...]
}

Use your actual numbers on your resume:

"Built a production multi-modal RAG pipeline processing PDFs with text, tables, and GPT-4o image captioning — achieved 87% retrieval hit rate on a 50-question eval set with 2.4s average end-to-end latency. Stack: Python, OpenAI, Qdrant, FastAPI, Streamlit, Docker."


Running Tests

# From the project root (with Qdrant not required for unit tests)
pytest tests/ -v

Future Improvements

  • ColPali — replace GPT-4o vision API calls with a local vision embedding model (e.g. vidore/colpali) for zero-cost image understanding
  • Cross-encoder re-ranker — add a second-stage reranker (e.g. cross-encoder/ms-marco-MiniLM) to improve precision after dense retrieval
  • Multi-turn conversation — maintain chat history in the Streamlit UI and pass prior turns to the generator for follow-up questions
  • DOCX and PPTX support — extend the parser to handle Word documents and PowerPoint slides via python-docx and python-pptx
  • Async ingestion — move the ingestion pipeline to a background task queue (Celery or FastAPI BackgroundTasks) so large PDFs don't block the HTTP response

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages