# gefolgwar/rag_42ber architecture

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

- Interactive diagram: https://gitdiagram.com/gefolgwar/rag_42ber
- Repository: https://github.com/gefolgwar/rag_42ber

## Overview

RAG Against the Machine indexes a vLLM corpus, retrieves relevant code or documentation spans, and can generate grounded answers or score retrieval quality. The main flow is corpus scan → chunk → lexical/dense index → retrieval → source-span resolution and answer generation; CLI commands and a FastAPI API expose it. Dataset evaluation is a separate capability. Edges use the supplied excerpts, SOURCE INDEX references, or README; unsampled wiring is not inferred.

Main entry points: [`src/retrieval.py`](https://github.com/gefolgwar/rag_42ber/blob/main/src/retrieval.py) (Retrieval Service), [`src/commands/index_cmd.py`](https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/index_cmd.py) (Index Command), [`src/cli.py`](https://github.com/gefolgwar/rag_42ber/blob/main/src/cli.py) (CLI Dispatcher), [`src/commands/eval_cmd.py`](https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/eval_cmd.py) (Evaluation Command)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and Chunking"]
  node_ingest["Corpus Ingestion<br/>[ingest.py]"]
  node_file_filter["File Filtering<br/>[file_filter.py]"]
  node_chunking["Chunking Facade<br/>[chunking.py]"]
  node_python_chunks["Python AST Chunks<br/>[chunk_python.py]"]
  node_markdown_chunks["Markdown Chunks<br/>[chunk_markdown.py]"]
  node_chunk_windows["Window Splitting<br/>[chunk_window.py]"]
  node_chunk_types["Chunk Spans<br/>[chunk_types.py]"]
end

subgraph group_indexing["Search Indexes"]
  node_hashing["Incremental Hashes<br/>[hash.py]"]
  node_bm25[("BM25 Knowledge Base<br/>[index.py]")]
  node_tokenizer["Query Tokenizer<br/>[tokenizer.py]"]
  node_dense[("Dense and RRF Search<br/>[dense.py]")]
end

subgraph group_retrieval["Retrieval and Sources"]
  node_retrieval_core["Retrieval Service<br/>[retrieval.py]"]
  node_cache[("Query Cache<br/>[cache.py]")]
  node_models["Request and Result Models<br/>[models.py]"]
end

subgraph group_interfaces["User Interfaces"]
  node_cli["CLI Dispatcher<br/>[cli.py]"]
  node_api["HTTP API<br/>[app.py]"]
  node_index_cmd["Index Command<br/>[index_cmd.py]"]
  node_search_cmd["Search Command<br/>[search_cmd.py]"]
  node_answer_cmd["Answer Command<br/>[answer_cmd.py]"]
  node_eval_cmd["Evaluation Command<br/>[eval_cmd.py]"]
end

subgraph group_answer_eval["Answers and Evaluation"]
  node_generator["Grounded Generator<br/>[generator.py]"]
  node_evaluator["Recall Evaluator<br/>[evaluator.py]"]
end

node_user(("User"))
node_corpus["vLLM Corpus"]
node_dataset["Question Dataset"]

node_user -->|"runs commands"| node_cli
node_user -->|"sends requests"| node_api
node_cli -->|"dispatches"| node_index_cmd
node_cli -->|"dispatches"| node_search_cmd
node_cli -->|"dispatches"| node_answer_cmd
node_cli -->|"dispatches"| node_eval_cmd
node_corpus -->|"provides files"| node_ingest
node_index_cmd -->|"collects files"| node_ingest
node_ingest -->|"filters paths"| node_file_filter
node_index_cmd -->|"chunks files"| node_chunking
node_chunking -->|"routes Python"| node_python_chunks
node_chunking -->|"routes documents"| node_markdown_chunks
node_python_chunks -->|"splits oversized spans"| node_chunk_windows
node_markdown_chunks -->|"splits oversized spans"| node_chunk_windows
node_chunking -->|"returns spans"| node_chunk_types
node_index_cmd -->|"checks changes"| node_hashing
node_index_cmd -->|"builds and saves"| node_bm25
node_bm25 -->|"tokenizes text"| node_tokenizer
node_index_cmd -.->|"optionally builds"| node_dense
node_search_cmd -->|"searches cached"| node_retrieval_core
node_answer_cmd -->|"loads and searches"| node_retrieval_core
node_api -->|"routes search"| node_retrieval_core
node_retrieval_core -->|"runs lexical search"| node_bm25
node_retrieval_core -->|"checks and stores"| node_cache
node_retrieval_core -->|"optionally fuses results"| node_dense
node_retrieval_core -->|"filters result types"| node_file_filter
node_retrieval_core -->|"creates source spans"| node_models
node_answer_cmd -->|"generates answers"| node_generator
node_api -->|"routes answers"| node_generator
node_answer_cmd -->|"resolves source chunks"| node_retrieval_core
node_dataset -->|"supplies questions"| node_eval_cmd
node_eval_cmd -->|"loads search results"| node_retrieval_core
node_eval_cmd -->|"scores recall"| node_evaluator
node_eval_cmd -->|"validates data"| node_models

click node_cli "https://github.com/gefolgwar/rag_42ber/blob/main/src/cli.py"
click node_api "https://github.com/gefolgwar/rag_42ber/blob/main/api/app.py"
click node_index_cmd "https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/index_cmd.py"
click node_search_cmd "https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/search_cmd.py"
click node_answer_cmd "https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/answer_cmd.py"
click node_eval_cmd "https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/eval_cmd.py"
click node_ingest "https://github.com/gefolgwar/rag_42ber/blob/main/src/ingest.py"
click node_file_filter "https://github.com/gefolgwar/rag_42ber/blob/main/src/file_filter.py"
click node_chunking "https://github.com/gefolgwar/rag_42ber/blob/main/src/chunking.py"
click node_python_chunks "https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_python.py"
click node_markdown_chunks "https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_markdown.py"
click node_chunk_windows "https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_window.py"
click node_chunk_types "https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_types.py"
click node_hashing "https://github.com/gefolgwar/rag_42ber/blob/main/src/hash.py"
click node_bm25 "https://github.com/gefolgwar/rag_42ber/blob/main/src/index.py"
click node_tokenizer "https://github.com/gefolgwar/rag_42ber/blob/main/src/tokenizer.py"
click node_dense "https://github.com/gefolgwar/rag_42ber/blob/main/src/dense.py"
click node_retrieval_core "https://github.com/gefolgwar/rag_42ber/blob/main/src/retrieval.py"
click node_cache "https://github.com/gefolgwar/rag_42ber/blob/main/src/cache.py"
click node_models "https://github.com/gefolgwar/rag_42ber/blob/main/src/models.py"
click node_generator "https://github.com/gefolgwar/rag_42ber/blob/main/src/generator.py"
click node_evaluator "https://github.com/gefolgwar/rag_42ber/blob/main/src/evaluator.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_file_filter,node_chunking,node_python_chunks,node_markdown_chunks,node_chunk_windows,node_chunk_types,node_user toneBlue
class node_hashing,node_bm25,node_tokenizer,node_dense toneAmber
class node_retrieval_core,node_cache,node_models toneMint
class node_cli,node_api,node_index_cmd,node_search_cmd,node_answer_cmd,node_eval_cmd toneRose
class node_generator,node_evaluator,node_corpus,node_dataset toneIndigo
```

## Components

### Ingestion and Chunking

- [Corpus Ingestion](https://github.com/gefolgwar/rag_42ber/blob/main/src/ingest.py): `src/ingest.py`
- [File Filtering](https://github.com/gefolgwar/rag_42ber/blob/main/src/file_filter.py): `src/file_filter.py`
- [Chunking Facade](https://github.com/gefolgwar/rag_42ber/blob/main/src/chunking.py): `src/chunking.py`
- [Python AST Chunks](https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_python.py): `src/chunk_python.py`
- [Markdown Chunks](https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_markdown.py): `src/chunk_markdown.py`
- [Window Splitting](https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_window.py): `src/chunk_window.py`
- [Chunk Spans](https://github.com/gefolgwar/rag_42ber/blob/main/src/chunk_types.py): `src/chunk_types.py`

### Search Indexes

- [Incremental Hashes](https://github.com/gefolgwar/rag_42ber/blob/main/src/hash.py): `src/hash.py`
- [BM25 Knowledge Base](https://github.com/gefolgwar/rag_42ber/blob/main/src/index.py): `src/index.py`
- [Query Tokenizer](https://github.com/gefolgwar/rag_42ber/blob/main/src/tokenizer.py): `src/tokenizer.py`
- [Dense and RRF Search](https://github.com/gefolgwar/rag_42ber/blob/main/src/dense.py): `src/dense.py`

### Retrieval and Sources

- [Retrieval Service](https://github.com/gefolgwar/rag_42ber/blob/main/src/retrieval.py): `src/retrieval.py`
- [Query Cache](https://github.com/gefolgwar/rag_42ber/blob/main/src/cache.py): `src/cache.py`
- [Request and Result Models](https://github.com/gefolgwar/rag_42ber/blob/main/src/models.py): `src/models.py`

### User Interfaces

- [CLI Dispatcher](https://github.com/gefolgwar/rag_42ber/blob/main/src/cli.py): `src/cli.py`
- [HTTP API](https://github.com/gefolgwar/rag_42ber/blob/main/api/app.py): `api/app.py`
- [Index Command](https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/index_cmd.py): `src/commands/index_cmd.py`
- [Search Command](https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/search_cmd.py): `src/commands/search_cmd.py`
- [Answer Command](https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/answer_cmd.py): `src/commands/answer_cmd.py`
- [Evaluation Command](https://github.com/gefolgwar/rag_42ber/blob/main/src/commands/eval_cmd.py): `src/commands/eval_cmd.py`

### Answers and Evaluation

- [Grounded Generator](https://github.com/gefolgwar/rag_42ber/blob/main/src/generator.py): `src/generator.py`
- [Recall Evaluator](https://github.com/gefolgwar/rag_42ber/blob/main/src/evaluator.py): `src/evaluator.py`

### Other components

- **User**
- **vLLM Corpus**
- **Question Dataset**

## Connections

- User → CLI Dispatcher: runs commands (evidence: `README.md`)
- User → HTTP API: sends requests (evidence: `README.md`)
- CLI Dispatcher → Index Command: dispatches (evidence: `src/cli.py`)
- CLI Dispatcher → Search Command: dispatches (evidence: `src/cli.py`)
- CLI Dispatcher → Answer Command: dispatches (evidence: `src/cli.py`)
- CLI Dispatcher → Evaluation Command: dispatches (evidence: `src/cli.py`)
- vLLM Corpus → Corpus Ingestion: provides files (evidence: `README.md`)
- Index Command → Corpus Ingestion: collects files (evidence: `src/commands/index_cmd.py`)
- Corpus Ingestion → File Filtering: filters paths (evidence: `src/ingest.py`)
- Index Command → Chunking Facade: chunks files (evidence: `src/commands/index_cmd.py`)
- Chunking Facade → Python AST Chunks: routes Python (evidence: `src/chunking.py`)
- Chunking Facade → Markdown Chunks: routes documents (evidence: `src/chunking.py`)
- Python AST Chunks → Window Splitting: splits oversized spans (evidence: `src/chunk_python.py`)
- Markdown Chunks → Window Splitting: splits oversized spans (evidence: `src/chunk_markdown.py`)
- Chunking Facade → Chunk Spans: returns spans (evidence: `src/chunking.py`)
- Index Command → Incremental Hashes: checks changes (evidence: `src/commands/index_cmd.py`)
- Index Command → BM25 Knowledge Base: builds and saves (evidence: `src/commands/index_cmd.py`)
- BM25 Knowledge Base → Query Tokenizer: tokenizes text (evidence: `src/index.py`)
- Index Command → Dense and RRF Search: optionally builds (evidence: `src/commands/index_cmd.py`)
- Search Command → Retrieval Service: searches cached (evidence: `src/commands/search_cmd.py`)
- Answer Command → Retrieval Service: loads and searches (evidence: `src/commands/answer_cmd.py`)
- HTTP API → Retrieval Service: routes search (evidence: `api/app.py`)
- Retrieval Service → BM25 Knowledge Base: runs lexical search (evidence: `src/retrieval.py`)
- Retrieval Service → Query Cache: checks and stores (evidence: `src/retrieval.py`)
- Retrieval Service → Dense and RRF Search: optionally fuses results (evidence: `src/retrieval.py`)
- Retrieval Service → File Filtering: filters result types
- Retrieval Service → Request and Result Models: creates source spans (evidence: `src/retrieval.py`)
- Answer Command → Grounded Generator: generates answers (evidence: `src/commands/answer_cmd.py`)
- HTTP API → Grounded Generator: routes answers (evidence: `api/app.py`)
- Answer Command → Retrieval Service: resolves source chunks (evidence: `src/commands/answer_cmd.py`)
- Question Dataset → Evaluation Command: supplies questions (evidence: `README.md`)
- Evaluation Command → Retrieval Service: loads search results (evidence: `src/commands/eval_cmd.py`)
- Evaluation Command → Recall Evaluator: scores recall (evidence: `src/commands/eval_cmd.py`)
- Evaluation Command → Request and Result Models: validates data (evidence: `src/commands/eval_cmd.py`)
