# tim-ponomarev/hybrid-rag architecture

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

- Interactive diagram: https://gitdiagram.com/tim-ponomarev/hybrid-rag
- Repository: https://github.com/tim-ponomarev/hybrid-rag

## Overview

hybrid-rag is a document-grounded question-answering system: ingest documents into overlapping chunks and index them for lexical and dense search; a query runs both retrieval methods, merges rankings with reciprocal rank fusion, reranks candidates, and generates a cited answer. Its separate evaluation workflow measures retrieval quality and uses an LLM judge for faithfulness, relevance, and coverage. The main control-flow links are visible in the excerpts; the README documents the product capabilities. The in-memory dense retriever is documented as an alternative, but its runtime wiring is not shown.

Main entry points: [`src/pipeline.py`](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/pipeline.py) (RAG pipeline), [`src/retrieval.py`](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py) (Dense search), [`src/ingest.py`](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/ingest.py) (Chunk and index), [`src/eval.py`](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/eval.py) (Evaluation harness)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document ingestion"]
  node_ingest["Chunk and index<br/>[ingest.py]"]
  node_qdrant[("Qdrant collection")]
  node_bm25_corpus["BM25 corpus file"]
end

subgraph group_retrieval["Hybrid retrieval"]
  node_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_bm25["BM25 search<br/>[retrieval.py]"]
  node_dense["Dense search<br/>[retrieval.py]"]
  node_rrf["Rank fusion<br/>[retrieval.py]"]
  node_memory_dense["In-memory dense"]
  node_reranker["Cross-encoder reranker<br/>[rerank.py]"]
end

subgraph group_answering["Answer generation"]
  node_generation["Cited answer generation<br/>[generate.py]"]
end

subgraph group_evaluation["Quality evaluation"]
  node_eval_harness["Evaluation harness<br/>[eval.py]"]
  node_judge["LLM quality judge<br/>[judge.py]"]
end

node_corpus_author(("Corpus provider"))
node_query_user(("Query user"))
node_answer_user(("Answer recipient"))
node_eval_user(("Evaluation operator"))
node_openai{{"OpenAI API"}}

node_corpus_author -->|"provides documents"| node_ingest
node_ingest -->|"upserts vectors"| node_qdrant
node_ingest -->|"writes chunks"| node_bm25_corpus
node_query_user -->|"submits query"| node_pipeline
node_pipeline -->|"constructs and searches"| node_bm25
node_pipeline -->|"constructs and searches"| node_dense
node_bm25 -->|"indexes corpus"| node_bm25_corpus
node_dense -->|"searches collection"| node_qdrant
node_bm25 -->|"ranked candidates"| node_rrf
node_dense -->|"ranked candidates"| node_rrf
node_pipeline -->|"reranks candidates"| node_reranker
node_pipeline -->|"generates answer"| node_generation
node_generation -->|"requests completion"| node_openai
node_pipeline -->|"returns answer"| node_answer_user
node_eval_user -->|"runs evaluation"| node_eval_harness
node_eval_harness -->|"evaluates queries"| node_pipeline
node_eval_harness -->|"scores answers"| node_judge
node_judge -->|"requests scores"| node_openai
node_memory_dense -.->|"alternative implementation"| node_dense

click node_ingest "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/ingest.py"
click node_pipeline "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/pipeline.py"
click node_bm25 "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py"
click node_dense "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py"
click node_rrf "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py"
click node_memory_dense "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval_inmemory.py"
click node_reranker "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/rerank.py"
click node_generation "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/generate.py"
click node_eval_harness "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/eval.py"
click node_judge "https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/judge.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_ingest,node_qdrant,node_bm25_corpus,node_query_user toneBlue
class node_pipeline,node_bm25,node_dense,node_rrf,node_memory_dense,node_reranker toneAmber
class node_generation,node_openai toneMint
class node_eval_harness,node_judge toneRose
class node_corpus_author,node_answer_user,node_eval_user toneIndigo
```

## Components

### Document ingestion

- [Chunk and index](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/ingest.py): `src/ingest.py`
- **Qdrant collection**
- **BM25 corpus file**

### Hybrid retrieval

- [RAG pipeline](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/pipeline.py): `src/pipeline.py`
- [BM25 search](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py): `src/retrieval.py`
- [Dense search](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py): `src/retrieval.py`
- [Rank fusion](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval.py): `src/retrieval.py`
- [In-memory dense](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/retrieval_inmemory.py): `src/retrieval_inmemory.py`
- [Cross-encoder reranker](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/rerank.py): `src/rerank.py`

### Answer generation

- [Cited answer generation](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/generate.py): `src/generate.py`

### Quality evaluation

- [Evaluation harness](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/eval.py): `src/eval.py`
- [LLM quality judge](https://github.com/tim-ponomarev/hybrid-rag/blob/main/src/judge.py): `src/judge.py`

### Other components

- **Corpus provider**
- **Query user**
- **Answer recipient**
- **Evaluation operator**
- **OpenAI API**

## Connections

- Corpus provider → Chunk and index: provides documents (evidence: `README.md`)
- Chunk and index → Qdrant collection: upserts vectors (evidence: `src/ingest.py`)
- Chunk and index → BM25 corpus file: writes chunks (evidence: `src/ingest.py`)
- Query user → RAG pipeline: submits query (evidence: `src/pipeline.py`)
- RAG pipeline → BM25 search: constructs and searches (evidence: `src/pipeline.py`)
- RAG pipeline → Dense search: constructs and searches (evidence: `src/pipeline.py`)
- BM25 search → BM25 corpus file: indexes corpus
- Dense search → Qdrant collection: searches collection (evidence: `README.md`)
- BM25 search → Rank fusion: ranked candidates (evidence: `src/retrieval.py`)
- Dense search → Rank fusion: ranked candidates (evidence: `src/retrieval.py`)
- RAG pipeline → Cross-encoder reranker: reranks candidates (evidence: `src/pipeline.py`)
- RAG pipeline → Cited answer generation: generates answer (evidence: `src/pipeline.py`)
- Cited answer generation → OpenAI API: requests completion (evidence: `src/generate.py`)
- RAG pipeline → Answer recipient: returns answer (evidence: `src/pipeline.py`)
- Evaluation operator → Evaluation harness: runs evaluation (evidence: `README.md`)
- Evaluation harness → RAG pipeline: evaluates queries (evidence: `src/eval.py`)
- Evaluation harness → LLM quality judge: scores answers (evidence: `src/eval.py`)
- LLM quality judge → OpenAI API: requests scores (evidence: `src/judge.py`)
- In-memory dense → Dense search: alternative implementation (evidence: `src/retrieval_inmemory.py`)
