# starryroses/groundrag-hybrid-retrieval-grounded-generation-system architecture

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

- Interactive diagram: https://gitdiagram.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system
- Repository: https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system

## Overview

Advanced RAG is a BBC News research assistant: users submit questions with conversation history, receive evidence-grounded answers and citations, and can inspect retrieved evidence. The backend loads and prepares the corpus at startup, then rewrites each query, retrieves through lexical and dense search, fuses and reranks results, and applies grounding, generation, verification, and citation checks. The frontend and API excerpts show the request/response path; several grounding and retrieval relationships are supported by the pipeline’s imports but their implementations were not sampled.

Main entry points: [`src/pipeline/rag_pipeline.py`](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/pipeline/rag_pipeline.py) (RAG pipeline), [`frontend/src/App.jsx`](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/App.jsx) (Chat app), [`src/app/container.py`](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/app/container.py) (RAG container), [`src/api/routes.py`](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/api/routes.py) (Query endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_app["Chat app<br/>[App.jsx]"]
  node_chat["Chat window<br/>[ChatWindow.jsx]"]
  node_messages["Message bubbles<br/>[MessageBubble.jsx]"]
  node_composer["Chat input<br/>[ChatInput.jsx]"]
  node_evidence_ui["Evidence panel<br/>[EvidencePanel.jsx]"]
  node_frontend_api["API client<br/>[api.js]"]
end

subgraph group_service["API and orchestration"]
  node_api["Query endpoint<br/>[routes.py]"]
  node_container["RAG container<br/>[container.py]"]
  node_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
end

subgraph group_corpus["Corpus preparation"]
  node_bbc["BBC corpus loader<br/>[bbc_loader.py]"]
  node_preprocess["Text preprocessing<br/>[preprocess.py]"]
  node_chunker["Document chunker<br/>[chunker.py]"]
  node_models["Document and result models<br/>[models.py]"]
end

subgraph group_search["Retrieval and ranking"]
  node_rewriter["Query rewriter<br/>[query_rewriter.py]"]
  node_bm25["BM25 search<br/>[bm25.py]"]
  node_dense["Dense search<br/>[dense.py]"]
  node_chroma[("Persistent vector store")]
  node_fusion["Rank fusion<br/>[rrf.py]"]
  node_reranker["Cross-encoder reranker<br/>[cross_encoder.py]"]
end

subgraph group_answers["Grounded answers"]
  node_decision["Grounding decision<br/>[decision.py]"]
  node_context["Evidence context<br/>[context.py]"]
  node_prompt["Grounded prompt<br/>[prompt.py]"]
  node_llm["Groq language model<br/>[groq_llm.py]"]
  node_verifier["Answer verifier<br/>[verifier.py]"]
  node_citations["Citation validation<br/>[citations.py]"]
end

node_user(("Researcher"))
node_groq{{"Groq service"}}

node_user -->|"asks"| node_app
node_app -->|"renders"| node_composer
node_app -->|"renders"| node_chat
node_chat -->|"renders"| node_messages
node_app -->|"renders"| node_evidence_ui
node_app -->|"calls"| node_frontend_api
node_frontend_api -.->|"sends query"| node_api
node_api -->|"calls"| node_container
node_container -->|"constructs and calls"| node_pipeline
node_container -->|"loads corpus"| node_bbc
node_container -->|"preprocesses documents"| node_preprocess
node_container -->|"chunks documents"| node_chunker
node_bbc -->|"creates documents"| node_models
node_chunker -->|"creates chunks"| node_models
node_pipeline -->|"rewrites query"| node_rewriter
node_pipeline -->|"searches query"| node_bm25
node_pipeline -->|"searches query"| node_dense
node_pipeline -->|"fuses results"| node_fusion
node_pipeline -->|"reranks results"| node_reranker
node_dense -->|"queries and indexes"| node_chroma
node_pipeline -->|"checks evidence"| node_decision
node_pipeline -->|"builds context"| node_context
node_pipeline -->|"builds prompt"| node_prompt
node_pipeline -->|"generates answer"| node_llm
node_llm -->|"requests completion"| node_groq
node_pipeline -->|"verifies answer"| node_verifier
node_pipeline -->|"validates and builds citations"| node_citations
node_app -.->|"displays response"| node_api
node_app -->|"selects evidence"| node_evidence_ui

click node_app "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/App.jsx"
click node_chat "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/ChatWindow.jsx"
click node_messages "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/MessageBubble.jsx"
click node_composer "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/ChatInput.jsx"
click node_evidence_ui "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/EvidencePanel.jsx"
click node_frontend_api "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/services/api.js"
click node_api "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/api/routes.py"
click node_container "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/app/container.py"
click node_pipeline "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/pipeline/rag_pipeline.py"
click node_bbc "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/ingestion/bbc_loader.py"
click node_preprocess "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/nlp/preprocess.py"
click node_chunker "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/ingestion/chunker.py"
click node_models "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/models.py"
click node_rewriter "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/generation/query_rewriter.py"
click node_bm25 "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/retrieval/bm25.py"
click node_dense "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/retrieval/dense.py"
click node_fusion "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/retrieval/rrf.py"
click node_reranker "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/reranking/cross_encoder.py"
click node_decision "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/decision.py"
click node_context "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/context.py"
click node_prompt "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/prompt.py"
click node_llm "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/generation/groq_llm.py"
click node_verifier "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/verifier.py"
click node_citations "https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/citations.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_app,node_chat,node_messages,node_composer,node_evidence_ui,node_frontend_api toneBlue
class node_api,node_container,node_pipeline toneAmber
class node_bbc,node_preprocess,node_chunker,node_models toneMint
class node_rewriter,node_bm25,node_dense,node_chroma,node_fusion,node_reranker toneRose
class node_decision,node_context,node_prompt,node_llm,node_verifier,node_citations,node_user,node_groq toneIndigo
```

## Components

### User experience

- [Chat app](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Chat window](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/ChatWindow.jsx): `frontend/src/components/ChatWindow.jsx`
- [Message bubbles](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/MessageBubble.jsx): `frontend/src/components/MessageBubble.jsx`
- [Chat input](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/ChatInput.jsx): `frontend/src/components/ChatInput.jsx`
- [Evidence panel](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/components/EvidencePanel.jsx): `frontend/src/components/EvidencePanel.jsx`
- [API client](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API and orchestration

- [Query endpoint](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/api/routes.py): `src/api/routes.py`
- [RAG container](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/app/container.py): `src/app/container.py`
- [RAG pipeline](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/pipeline/rag_pipeline.py): `src/pipeline/rag_pipeline.py`

### Corpus preparation

- [BBC corpus loader](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/ingestion/bbc_loader.py): `src/ingestion/bbc_loader.py`
- [Text preprocessing](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/nlp/preprocess.py): `src/nlp/preprocess.py`
- [Document chunker](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/ingestion/chunker.py): `src/ingestion/chunker.py`
- [Document and result models](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/models.py): `src/models.py`

### Retrieval and ranking

- [Query rewriter](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/generation/query_rewriter.py): `src/generation/query_rewriter.py`
- [BM25 search](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/retrieval/bm25.py): `src/retrieval/bm25.py`
- [Dense search](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/retrieval/dense.py): `src/retrieval/dense.py`
- **Persistent vector store**
- [Rank fusion](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/retrieval/rrf.py): `src/retrieval/rrf.py`
- [Cross-encoder reranker](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/reranking/cross_encoder.py): `src/reranking/cross_encoder.py`

### Grounded answers

- [Grounding decision](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/decision.py): `src/grounding/decision.py`
- [Evidence context](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/context.py): `src/grounding/context.py`
- [Grounded prompt](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/prompt.py): `src/grounding/prompt.py`
- [Groq language model](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/generation/groq_llm.py): `src/generation/groq_llm.py`
- [Answer verifier](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/verifier.py): `src/grounding/verifier.py`
- [Citation validation](https://github.com/starryroses/groundrag-hybrid-retrieval-grounded-generation-system/blob/main/src/grounding/citations.py): `src/grounding/citations.py`

### Other components

- **Researcher**
- **Groq service**

## Connections

- Researcher → Chat app: asks (evidence: `frontend/src/App.jsx`)
- Chat app → Chat input: renders (evidence: `frontend/src/App.jsx`)
- Chat app → Chat window: renders (evidence: `frontend/src/App.jsx`)
- Chat window → Message bubbles: renders (evidence: `frontend/src/components/ChatWindow.jsx`)
- Chat app → Evidence panel: renders (evidence: `frontend/src/App.jsx`)
- Chat app → API client: calls (evidence: `frontend/src/App.jsx`)
- API client → Query endpoint: sends query
- Query endpoint → RAG container: calls (evidence: `src/api/routes.py`)
- RAG container → RAG pipeline: constructs and calls (evidence: `src/app/container.py`)
- RAG container → BBC corpus loader: loads corpus (evidence: `src/app/container.py`)
- RAG container → Text preprocessing: preprocesses documents (evidence: `src/app/container.py`)
- RAG container → Document chunker: chunks documents (evidence: `src/app/container.py`)
- BBC corpus loader → Document and result models: creates documents (evidence: `src/ingestion/bbc_loader.py`)
- Document chunker → Document and result models: creates chunks (evidence: `src/ingestion/chunker.py`)
- RAG pipeline → Query rewriter: rewrites query (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → BM25 search: searches query (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Dense search: searches query (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Rank fusion: fuses results (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Cross-encoder reranker: reranks results (evidence: `src/pipeline/rag_pipeline.py`)
- Dense search → Persistent vector store: queries and indexes (evidence: `src/retrieval/dense.py`)
- RAG pipeline → Grounding decision: checks evidence (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Evidence context: builds context (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Grounded prompt: builds prompt (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Groq language model: generates answer (evidence: `src/pipeline/rag_pipeline.py`)
- Groq language model → Groq service: requests completion (evidence: `src/generation/groq_llm.py`)
- RAG pipeline → Answer verifier: verifies answer (evidence: `src/pipeline/rag_pipeline.py`)
- RAG pipeline → Citation validation: validates and builds citations (evidence: `src/pipeline/rag_pipeline.py`)
- Chat app → Query endpoint: displays response
- Chat app → Evidence panel: selects evidence (evidence: `frontend/src/App.jsx`)
