# younesameziane/local-rag architecture

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

- Interactive diagram: https://gitdiagram.com/younesameziane/local-rag
- Repository: https://github.com/younesameziane/local-rag

## Overview

This is a local, on-premises data-governance assistant. Users ask through the browser UI or terminal; chat maintains turn state, routes each question, retrieves catalog or document context, and generates read-only SQL when needed. Separate ingestion paths populate the two Qdrant collections. The graph follows documented workflows and sampled references; unsampled implementation details are not used to infer additional calls.

Main entry points: [`chat.py`](https://github.com/younesameziane/local-rag/blob/main/chat.py) (Turn coordinator), [`llm.py`](https://github.com/younesameziane/local-rag/blob/main/llm.py) (Local model client), [`sql_generator.py`](https://github.com/younesameziane/local-rag/blob/main/sql_generator.py) (SQL generation and validation), [`retriever.py`](https://github.com/younesameziane/local-rag/blob/main/retriever.py) (Catalog and document retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_webui["Browser UI<br/>[webui.py]"]
  node_terminal["Terminal chat<br/>[chat.py]"]
end

subgraph group_conversation["Conversation and routing"]
  node_chat["Turn coordinator<br/>[chat.py]"]
  node_session["Conversation state<br/>[session.py]"]
  node_router["Question router<br/>[router.py]"]
  node_llm["Local model client<br/>[llm.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_knowledge["Knowledge retrieval"]
  node_retriever["Catalog and document retrieval<br/>[retriever.py]"]
  node_lexical["BM25 ranking<br/>[lexical.py]"]
  node_qdrant[("Qdrant vector store")]
end

subgraph group_sql["SQL answering"]
  node_sqlgen["SQL generation and validation<br/>[sql_generator.py]"]
  node_planner["Multi-step SQL planner<br/>[planner.py]"]
  node_dbpool["Connection pool<br/>[db_pool.py]"]
  node_sqlserver[("MetadataRepository")]
end

subgraph group_ingestion["Knowledge ingestion"]
  node_dataingest["Catalog ingestion<br/>[ingest.py]"]
  node_docingest["Document ingestion<br/>[ingest_docs.py]"]
  node_chunker["Document chunking<br/>[chunker.py]"]
  node_registry["Document registry<br/>[doc_registry.py]"]
end

node_user(("User"))
node_browser(("Browser"))

node_user -->|"asks via"| node_webui
node_browser -->|"uses"| node_webui
node_user -->|"asks via"| node_terminal
node_webui -->|"submits turns"| node_chat
node_terminal -->|"runs turns"| node_chat
node_chat -->|"uses state"| node_session
node_chat -->|"routes questions"| node_router
node_chat -->|"retrieves context"| node_retriever
node_chat -->|"runs SQL path"| node_sqlgen
node_chat -->|"generates responses"| node_llm
node_router -->|"classifies with"| node_llm
node_retriever -->|"searches collections"| node_qdrant
node_retriever -->|"fuses rankings"| node_lexical
node_retriever -->|"rewrites queries"| node_llm
node_sqlgen -->|"gets schema context"| node_retriever
node_sqlgen -->|"generates SQL"| node_llm
node_sqlgen -->|"delegates enumeration"| node_planner
node_planner -->|"checks out connection"| node_dbpool
node_sqlgen -->|"checks out connection"| node_dbpool
node_dbpool -->|"opens connections"| node_sqlserver
node_dataingest -->|"reads catalog"| node_sqlserver
node_dataingest -->|"embeds chunks"| node_llm
node_dataingest -->|"upserts vectors"| node_qdrant
node_docingest -->|"chunks files"| node_chunker
node_docingest -->|"embeds chunks"| node_llm
node_docingest -->|"upserts vectors"| node_qdrant
node_docingest -->|"tracks file state"| node_registry
node_config -->|"configures clients"| node_llm
node_config -->|"sets pool size"| node_dbpool

click node_webui "https://github.com/younesameziane/local-rag/blob/main/webui.py"
click node_terminal "https://github.com/younesameziane/local-rag/blob/main/chat.py"
click node_chat "https://github.com/younesameziane/local-rag/blob/main/chat.py"
click node_session "https://github.com/younesameziane/local-rag/blob/main/session.py"
click node_router "https://github.com/younesameziane/local-rag/blob/main/router.py"
click node_llm "https://github.com/younesameziane/local-rag/blob/main/llm.py"
click node_retriever "https://github.com/younesameziane/local-rag/blob/main/retriever.py"
click node_lexical "https://github.com/younesameziane/local-rag/blob/main/lexical.py"
click node_sqlgen "https://github.com/younesameziane/local-rag/blob/main/sql_generator.py"
click node_planner "https://github.com/younesameziane/local-rag/blob/main/planner.py"
click node_dbpool "https://github.com/younesameziane/local-rag/blob/main/db_pool.py"
click node_dataingest "https://github.com/younesameziane/local-rag/blob/main/ingest.py"
click node_docingest "https://github.com/younesameziane/local-rag/blob/main/ingest_docs.py"
click node_chunker "https://github.com/younesameziane/local-rag/blob/main/chunker.py"
click node_registry "https://github.com/younesameziane/local-rag/blob/main/doc_registry.py"
click node_config "https://github.com/younesameziane/local-rag/blob/main/config.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_webui,node_terminal,node_user,node_browser toneBlue
class node_chat,node_session,node_router,node_llm,node_config toneAmber
class node_retriever,node_lexical,node_qdrant toneMint
class node_sqlgen,node_planner,node_dbpool,node_sqlserver toneRose
class node_dataingest,node_docingest,node_chunker,node_registry toneIndigo
```

## Components

### User interfaces

- [Browser UI](https://github.com/younesameziane/local-rag/blob/main/webui.py): `webui.py`
- [Terminal chat](https://github.com/younesameziane/local-rag/blob/main/chat.py): `chat.py`

### Conversation and routing

- [Turn coordinator](https://github.com/younesameziane/local-rag/blob/main/chat.py): `chat.py`
- [Conversation state](https://github.com/younesameziane/local-rag/blob/main/session.py): `session.py`
- [Question router](https://github.com/younesameziane/local-rag/blob/main/router.py): `router.py`
- [Local model client](https://github.com/younesameziane/local-rag/blob/main/llm.py): `llm.py`
- [Runtime configuration](https://github.com/younesameziane/local-rag/blob/main/config.py): `config.py`

### Knowledge retrieval

- [Catalog and document retrieval](https://github.com/younesameziane/local-rag/blob/main/retriever.py): `retriever.py`
- [BM25 ranking](https://github.com/younesameziane/local-rag/blob/main/lexical.py): `lexical.py`
- **Qdrant vector store**

### SQL answering

- [SQL generation and validation](https://github.com/younesameziane/local-rag/blob/main/sql_generator.py): `sql_generator.py`
- [Multi-step SQL planner](https://github.com/younesameziane/local-rag/blob/main/planner.py): `planner.py`
- [Connection pool](https://github.com/younesameziane/local-rag/blob/main/db_pool.py): `db_pool.py`
- **MetadataRepository**

### Knowledge ingestion

- [Catalog ingestion](https://github.com/younesameziane/local-rag/blob/main/ingest.py): `ingest.py`
- [Document ingestion](https://github.com/younesameziane/local-rag/blob/main/ingest_docs.py): `ingest_docs.py`
- [Document chunking](https://github.com/younesameziane/local-rag/blob/main/chunker.py): `chunker.py`
- [Document registry](https://github.com/younesameziane/local-rag/blob/main/doc_registry.py): `doc_registry.py`

### Other components

- **User**
- **Browser**

## Connections

- User → Browser UI: asks via (evidence: `README.md`)
- Browser → Browser UI: uses (evidence: `README.md`)
- User → Terminal chat: asks via (evidence: `README.md`)
- Browser UI → Turn coordinator: submits turns (evidence: `README.md`)
- Terminal chat → Turn coordinator: runs turns (evidence: `README.md`)
- Turn coordinator → Conversation state: uses state (evidence: `chat.py`)
- Turn coordinator → Question router: routes questions (evidence: `chat.py`)
- Turn coordinator → Catalog and document retrieval: retrieves context (evidence: `chat.py`)
- Turn coordinator → SQL generation and validation: runs SQL path (evidence: `chat.py`)
- Turn coordinator → Local model client: generates responses (evidence: `chat.py`)
- Question router → Local model client: classifies with (evidence: `README.md`)
- Catalog and document retrieval → Qdrant vector store: searches collections (evidence: `README.md`)
- Catalog and document retrieval → BM25 ranking: fuses rankings (evidence: `retriever.py`)
- Catalog and document retrieval → Local model client: rewrites queries (evidence: `README.md`)
- SQL generation and validation → Catalog and document retrieval: gets schema context (evidence: `sql_generator.py`)
- SQL generation and validation → Local model client: generates SQL (evidence: `README.md`)
- SQL generation and validation → Multi-step SQL planner: delegates enumeration (evidence: `README.md`)
- Multi-step SQL planner → Connection pool: checks out connection (evidence: `planner.py`)
- SQL generation and validation → Connection pool: checks out connection (evidence: `sql_generator.py`)
- Connection pool → MetadataRepository: opens connections (evidence: `db_pool.py`)
- Catalog ingestion → MetadataRepository: reads catalog (evidence: `ingest.py`)
- Catalog ingestion → Local model client: embeds chunks (evidence: `ingest.py`)
- Catalog ingestion → Qdrant vector store: upserts vectors (evidence: `ingest.py`)
- Document ingestion → Document chunking: chunks files (evidence: `ingest_docs.py`)
- Document ingestion → Local model client: embeds chunks (evidence: `ingest_docs.py`)
- Document ingestion → Qdrant vector store: upserts vectors (evidence: `ingest_docs.py`)
- Document ingestion → Document registry: tracks file state (evidence: `ingest_docs.py`)
- Runtime configuration → Local model client: configures clients (evidence: `llm.py`)
- Runtime configuration → Connection pool: sets pool size (evidence: `db_pool.py`)
