How ms-kumar/rag-journey-poc-to-prod works
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: dependencies.py Wiring · main.py FastAPI app · router API routers · query_understanding Query understanding
Components 20
HTTP Layer
FastAPI entrypoint, routers, schemas, and wiring
- FastAPI app · Application bootstrap and server startup
src/main.py - API routers · Health, RAG, ingestion, ask, and agent endpoints
src/api/router - API schemas · Request and response validation for HTTP boundaries
src/schemas/api - Wiring · Dependency injection and runtime configuration
src/dependencies.py
RAG Core
Ingestion, retrieval, generation, and safety subsystems
- Ingestion pipeline · Loads source content and prepares it for indexing
src/services/ingestion - Chunking · Splits documents into retrievable units
src/services/chunking - Embeddings · Provider selection, caching, and sparse/dense encoding
src/services/embeddings - Vector store · Qdrant-backed storage, filters, fusion, and retrieval metrics
src/services/vectorstore - Query understanding · Rewrites and expands user prompts before retrieval
src/services/query_understanding - Reranker · Reorders candidate passages after retrieval
src/services/reranker - Truncation · Fits context to token budgets before generation
src/services/truncation.py - Generation · Final response generation from retrieved context
src/services/generation - Guardrails · PII, toxicity, jailbreak checks, and safe response handling
src/services/guardrails
Agentic RAG
Graph-based tool orchestration
- Agent graph · LangGraph-style planning, state, reflection, and execution
src/services/agent - Tool registry · Routes agent actions to local, external, and hybrid tools
src/services/agent/tools
Platform Ops
Cross-cutting runtime controls and governance
- Cache · Embedding and semantic caching
src/services/cache - Observability · Logging, metrics, tracing, SLOs, and golden traces
src/services/observability - Perf and cost · Profiling, token budgets, model selection, and cost tracking
src/services/performance
Delivery
Evaluation, experiments, and deployment workflows
- Eval and experiments · Offline evaluation, canary analysis, feature flags, and reports
src/services/evaluation - CI/CD workflows · Workflow gates for eval, deploy, release, and rollback
.github/workflows
Connections 27
- 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