# kalvium23/sw81_autorag_champs architecture

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

- Interactive diagram: https://gitdiagram.com/kalvium23/sw81_autorag_champs
- Repository: https://github.com/kalvium23/sw81_autorag_champs

## Overview

#### Purpose and Entry Points
This is a Python retrieval-augmented generation (RAG) pipeline repository. It ingests source documents, prepares searchable chunks, indexes them for hybrid retrieval, and sends retrieved context to an LLM. There is no declared application CLI or service entry point in the supplied README; the callable boundaries are the package modules under `src/`.

#### 1. Document Ingestion Pipeline
The ingestion layer converts raw files into validated, cleaned, and chunked content suitable for indexing. Its stages are separated so input handling and content normalization can evolve independently.
- `src/ingestion/loaders.py`
- `src/ingestion/validator.py`
- `src/ingestion/cleaner.py`
- `src/ingestion/chunker.py`

Primary flow: source material from `data/` → loader → validation → cleaning → chunking → retrieval/indexing layer.

#### 2. Retrieval Corpus Boundary
`data/` is the raw-document boundary, while `outputs/` is the intended boundary for generated artifacts or run results. The repository keeps these directories present but does not commit their contents.
- `data/.gitkeep`
- `outputs/.gitkeep`
- `src/ingestion/__init__.py`

This separation implies ingestion should not depend on generated RAG responses, and retrieval/index artifacts should be treated independently from source inputs.

#### 3. Embedding and Vector Indexing
The retrieval subsystem turns document chunks into vector representations and persists or accesses them through a vector-store abstraction.
- `src/retrieval/embedder.py`
- `src/retrieval/vector_store.py`
- `src/retrieval/__init__.py`

The key boundary is between embedding generation and storage/query mechanics: callers should pass normalized chunks and metadata into this layer rather than coupling ingestion directly to a specific vector database implementation.

#### 4. Hybrid Search
Query-time retrieval combines vector similarity with another retrieval signal, likely keyword or lexical search, behind a dedicated hybrid-search component.
- `src/retrieval/hybrid_search.py`
- `src/retrieval/embedder.py`
- `src/retrieval/vector_store.py`

Primary control flow: user/query text → query embedding and lexical retrieval → hybrid ranking → selected context chunks. This module is the central ranking boundary before LLM invocation.

#### 5. RAG Orchestration and LLM Boundary
The RAG package defines prompt construction, request/response structures, token constraints, and the external LLM client integration.
- `src/rag/llm_client.py`
- `src/rag/prompts.py`
- `src/rag/schema.py`
- `src/rag/token_budget.py`

The expected flow is ranked retrieval context → token-budget enforcement → prompt assembly → LLM client → structured response. `schema.py` should be the contract boundary for data exchanged among retrieval, prompting, and model invocation code.

#### 6. Prompt Assets and Model Configuration
Prompt text is partly maintained as a repository asset, distinct from Python prompt assembly logic.
- `prompts/diagnostic_system.md`
- `src/rag/prompts.py`
- `.env.example`

`prompts/diagnostic_system.md` suggests a diagnostic-oriented system instruction. `.env.example` indicates runtime configuration or credentials are externalized, likely including LLM and/or vector-store service settings. External services are not named in the provided tree, so their concrete providers should remain implementation-configurable.

#### 7. Runtime and Validation
The project is Python-based, with dependencies declared in `requirements.txt`. Focused test modules exercise the two major pipeline boundaries.
- `requirements.txt`
- `src/test_ingestion.py`
- `src/test_retrieval.py`
- `src/rag/test_llm.py`

The architecture’s critical integration path is ingestion → vector indexing → hybrid retrieval → budgeted prompt generation → external LLM response.

Main entry points: [`src/rag/llm_client.py`](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/llm_client.py) (LLM client), [`src/retrieval/hybrid_search.py`](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/hybrid_search.py) (Hybrid search), [`src/retrieval/embedder.py`](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/embedder.py) (Embedder), [`src/rag/schema.py`](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/schema.py) (RAG schema)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Ingestion"]
  node_loader["Loaders<br/>ingestion module<br/>[loaders.py]"]
  node_validator["Validator<br/>ingestion module<br/>[validator.py]"]
  node_cleaner["Cleaner<br/>ingestion module<br/>[cleaner.py]"]
  node_chunker["Chunker<br/>ingestion module<br/>[chunker.py]"]
end

subgraph group_retrieval["Retrieval"]
  node_embedder["Embedder<br/>retrieval module<br/>[embedder.py]"]
  node_vector_store[("Vector store<br/>storage abstraction<br/>[vector_store.py]")]
  node_hybrid_search["Hybrid search<br/>ranking module<br/>[hybrid_search.py]"]
end

subgraph group_rag["RAG Orchestration"]
  node_schema["RAG schema<br/>data contracts<br/>[schema.py]"]
  node_token_budget["Token budget<br/>context control<br/>[token_budget.py]"]
  node_prompts["Prompt assembly<br/>RAG module<br/>[prompts.py]"]
  node_llm_client["LLM client<br/>model adapter<br/>[llm_client.py]"]
end

node_data[("Raw documents<br/>source corpus<br/>[.gitkeep]")]
node_query["User query<br/>query input"]
node_prompt_asset["Diagnostic system prompt<br/>prompt asset"]
node_llm{{"External LLM<br/>model service"}}
node_outputs[("Generated outputs<br/>artifact boundary<br/>[.gitkeep]")]
node_runtime_config["Runtime configuration<br/>environment template<br/>[.env.example]"]

node_data -->|"load files"| node_loader
node_loader -->|"validate"| node_validator
node_validator -->|"clean"| node_cleaner
node_cleaner -->|"chunk"| node_chunker
node_chunker -->|"normalized chunks"| node_embedder
node_embedder -->|"index vectors"| node_vector_store
node_query -->|"retrieve"| node_hybrid_search
node_hybrid_search -->|"embed query"| node_embedder
node_hybrid_search -->|"vector and lexical lookup"| node_vector_store
node_hybrid_search -->|"ranked context"| node_schema
node_schema -->|"context contract"| node_token_budget
node_token_budget -->|"selected context"| node_prompts
node_prompt_asset -->|"system instruction"| node_prompts
node_prompts -->|"assembled request"| node_llm_client
node_llm_client -->|"model request"| node_llm
node_llm_client -->|"structured response"| node_schema
node_llm_client -->|"generated result"| node_outputs
node_runtime_config -.->|"store settings"| node_vector_store
node_runtime_config -.->|"model settings"| node_llm_client

click node_data "https://github.com/kalvium23/sw81_autorag_champs/blob/main/data/.gitkeep"
click node_loader "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/loaders.py"
click node_validator "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/validator.py"
click node_cleaner "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/cleaner.py"
click node_chunker "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/chunker.py"
click node_embedder "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/embedder.py"
click node_vector_store "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/vector_store.py"
click node_hybrid_search "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/hybrid_search.py"
click node_schema "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/schema.py"
click node_token_budget "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/token_budget.py"
click node_prompts "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/prompts.py"
click node_prompt_asset "https://github.com/kalvium23/sw81_autorag_champs/blob/main/prompts/diagnostic_system.md"
click node_llm_client "https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/llm_client.py"
click node_outputs "https://github.com/kalvium23/sw81_autorag_champs/blob/main/outputs/.gitkeep"
click node_runtime_config "https://github.com/kalvium23/sw81_autorag_champs/blob/main/.env.example"

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_loader,node_validator,node_cleaner,node_chunker toneBlue
class node_embedder,node_vector_store,node_hybrid_search toneAmber
class node_schema,node_token_budget,node_prompts,node_llm_client toneMint
class node_data,node_query,node_prompt_asset,node_llm,node_outputs,node_runtime_config toneNeutral
```

## Components

### Ingestion

Transforms raw documents into indexable chunks.

- [Loaders](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/loaders.py): ingestion module · `src/ingestion/loaders.py`
- [Validator](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/validator.py): ingestion module · `src/ingestion/validator.py`
- [Cleaner](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/cleaner.py): ingestion module · `src/ingestion/cleaner.py`
- [Chunker](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/ingestion/chunker.py): ingestion module · `src/ingestion/chunker.py`

### Retrieval

Indexes chunks and produces hybrid-ranked context.

- [Embedder](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/embedder.py): retrieval module · Creates document and query vectors. · `src/retrieval/embedder.py`
- [Vector store](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/vector_store.py): storage abstraction · Decouples indexing and similarity queries from a provider. · `src/retrieval/vector_store.py`
- [Hybrid search](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/retrieval/hybrid_search.py): ranking module · Combines vector and lexical retrieval signals. · `src/retrieval/hybrid_search.py`

### RAG Orchestration

Builds budgeted prompts and invokes the model.

- [RAG schema](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/schema.py): data contracts · Contract between retrieval, prompting, and model invocation. · `src/rag/schema.py`
- [Token budget](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/token_budget.py): context control · `src/rag/token_budget.py`
- [Prompt assembly](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/prompts.py): RAG module · `src/rag/prompts.py`
- [LLM client](https://github.com/kalvium23/sw81_autorag_champs/blob/main/src/rag/llm_client.py): model adapter · Provider-configurable external-model boundary. · `src/rag/llm_client.py`

### Other components

- [Raw documents](https://github.com/kalvium23/sw81_autorag_champs/blob/main/data/.gitkeep): source corpus · Uncommitted source-document boundary. · `data/.gitkeep`
- **User query**: query input
- [Diagnostic system prompt](https://github.com/kalvium23/sw81_autorag_champs/blob/main/prompts/diagnostic_system.md): prompt asset · `prompts/diagnostic_system.md`
- **External LLM**: model service
- [Generated outputs](https://github.com/kalvium23/sw81_autorag_champs/blob/main/outputs/.gitkeep): artifact boundary · Uncommitted run-result boundary. · `outputs/.gitkeep`
- [Runtime configuration](https://github.com/kalvium23/sw81_autorag_champs/blob/main/.env.example): environment template · Externalizes model and store settings or credentials. · `.env.example`

## Connections

- Raw documents → Loaders: load files
- Loaders → Validator: validate
- Validator → Cleaner: clean
- Cleaner → Chunker: chunk
- Chunker → Embedder: normalized chunks
- Embedder → Vector store: index vectors
- User query → Hybrid search: retrieve
- Hybrid search → Embedder: embed query
- Hybrid search → Vector store: vector and lexical lookup
- Hybrid search → RAG schema: ranked context
- RAG schema → Token budget: context contract
- Token budget → Prompt assembly: selected context
- Diagnostic system prompt → Prompt assembly: system instruction
- Prompt assembly → LLM client: assembled request
- LLM client → External LLM: model request
- LLM client → RAG schema: structured response
- LLM client → Generated outputs: generated result
- Runtime configuration → Vector store: store settings
- Runtime configuration → LLM client: model settings
