# shaks20/rag_scaleable_10k architecture

> Architecture diagram of the GitHub repository shaks20/rag_scaleable_10k, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shaks20/rag_scaleable_10k
- Repository: https://github.com/shaks20/rag_scaleable_10k

## Overview

#### 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: [`api/main.py`](https://github.com/shaks20/rag_scaleable_10k/blob/master/api/main.py) (Query API), [`docker-compose.yml`](https://github.com/shaks20/rag_scaleable_10k/blob/master/docker-compose.yml) (Docker Compose), [`ingestion/worker.py`](https://github.com/shaks20/rag_scaleable_10k/blob/master/ingestion/worker.py) (Ingestion worker), [`seed_queue.py`](https://github.com/shaks20/rag_scaleable_10k/blob/master/seed_queue.py) (Batch producer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Ingestion pipeline"]
  node_corpus_download["Corpus acquisition<br/>corpus downloader<br/>[download_corpus.py]"]
  node_seed_queue["Batch producer<br/>job publisher<br/>[seed_queue.py]"]
  node_redis["Redis<br/>Celery broker"]
  node_worker["Ingestion worker<br/>Celery worker<br/>[worker.py]"]
end

subgraph group_query["Query serving"]
  node_frontend["Streamlit client<br/>user interface<br/>[app.py]"]
  node_api["Query API<br/>FastAPI backend<br/>[main.py]"]
  node_reranker["Cross-encoder reranker<br/>local PyTorch model"]
  node_groq{{"Groq Llama<br/>external LLM"}}
end

subgraph group_evaluation["Evaluation"]
  node_synthetic_data["Synthetic QA generator<br/>data generator<br/>[synthetic_data.py]"]
  node_qa_data["Synthetic QA dataset<br/>evaluation data"]
  node_evaluation_runner["Live evaluator<br/>LLM-as-judge evaluation<br/>[eval.py]"]
end

node_compose{{"Docker Compose<br/>orchestrator<br/>[docker-compose.yml]"}}
node_image["Application image<br/>container build"]
node_embedding_model["MiniLM embeddings<br/>local HuggingFace model"]
node_qdrant[("Qdrant<br/>vector database")]

node_compose -->|"builds"| node_image
node_compose -->|"runs"| node_api
node_compose -->|"runs"| node_frontend
node_compose -->|"runs"| node_worker
node_compose -->|"runs"| node_redis
node_compose -->|"runs"| node_qdrant
node_corpus_download -->|"supplies corpus"| node_seed_queue
node_seed_queue -->|"publishes jobs"| node_redis
node_redis -->|"dispatches jobs"| node_worker
node_worker -->|"embeds chunks"| node_embedding_model
node_worker -->|"upserts vectors"| node_qdrant
node_frontend -->|"submits question"| node_api
node_api -->|"embeds query"| node_embedding_model
node_api -->|"retrieves top 15"| node_qdrant
node_api -->|"reranks contexts"| node_reranker
node_api -.->|"sends top 3 and question"| node_groq
node_groq -->|"returns answer"| node_api
node_synthetic_data -->|"generates"| node_qa_data
node_qa_data -->|"provides cases"| node_evaluation_runner
node_evaluation_runner -->|"exercises live path"| node_api

click node_compose "https://github.com/shaks20/rag_scaleable_10k/blob/master/docker-compose.yml"
click node_image "https://github.com/shaks20/rag_scaleable_10k/tree/master/Dockerfile"
click node_corpus_download "https://github.com/shaks20/rag_scaleable_10k/blob/master/download_corpus.py"
click node_seed_queue "https://github.com/shaks20/rag_scaleable_10k/blob/master/seed_queue.py"
click node_worker "https://github.com/shaks20/rag_scaleable_10k/blob/master/ingestion/worker.py"
click node_frontend "https://github.com/shaks20/rag_scaleable_10k/blob/master/frontend/app.py"
click node_api "https://github.com/shaks20/rag_scaleable_10k/blob/master/api/main.py"
click node_synthetic_data "https://github.com/shaks20/rag_scaleable_10k/blob/master/synthetic_data.py"
click node_qa_data "https://github.com/shaks20/rag_scaleable_10k/blob/master/synthetic_test_data.csv"
click node_evaluation_runner "https://github.com/shaks20/rag_scaleable_10k/blob/master/eval.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_corpus_download,node_seed_queue,node_redis,node_worker toneBlue
class node_frontend,node_api,node_reranker,node_groq toneAmber
class node_synthetic_data,node_qa_data,node_evaluation_runner toneMint
class node_compose,node_image,node_embedding_model,node_qdrant toneNeutral
```

## Components

### Ingestion pipeline

Asynchronous corpus processing.

- [Corpus acquisition](https://github.com/shaks20/rag_scaleable_10k/blob/master/download_corpus.py): corpus downloader · `download_corpus.py`
- [Batch producer](https://github.com/shaks20/rag_scaleable_10k/blob/master/seed_queue.py): job publisher · Publishes lightweight document jobs. · `seed_queue.py`
- **Redis**: Celery broker · Carries ingestion jobs.
- [Ingestion worker](https://github.com/shaks20/rag_scaleable_10k/blob/master/ingestion/worker.py): Celery worker · Extracts, chunks, embeds, and upserts documents. · `ingestion/worker.py`

### Query serving

Latency-sensitive grounded answering path.

- [Streamlit client](https://github.com/shaks20/rag_scaleable_10k/blob/master/frontend/app.py): user interface · `frontend/app.py`
- [Query API](https://github.com/shaks20/rag_scaleable_10k/blob/master/api/main.py): FastAPI backend · Coordinates retrieval, reranking, and answer synthesis. · `api/main.py`
- **Cross-encoder reranker**: local PyTorch model · Reduces broad retrieval results to top contexts.
- **Groq Llama**: external LLM · Receives only the question and selected passages.

### Evaluation

Live end-to-end quality validation.

- [Synthetic QA generator](https://github.com/shaks20/rag_scaleable_10k/blob/master/synthetic_data.py): data generator · `synthetic_data.py`
- [Synthetic QA dataset](https://github.com/shaks20/rag_scaleable_10k/blob/master/synthetic_test_data.csv): evaluation data · `synthetic_test_data.csv`
- [Live evaluator](https://github.com/shaks20/rag_scaleable_10k/blob/master/eval.py): LLM-as-judge evaluation · Measures context precision and answer faithfulness through the active API. · `eval.py`

### Other components

- [Docker Compose](https://github.com/shaks20/rag_scaleable_10k/blob/master/docker-compose.yml): orchestrator · Runs application services and backing infrastructure. · `docker-compose.yml`
- [Application image](https://github.com/shaks20/rag_scaleable_10k/tree/master/Dockerfile): container build · `Dockerfile`
- **MiniLM embeddings**: local HuggingFace model · Embeds documents and queries locally.
- **Qdrant**: vector database · Persists embeddings and source metadata.

## Connections

- 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
