How shaks20/rag_scaleable_10k works
Purpose and Entry Points
This repository implements a scalable Retrieval-Augmented Generation (RAG) system for ingesting large PDF/text corpora and answering grounded questions. Primary runtime entry points are the query API at api/main.py, Streamlit client at frontend/app.py, asynchronous ingestion worker at ingestion/worker.py, and batch producer seed_queue.py.
Service Topology
Docker Compose orchestrates the application services and backing infrastructure through docker-compose.yml, using a shared image definition in Dockerfile. The system separates latency-sensitive query serving from CPU/GPU-heavy ingestion:
• FastAPI serves retrieval and generation requests.
• Streamlit submits user questions to FastAPI.
• Celery workers consume ingestion jobs from Redis.
• Qdrant persists embeddings and vector-search metadata.
Ingestion Pipeline
seed_queue.py discovers or batches corpus files and publishes lightweight path/metadata jobs to Redis rather than processing documents in the API process. ingestion/worker.py is the Celery consumer boundary: it extracts document text, splits it into overlapping semantic chunks, embeds chunks with the local HuggingFace MiniLM model, and upserts vectors plus source metadata into Qdrant. Corpus acquisition is handled separately by download_corpus.py.
This queue-based design allows workers to scale independently and prevents document parsing or embedding from blocking query traffic.
Retrieval and Answering Path
frontend/app.py sends a user question to the FastAPI backend in api/main.py. The backend embeds the query, performs broad Qdrant dense-vector retrieval (Top 15), then applies a local PyTorch cross-encoder re-ranker to select the strongest contexts (Top 3). Those selected passages and a constrained anti-hallucination prompt are sent to Groq’s Llama model for final answer synthesis. The response is returned through the API to Streamlit.
The critical trust boundary is between local retrieval—which retains corpus content in local Redis/Qdrant/model processing—and external Groq generation, which receives only selected context and the question.
Models and External Services
Local HuggingFace models perform document/query embeddings (all-MiniLM-L6-v2) and cross-encoder ranking (ms-marco-MiniLM-L-6-v2). Redis is both Celery broker and task queue; Qdrant is the vector database. Groq is the external LLM inference service and requires credentials via environment configuration. Container deployment requires substantial memory because Qdrant and local PyTorch models run together.
Relevant infrastructure: docker-compose.yml, Dockerfile, requirements.txt.
Evaluation Loop
synthetic_data.py generates synthetic QA data, stored in synthetic_test_data.csv. eval.py exercises the active backend end-to-end and uses an LLM-as-judge approach to assess retrieval context precision and generated-answer faithfulness. This validates the deployed query path rather than only unit-level model behavior.
Operational Sequence
Typical operation is: acquire corpus with download_corpus.py; enqueue batches with seed_queue.py; let ingestion/worker.py populate Qdrant; start the composed API/frontend/infrastructure stack; then query through frontend/app.py or FastAPI. Evaluation runs after ingestion against the live API via eval.py.
Main entry points: main.py Query API · docker-compose.yml Docker Compose · worker.py Ingestion worker · seed_queue.py Batch producer
Components 15
Ingestion pipeline
Asynchronous corpus processing.
- Corpus acquisition
download_corpus.py - Batch producer · Publishes lightweight document jobs.
seed_queue.py - Redis · Carries ingestion jobs.
- Ingestion worker · Extracts, chunks, embeds, and upserts documents.
ingestion/worker.py
Query serving
Latency-sensitive grounded answering path.
- Streamlit client
frontend/app.py - Query API · Coordinates retrieval, reranking, and answer synthesis.
api/main.py - Cross-encoder reranker · Reduces broad retrieval results to top contexts.
- Groq Llama · Receives only the question and selected passages.
Evaluation
Live end-to-end quality validation.
- Synthetic QA generator
synthetic_data.py - Synthetic QA dataset
synthetic_test_data.csv - Live evaluator · Measures context precision and answer faithfulness through the active API.
eval.py
Other components
- Docker Compose · Runs application services and backing infrastructure.
docker-compose.yml - Application image
Dockerfile - MiniLM embeddings · Embeds documents and queries locally.
- Qdrant · Persists embeddings and source metadata.
Connections 20
- Docker Compose → Application image: builds
- Docker Compose → Query API: runs
- Docker Compose → Streamlit client: runs
- Docker Compose → Ingestion worker: runs
- Docker Compose → Redis: runs
- Docker Compose → Qdrant: runs
- Corpus acquisition → Batch producer: supplies corpus
- Batch producer → Redis: publishes jobs
- Redis → Ingestion worker: dispatches jobs
- Ingestion worker → MiniLM embeddings: embeds chunks
- Ingestion worker → Qdrant: upserts vectors
- Streamlit client → Query API: submits question
- Query API → MiniLM embeddings: embeds query
- Query API → Qdrant: retrieves top 15
- Query API → Cross-encoder reranker: reranks contexts
- Query API → Groq Llama: sends top 3 and question · External trust boundary.
- Groq Llama → Query API: returns answer
- Synthetic QA generator → Synthetic QA dataset: generates
- Synthetic QA dataset → Live evaluator: provides cases
- Live evaluator → Query API: exercises live path