# vandinh2912/hybrid_rag_agu architecture

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

- Interactive diagram: https://gitdiagram.com/vandinh2912/hybrid_rag_agu
- Repository: https://github.com/vandinh2912/hybrid_rag_agu

## Overview

This is an AGU academic-regulations question-answering product. Users ask through the CLI or desktop GUI; the pipeline normalizes and expands the query, retrieves evidence with hybrid search, and generates a cited answer. Separate product branches ingest documents, collect learning feedback, and compare/evaluate chunking and answer quality. Edges reflect the excerpts, SOURCE INDEX references, or README; some internal call details and unsampled subsystems are documented only at a high level.

Main entry points: [`src/pipeline.py`](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/pipeline.py) (RAG orchestrator), [`ingest.py`](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ingest.py) (Ingestion workflow), [`ui/app.py`](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ui/app.py) (Desktop GUI), [`src/generator.py`](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/generator.py) (Answer generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["Interactive CLI<br/>[main.py]"]
  node_desktop["Desktop GUI<br/>[app.py]"]
  node_streamlit["Chunking demo<br/>[demo_streamlit.py]"]
end

subgraph group_knowledge["Knowledge preparation"]
  node_corpus["Regulations corpus"]
  node_loader["Document loader<br/>[loader.py]"]
  node_chunker["Document chunker<br/>[chunking.py]"]
  node_ingestion["Ingestion workflow<br/>[ingest.py]"]
  node_index[("Hybrid index<br/>[vector_db.py]")]
end

subgraph group_answering["Answer pipeline"]
  node_pipeline["RAG orchestrator<br/>[pipeline.py]"]
  node_normalizer["Query normalization"]
  node_localmodel["Local Qwen<br/>[local_slm.py]"]
  node_expansion["Legal query expansion<br/>[retrieval.py]"]
  node_textutils["Text folding<br/>[text_utils.py]"]
  node_generator["Answer generation<br/>[generator.py]"]
end

subgraph group_learning["Learning and evaluation"]
  node_feedback["Learning feedback<br/>[app.py]"]
  node_learncli["CLI learning mode<br/>[learn.py]"]
  node_evaluation["Pipeline evaluation<br/>[evaluation.py]"]
  node_benchmark["Chunking benchmark"]
end

node_student(("Student"))
node_gemini["Gemini API"]
node_ollama["Ollama service"]

node_student -->|"asks via"| node_cli
node_student -->|"asks via"| node_desktop
node_cli -->|"submits query"| node_pipeline
node_desktop -->|"submits query"| node_pipeline
node_pipeline -->|"normalizes with"| node_normalizer
node_normalizer -->|"uses"| node_localmodel
node_localmodel -->|"calls"| node_ollama
node_pipeline -->|"expands query"| node_expansion
node_pipeline -->|"retrieves from"| node_index
node_index -->|"folds tokens"| node_textutils
node_pipeline -->|"folds query"| node_textutils
node_pipeline -->|"generates answer"| node_generator
node_generator -->|"generates with"| node_gemini
node_generator -.->|"falls back to"| node_ollama
node_corpus -->|"provides documents"| node_loader
node_ingestion -->|"loads corpus"| node_loader
node_ingestion -->|"chunks documents"| node_chunker
node_ingestion -->|"builds index"| node_index
node_desktop -->|"starts reload"| node_ingestion
node_desktop -->|"records labels"| node_feedback
node_learncli -->|"tests queries"| node_pipeline
node_learncli -->|"refreshes corpus"| node_ingestion
node_evaluation -->|"evaluates runs"| node_pipeline
node_benchmark -->|"benchmarks strategies"| node_pipeline
node_streamlit -->|"compares strategies"| node_chunker
node_streamlit -->|"runs comparisons"| node_pipeline

click node_cli "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/main.py"
click node_desktop "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ui/app.py"
click node_streamlit "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/demo_streamlit.py"
click node_corpus "https://github.com/vandinh2912/hybrid_rag_agu/tree/main/data/corpus"
click node_loader "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/loader.py"
click node_chunker "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/chunking.py"
click node_ingestion "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ingest.py"
click node_index "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/vector_db.py"
click node_pipeline "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/pipeline.py"
click node_normalizer "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/query_normalizer.py"
click node_localmodel "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/local_slm.py"
click node_expansion "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/retrieval.py"
click node_textutils "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/text_utils.py"
click node_generator "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/generator.py"
click node_feedback "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ui/app.py"
click node_learncli "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/learn.py"
click node_evaluation "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/evaluation.py"
click node_benchmark "https://github.com/vandinh2912/hybrid_rag_agu/blob/main/benchmark_chunking.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_cli,node_desktop,node_streamlit toneBlue
class node_corpus,node_loader,node_chunker,node_ingestion,node_index toneAmber
class node_pipeline,node_normalizer,node_localmodel,node_expansion,node_textutils,node_generator,node_gemini toneMint
class node_feedback,node_learncli,node_evaluation,node_benchmark toneRose
class node_student,node_ollama toneIndigo
```

## Components

### User interfaces

- [Interactive CLI](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/main.py): `main.py`
- [Desktop GUI](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ui/app.py): `ui/app.py`
- [Chunking demo](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/demo_streamlit.py): `demo_streamlit.py`

### Knowledge preparation

- [Regulations corpus](https://github.com/vandinh2912/hybrid_rag_agu/tree/main/data/corpus): `data/corpus`
- [Document loader](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/loader.py): `src/loader.py`
- [Document chunker](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/chunking.py): `src/chunking.py`
- [Ingestion workflow](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ingest.py): `ingest.py`
- [Hybrid index](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/vector_db.py): `src/vector_db.py`

### Answer pipeline

- [RAG orchestrator](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/pipeline.py): `src/pipeline.py`
- [Query normalization](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/query_normalizer.py): `src/query_normalizer.py`
- [Local Qwen](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/local_slm.py): `src/local_slm.py`
- [Legal query expansion](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/retrieval.py): `src/retrieval.py`
- [Text folding](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/text_utils.py): `src/text_utils.py`
- [Answer generation](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/generator.py): `src/generator.py`

### Learning and evaluation

- [Learning feedback](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/ui/app.py): `ui/app.py`
- [CLI learning mode](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/learn.py): `learn.py`
- [Pipeline evaluation](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/src/evaluation.py): `src/evaluation.py`
- [Chunking benchmark](https://github.com/vandinh2912/hybrid_rag_agu/blob/main/benchmark_chunking.py): `benchmark_chunking.py`

### Other components

- **Student**
- **Gemini API**
- **Ollama service**

## Connections

- Student → Interactive CLI: asks via (evidence: `README.md`)
- Student → Desktop GUI: asks via (evidence: `README.md`)
- Interactive CLI → RAG orchestrator: submits query (evidence: `main.py`)
- Desktop GUI → RAG orchestrator: submits query (evidence: `ui/app.py`)
- RAG orchestrator → Query normalization: normalizes with (evidence: `src/pipeline.py`)
- Query normalization → Local Qwen: uses (evidence: `src/query_normalizer.py`)
- Local Qwen → Ollama service: calls (evidence: `src/local_slm.py`)
- RAG orchestrator → Legal query expansion: expands query (evidence: `src/pipeline.py`)
- RAG orchestrator → Hybrid index: retrieves from (evidence: `src/pipeline.py`)
- Hybrid index → Text folding: folds tokens (evidence: `src/vector_db.py`)
- RAG orchestrator → Text folding: folds query (evidence: `src/pipeline.py`)
- RAG orchestrator → Answer generation: generates answer (evidence: `README.md`)
- Answer generation → Gemini API: generates with (evidence: `src/generator.py`)
- Answer generation → Ollama service: falls back to (evidence: `README.md`)
- Regulations corpus → Document loader: provides documents
- Ingestion workflow → Document loader: loads corpus (evidence: `ingest.py`)
- Ingestion workflow → Document chunker: chunks documents (evidence: `ingest.py`)
- Ingestion workflow → Hybrid index: builds index (evidence: `ingest.py`)
- Desktop GUI → Ingestion workflow: starts reload (evidence: `ui/app.py`)
- Desktop GUI → Learning feedback: records labels (evidence: `ui/app.py`)
- CLI learning mode → RAG orchestrator: tests queries (evidence: `learn.py`)
- CLI learning mode → Ingestion workflow: refreshes corpus (evidence: `learn.py`)
- Pipeline evaluation → RAG orchestrator: evaluates runs (evidence: `src/evaluation.py`)
- Chunking benchmark → RAG orchestrator: benchmarks strategies (evidence: `benchmark_chunking.py`)
- Chunking demo → Document chunker: compares strategies (evidence: `demo_streamlit.py`)
- Chunking demo → RAG orchestrator: runs comparisons (evidence: `demo_streamlit.py`)
