# parthsharma1011/productionrag_hybrid_retrieval_bm25_cli architecture

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

- Interactive diagram: https://gitdiagram.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli
- Repository: https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli

## Overview

This is a Python RAG command-line application. Users provide PDF or text documents for ingestion, then ask questions in an interactive session: the pipeline chunks and indexes documents, retrieves candidates through dense and sparse search, optionally reranks them, and sends context plus conversation history to Gemini for an answer. The README also documents persistent indexes, query caching, memory, and reranker comparison. Relationships follow the sampled CLI and pipeline code; unsampled subsystem details are represented only where documented.

Main entry points: [`rag/pipeline.py`](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/rag/pipeline.py) (RAG pipeline), [`main.py`](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/main.py) (Interactive CLI), [`core/hybrid_search.py`](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/hybrid_search.py) (Hybrid RRF search), [`core/vector_store.py`](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/vector_store.py) (FAISS vector store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and orchestration"]
  node_cli["Interactive CLI<br/>[main.py]"]
  node_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_ingest["Document indexing"]
  node_documents["PDF and text files"]
  node_processor["Document chunking"]
  node_vector[("FAISS vector store<br/>[vector_store.py]")]
  node_bm25[("BM25 index<br/>[bm25_store.py]")]
  node_indexfiles[("Persistent indexes<br/>[vector_store.py]")]
end

subgraph group_retrieval["Hybrid retrieval"]
  node_embedding["Gemini embeddings<br/>[embeddings.py]"]
  node_search["Hybrid RRF search<br/>[hybrid_search.py]"]
  node_reranker["Cosine reranker<br/>[reranker.py]"]
end

subgraph group_answer["Answer and context"]
  node_cache[("Query cache<br/>[cache.py]")]
  node_memory["Conversation memory<br/>[memory.py]"]
  node_answer["Answer"]
end

node_user(("User"))
node_gemini["Gemini generation API"]

node_user -->|"enters questions"| node_cli
node_cli -->|"starts and routes"| node_pipeline
node_cli -->|"accepts files"| node_documents
node_pipeline -->|"loads documents"| node_processor
node_processor -->|"extracts and chunks"| node_documents
node_pipeline -->|"adds chunks"| node_vector
node_pipeline -->|"adds chunks"| node_bm25
node_vector -->|"embeds chunks"| node_embedding
node_pipeline -->|"saves or loads"| node_indexfiles
node_pipeline -->|"searches query"| node_search
node_search -->|"retrieves dense"| node_vector
node_search -->|"retrieves sparse"| node_bm25
node_pipeline -->|"reranks candidates"| node_reranker
node_reranker -->|"embeds query and docs"| node_embedding
node_pipeline -->|"checks and stores answers"| node_cache
node_pipeline -->|"formats and updates history"| node_memory
node_pipeline -->|"generates answer"| node_gemini
node_gemini -->|"returns text"| node_answer
node_pipeline -->|"returns answer"| node_cli
node_config -->|"sets runtime options"| node_pipeline

click node_cli "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/main.py"
click node_pipeline "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/rag/pipeline.py"
click node_config "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/config.py"
click node_processor "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/document_processor.py"
click node_vector "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/vector_store.py"
click node_bm25 "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/bm25_store.py"
click node_embedding "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/embeddings.py"
click node_search "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/hybrid_search.py"
click node_reranker "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/reranker.py"
click node_indexfiles "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/vector_store.py"
click node_cache "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/cache.py"
click node_memory "https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/memory.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_cli,node_pipeline,node_config,node_user toneBlue
class node_documents,node_processor,node_vector,node_bm25,node_indexfiles toneAmber
class node_embedding,node_search,node_reranker,node_gemini toneMint
class node_cache,node_memory,node_answer toneRose
```

## Components

### CLI and orchestration

- [Interactive CLI](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/main.py): `main.py`
- [RAG pipeline](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/rag/pipeline.py): `rag/pipeline.py`
- [Runtime configuration](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/config.py): `config.py`

### Document indexing

- **PDF and text files**
- [Document chunking](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/document_processor.py): `core/document_processor.py`
- [FAISS vector store](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/vector_store.py): `core/vector_store.py`
- [BM25 index](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/bm25_store.py): `core/bm25_store.py`
- [Persistent indexes](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/vector_store.py): `core/vector_store.py`

### Hybrid retrieval

- [Gemini embeddings](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/embeddings.py): `core/embeddings.py`
- [Hybrid RRF search](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/hybrid_search.py): `core/hybrid_search.py`
- [Cosine reranker](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/reranker.py): `core/reranker.py`

### Answer and context

- [Query cache](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/cache.py): `core/cache.py`
- [Conversation memory](https://github.com/parthsharma1011/productionrag_hybrid_retrieval_bm25_cli/blob/main/core/memory.py): `core/memory.py`
- **Answer**

### Other components

- **User**
- **Gemini generation API**

## Connections

- User → Interactive CLI: enters questions (evidence: `main.py`)
- Interactive CLI → RAG pipeline: starts and routes (evidence: `main.py`)
- Interactive CLI → PDF and text files: accepts files (evidence: `main.py`)
- RAG pipeline → Document chunking: loads documents (evidence: `rag/pipeline.py`)
- Document chunking → PDF and text files: extracts and chunks (evidence: `core/document_processor.py`)
- RAG pipeline → FAISS vector store: adds chunks (evidence: `rag/pipeline.py`)
- RAG pipeline → BM25 index: adds chunks (evidence: `rag/pipeline.py`)
- FAISS vector store → Gemini embeddings: embeds chunks (evidence: `core/vector_store.py`)
- RAG pipeline → Persistent indexes: saves or loads (evidence: `rag/pipeline.py`)
- RAG pipeline → Hybrid RRF search: searches query (evidence: `rag/pipeline.py`)
- Hybrid RRF search → FAISS vector store: retrieves dense (evidence: `core/hybrid_search.py`)
- Hybrid RRF search → BM25 index: retrieves sparse (evidence: `core/hybrid_search.py`)
- RAG pipeline → Cosine reranker: reranks candidates (evidence: `rag/pipeline.py`)
- Cosine reranker → Gemini embeddings: embeds query and docs (evidence: `core/reranker.py`)
- RAG pipeline → Query cache: checks and stores answers (evidence: `rag/pipeline.py`)
- RAG pipeline → Conversation memory: formats and updates history (evidence: `rag/pipeline.py`)
- RAG pipeline → Gemini generation API: generates answer (evidence: `rag/pipeline.py`)
- Gemini generation API → Answer: returns text
- RAG pipeline → Interactive CLI: returns answer (evidence: `main.py`)
- Runtime configuration → RAG pipeline: sets runtime options (evidence: `rag/pipeline.py`)
