# ms-kumar/rag-journey-poc-to-prod architecture

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

- Interactive diagram: https://gitdiagram.com/ms-kumar/rag-journey-poc-to-prod
- Repository: https://github.com/ms-kumar/rag-journey-poc-to-prod

## Overview

1. This repository is a production-oriented Python 3.11 RAG platform. The runtime entrypoint is a FastAPI app in `src/main.py`, with API routing split into health, traditional RAG, ingestion, ask, and agent-oriented endpoints under `src/api/`.

2. The main architectural boundary is between the HTTP layer and the service layer. API routers and Pydantic schemas in `src/schemas/api` validate requests/responses, then delegate to orchestrated services in `src/services/` through dependency wiring in `src/dependencies.py` and configuration in `src/config.py`.

3. The ingestion path is a pipeline: source documents from `data/` or user uploads flow through ingestion and chunking services, then into embedding generation, and finally into the vector store. This path is implemented across `src/services/ingestion`, `src/services/chunking`, `src/services/embeddings`, and `src/services/vectorstore`, with Qdrant as the persistent retrieval backend.

4. The query path is separate and centered on retrieval-augmented generation. A user prompt is first processed by query understanding, then embedded, used for similarity and hybrid retrieval, optionally reranked, truncated to fit token budgets, and passed to generation for the final answer. Relevant modules are `src/services/query_understanding`, `src/services/vectorstore`, `src/services/reranker`, `src/services/truncation`, and `src/services/generation`.

5. Retrieval is not purely vector-based. The repo supports hybrid retrieval with BM25, sparse encoding, metadata filters, and fusion strategies such as RRF/weighted fusion. Those capabilities are concentrated in `src/services/vectorstore`, `src/services/vectorstore/filters.py`, `fusion.py`, and `index_mappings.py`, with docs and demos showing the supported search modes.

6. Embeddings are abstracted behind provider and caching layers. `src/services/embeddings` includes provider adapters, cached clients, sparse encoders, and factory selection for local and API-backed models. The cache subsystem is a distinct component with in-memory/LRU and persistence-oriented pieces in `src/services/cache` and `src/services/embeddings/cache.py`, intended to reduce repeated embedding cost and latency.

7. The agentic RAG path is a separate subsystem rather than a variant of the basic query flow. `src/services/agent` uses LangGraph-style orchestration with graph/state/nodes/planning/reflection, plus a tool registry and tool router. Tool implementations are grouped into local, external, and hybrid categories, including vector DB access, reranking, web search, Wikipedia, and sandboxed code execution.

8. Safety and policy enforcement are treated as a first-class layer around query processing and responses. `src/services/guardrails` provides PII detection, toxicity filtering, jailbreak detection, safe response handling, and audit logging. This means the system can redact or block unsafe content before generation or before results are returned.

9. The platform includes operational controls that sit alongside retrieval and generation rather than inside them. `src/services/observability` handles logging, metrics, tracing, SLOs, and golden traces; `src/services/performance` tracks profiling, overflow guards, token budgets, and reporting; `src/services/cost` manages model selection and cost tracking. These are cross-cutting concerns that influence runtime behavior and alerting.

10. Experimentation and rollout are built into the architecture. `src/services/experimentation` contains feature flags, canary support, statistical analysis, and reports, which connect to the deployment workflows in `.github/workflows/`. The repo is designed for staged evaluation, then canary rollout, then production promotion.

11. Evaluation is a separate offline/CI subsystem, not just a test suite. `src/services/evaluation`, the datasets in `data/eval/`, and scripts like `scripts/ci_eval_gate.py` and `scripts/verify_evaluation.py` support quality gating for retrieval and generation behavior. The evaluation gate is part of CI/CD, so model or retrieval changes can be blocked before deployment.

12. Infrastructure is intentionally lightweight and local-first for development. `infra/docker/compose.yml` starts Qdrant, and the README indicates Redis-backed caching options through configuration. Docker is used for reproducible runtime setup, while the application itself remains a Python service with external dependencies for vector storage and optional caching.

13. The repository is organized around testability and reproducibility. There is a large unit/integration test suite under `tests/`, example scripts under `examples/`, and notebooks showing the system’s evolution across weeks. That suggests the architecture is layered and modular, with clear seams for swapping retrieval, embedding, guardrail, and agent components.

14. For an architecture diagram, the most important flows are: document ingestion into Qdrant; query understanding into retrieval/fusion/reranking; answer generation with safety and truncation controls; and agentic query handling through a tool-based LangGraph subsystem. Surrounding those flows are shared services for caching, observability, cost, evaluation, and deployment governance.

Main entry points: [`src/dependencies.py`](https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/dependencies.py) (Wiring), [`src/main.py`](https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/main.py) (FastAPI app), [`src/api/router`](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/api/router) (API routers), [`src/services/query_understanding`](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/query_understanding) (Query understanding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP Layer"]
  node_main_app["FastAPI app<br/>runtime entrypoint<br/>[main.py]"]
  node_api_routers["API routers<br/>http routing"]
  node_api_schemas["API schemas<br/>pydantic contracts"]
  node_wiring["Wiring<br/>dependency/config<br/>[dependencies.py]"]
end

subgraph group_core["RAG Core"]
  node_ingestion_pipeline["Ingestion pipeline<br/>document pipeline"]
  node_chunking["Chunking<br/>text segmentation"]
  node_embeddings["Embeddings<br/>model adapters"]
  node_vectorstore[("Vector store<br/>retrieval backend")]
  node_query_understanding["Query understanding<br/>query preprocessing"]
  node_reranker["Reranker<br/>ranking service"]
  node_truncation["Truncation<br/>token control<br/>[truncation.py]"]
  node_generation["Generation<br/>answer synthesis"]
  node_guardrails["Guardrails<br/>safety layer"]
end

subgraph group_agent["Agentic RAG"]
  node_agent_subsystem["Agent graph<br/>agent orchestration"]
  node_agent_tools["Tool registry<br/>tool routing"]
end

subgraph group_ops["Platform Ops"]
  node_cache[("Cache<br/>latency reduction")]
  node_observability["Observability<br/>telemetry"]
  node_performance_cost["Perf and cost<br/>runtime controls"]
end

subgraph group_delivery["Delivery"]
  node_experimentation_eval["Eval and experiments<br/>quality governance"]
  node_ci_cd["CI/CD workflows<br/>deployment governance<br/>[workflows]"]
end

node_main_app -->|"mounts"| node_api_routers
node_api_routers -->|"validates via"| node_api_schemas
node_api_routers -->|"depends on"| node_wiring
node_wiring -->|"provides"| node_ingestion_pipeline
node_wiring -->|"provides"| node_query_understanding
node_wiring -->|"provides"| node_generation
node_wiring -->|"provides"| node_agent_subsystem
node_ingestion_pipeline -->|"uses"| node_chunking
node_chunking -->|"feeds"| node_embeddings
node_embeddings -->|"accelerated by"| node_cache
node_embeddings -->|"indexes into"| node_vectorstore
node_query_understanding -->|"prepares query"| node_embeddings
node_query_understanding -->|"retrieves from"| node_vectorstore
node_vectorstore -->|"candidates to"| node_reranker
node_reranker -->|"top-k to"| node_truncation
node_truncation -->|"supplies context"| node_generation
node_generation -->|"checked by"| node_guardrails
node_query_understanding -->|"screened by"| node_guardrails
node_main_app -->|"instrumented by"| node_observability
node_main_app -->|"controlled by"| node_performance_cost
node_main_app -->|"governed by"| node_experimentation_eval
node_experimentation_eval -->|"enforced in"| node_ci_cd
node_api_routers -->|"exposes"| node_agent_subsystem
node_agent_subsystem -->|"dispatches to"| node_agent_tools
node_agent_tools -->|"queries"| node_vectorstore
node_agent_tools -->|"calls"| node_generation
node_agent_subsystem -->|"constrained by"| node_guardrails

click node_main_app "https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/main.py"
click node_api_routers "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/api/router"
click node_api_schemas "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/schemas/api"
click node_wiring "https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/dependencies.py"
click node_ingestion_pipeline "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/ingestion"
click node_chunking "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/chunking"
click node_embeddings "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/embeddings"
click node_vectorstore "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/vectorstore"
click node_query_understanding "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/query_understanding"
click node_reranker "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/reranker"
click node_truncation "https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/services/truncation.py"
click node_generation "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/generation"
click node_guardrails "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/guardrails"
click node_cache "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/cache"
click node_observability "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/observability"
click node_performance_cost "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/performance"
click node_experimentation_eval "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/evaluation"
click node_ci_cd "https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/.github/workflows"
click node_agent_subsystem "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/agent"
click node_agent_tools "https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/agent/tools"

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_main_app,node_api_routers,node_api_schemas,node_wiring toneBlue
class node_ingestion_pipeline,node_chunking,node_embeddings,node_vectorstore,node_query_understanding,node_reranker,node_truncation,node_generation,node_guardrails toneAmber
class node_agent_subsystem,node_agent_tools toneMint
class node_cache,node_observability,node_performance_cost toneRose
class node_experimentation_eval,node_ci_cd toneIndigo
```

## Components

### HTTP Layer

FastAPI entrypoint, routers, schemas, and wiring

- [FastAPI app](https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/main.py): runtime entrypoint · Application bootstrap and server startup · `src/main.py`
- [API routers](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/api/router): http routing · Health, RAG, ingestion, ask, and agent endpoints · `src/api/router`
- [API schemas](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/schemas/api): pydantic contracts · Request and response validation for HTTP boundaries · `src/schemas/api`
- [Wiring](https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/dependencies.py): dependency/config · Dependency injection and runtime configuration · `src/dependencies.py`

### RAG Core

Ingestion, retrieval, generation, and safety subsystems

- [Ingestion pipeline](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/ingestion): document pipeline · Loads source content and prepares it for indexing · `src/services/ingestion`
- [Chunking](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/chunking): text segmentation · Splits documents into retrievable units · `src/services/chunking`
- [Embeddings](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/embeddings): model adapters · Provider selection, caching, and sparse/dense encoding · `src/services/embeddings`
- [Vector store](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/vectorstore): retrieval backend · Qdrant-backed storage, filters, fusion, and retrieval metrics · `src/services/vectorstore`
- [Query understanding](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/query_understanding): query preprocessing · Rewrites and expands user prompts before retrieval · `src/services/query_understanding`
- [Reranker](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/reranker): ranking service · Reorders candidate passages after retrieval · `src/services/reranker`
- [Truncation](https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/src/services/truncation.py): token control · Fits context to token budgets before generation · `src/services/truncation.py`
- [Generation](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/generation): answer synthesis · Final response generation from retrieved context · `src/services/generation`
- [Guardrails](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/guardrails): safety layer · PII, toxicity, jailbreak checks, and safe response handling · `src/services/guardrails`

### Agentic RAG

Graph-based tool orchestration

- [Agent graph](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/agent): agent orchestration · LangGraph-style planning, state, reflection, and execution · `src/services/agent`
- [Tool registry](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/agent/tools): tool routing · Routes agent actions to local, external, and hybrid tools · `src/services/agent/tools`

### Platform Ops

Cross-cutting runtime controls and governance

- [Cache](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/cache): latency reduction · Embedding and semantic caching · `src/services/cache`
- [Observability](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/observability): telemetry · Logging, metrics, tracing, SLOs, and golden traces · `src/services/observability`
- [Perf and cost](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/performance): runtime controls · Profiling, token budgets, model selection, and cost tracking · `src/services/performance`

### Delivery

Evaluation, experiments, and deployment workflows

- [Eval and experiments](https://github.com/ms-kumar/rag-journey-poc-to-prod/tree/main/src/services/evaluation): quality governance · Offline evaluation, canary analysis, feature flags, and reports · `src/services/evaluation`
- [CI/CD workflows](https://github.com/ms-kumar/rag-journey-poc-to-prod/blob/main/.github/workflows): deployment governance · Workflow gates for eval, deploy, release, and rollback · `.github/workflows`

## Connections

- FastAPI app → API routers: mounts · Registers HTTP routes and app lifecycle
- API routers → API schemas: validates via · Endpoints use request/response schemas
- API routers → Wiring: depends on · Routers resolve services through dependency injection
- Wiring → Ingestion pipeline: provides · Constructs ingestion services
- Wiring → Query understanding: provides · Constructs query preprocessing services
- Wiring → Generation: provides · Constructs generation services
- Wiring → Agent graph: provides · Constructs agent runtime services
- Ingestion pipeline → Chunking: uses · Document ingestion delegates to chunking
- Chunking → Embeddings: feeds · Chunks are embedded for indexing
- Embeddings → Cache: accelerated by · Embedding calls are cached
- Embeddings → Vector store: indexes into · Embedded chunks are persisted for retrieval
- Query understanding → Embeddings: prepares query · Query text is normalized and embedded
- Query understanding → Vector store: retrieves from · Uses hybrid search and filters
- Vector store → Reranker: candidates to · Retrieval results can be reranked
- Reranker → Truncation: top-k to · Ranked context is trimmed for budget
- Truncation → Generation: supplies context · Token-safe context is passed to generation
- Generation → Guardrails: checked by · Outputs can be screened or redacted
- Query understanding → Guardrails: screened by · User prompts can be filtered before retrieval
- FastAPI app → Observability: instrumented by · Runtime telemetry is attached at the app layer
- FastAPI app → Perf and cost: controlled by · Token budgets and cost controls affect serving
- FastAPI app → Eval and experiments: governed by · Feature flags and evaluation gates influence rollout
- Eval and experiments → CI/CD workflows: enforced in · Evaluation gates connect to workflows
- API routers → Agent graph: exposes · Agent-oriented endpoints reach the graph runtime
- Agent graph → Tool registry: dispatches to · Planning and node execution invoke tools
- Tool registry → Vector store: queries · Local tools access retrieval backend
- Tool registry → Generation: calls · Agent tools can invoke local generation
- Agent graph → Guardrails: constrained by · Agent responses are safety-checked
