# stan-ely/lakehouse-rag architecture

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

- Interactive diagram: https://gitdiagram.com/stan-ely/lakehouse-rag
- Repository: https://github.com/stan-ely/lakehouse-rag

## Overview

lakehouse-rag is an access-controlled enterprise RAG service with a document lakehouse ingestion path and a FastAPI query path that combines hybrid document retrieval and guarded text-to-SQL. The principal workflow authenticates a caller, routes their question, runs the required tools, and produces a cited answer or uniform refusal. The graph includes documented ingestion stages and serving safeguards; unsampled modules are represented only where the README or source index supports their role and connections.

Main entry points: [`app/orchestrator.py`](https://github.com/stan-ely/lakehouse-rag/blob/main/app/orchestrator.py) (Query orchestrator), [`app/generation/answer.py`](https://github.com/stan-ely/lakehouse-rag/blob/main/app/generation/answer.py) (Grounded answers), [`app/sql_tool/service.py`](https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/service.py) (SQL tool), [`app/api/main.py`](https://github.com/stan-ely/lakehouse-rag/blob/main/app/api/main.py) (Query API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Query serving"]
  node_ui["Persona UI<br/>[streamlit_app.py]"]
  node_api["Query API<br/>[main.py]"]
  node_auth["JWT identity<br/>[auth.py]"]
  node_orchestrator["Query orchestrator<br/>[orchestrator.py]"]
  node_router["Route classifier<br/>[classifier.py]"]
  node_retrieval["Hybrid retrieval<br/>[hybrid.py]"]
  node_answer["Grounded answers<br/>[answer.py]"]
  node_prompt["Answer prompting<br/>[prompt.py]"]
  node_sqltool["SQL tool<br/>[service.py]"]
  node_catalog["SQL catalog<br/>[catalog.py]"]
  node_validator["SQL validation<br/>[validator.py]"]
  node_executor["SQL executor<br/>[executor.py]"]
  node_opsdb[("Operations data")]
  node_llm["LLM providers<br/>[base.py]"]
end

subgraph group_ingest["Lakehouse ingestion"]
  node_vectorstore[("Chunks and vectors")]
  node_spark["Spark medallion job<br/>[run.py]"]
  node_bronze[("Bronze objects<br/>[bronze.py]")]
  node_silver[("Silver documents<br/>[silver.py]")]
  node_gold[("Gold chunks<br/>[gold.py]")]
  node_indexer["Incremental indexer<br/>[run.py]"]
  node_embed["Chunk embeddings<br/>[embed.py]"]
  node_store["Index store<br/>[store.py]"]
  node_register["Event registration<br/>[handler.py]"]
  node_ingestsource[("Source files")]
end

subgraph group_data["Data and evaluation"]
  node_facts["Business facts<br/>[facts.py]"]
  node_models["Generated data models<br/>[models.py]"]
  node_world["Synthetic world<br/>[world.py]"]
  node_golden["Golden evaluation<br/>[golden.py]"]
end

subgraph group_ops["Runtime safeguards"]
  node_cost["Usage costing<br/>[cost.py]"]
  node_pii["PII masking<br/>[pii.py]"]
  node_settings["Runtime settings<br/>[settings.py]"]
  node_logging["Structured logging<br/>[logging.py]"]
  node_tracing["Optional tracing<br/>[tracing.py]"]
end

node_employee(("Employee"))

node_employee -->|"asks through"| node_ui
node_ui -->|"submits query"| node_api
node_api -->|"decodes token"| node_auth
node_api -->|"serves query"| node_orchestrator
node_orchestrator -->|"routes question"| node_router
node_orchestrator -->|"runs SQL leg"| node_sqltool
node_orchestrator -->|"requests answer"| node_answer
node_answer -->|"searches sources"| node_retrieval
node_answer -->|"builds prompt"| node_prompt
node_answer -->|"generates response"| node_llm
node_retrieval -->|"queries chunks"| node_vectorstore
node_sqltool -->|"loads schema"| node_catalog
node_sqltool -->|"writes SQL"| node_llm
node_sqltool -->|"validates query"| node_validator
node_sqltool -->|"runs validated SQL"| node_executor
node_executor -->|"queries views"| node_opsdb
node_orchestrator -->|"totals request cost"| node_cost
node_ingestsource -->|"raises event"| node_register
node_register -->|"records manifest"| node_bronze
node_spark -->|"builds bronze"| node_bronze
node_spark -->|"builds silver"| node_silver
node_spark -->|"builds gold"| node_gold
node_bronze -->|"parses and tags"| node_silver
node_silver -->|"forms chunks"| node_gold
node_gold -->|"feeds changes"| node_indexer
node_indexer -->|"creates embeddings"| node_embed
node_indexer -->|"writes index"| node_store
node_store -->|"stores vectors"| node_vectorstore
node_answer -->|"masks answer"| node_pii
node_settings -.->|"configures optionally"| node_tracing
node_tracing -->|"masks trace content"| node_pii
node_api -->|"configures logging"| node_logging
node_facts -->|"informs data world"| node_world
node_facts -->|"defines expectations"| node_golden
node_world -->|"supplies expected data"| node_golden
node_models -->|"models generated entities"| node_world

click node_ui "https://github.com/stan-ely/lakehouse-rag/blob/main/ui/streamlit_app.py"
click node_api "https://github.com/stan-ely/lakehouse-rag/blob/main/app/api/main.py"
click node_auth "https://github.com/stan-ely/lakehouse-rag/blob/main/app/auth.py"
click node_orchestrator "https://github.com/stan-ely/lakehouse-rag/blob/main/app/orchestrator.py"
click node_router "https://github.com/stan-ely/lakehouse-rag/blob/main/app/router/classifier.py"
click node_retrieval "https://github.com/stan-ely/lakehouse-rag/blob/main/app/retrieval/hybrid.py"
click node_answer "https://github.com/stan-ely/lakehouse-rag/blob/main/app/generation/answer.py"
click node_prompt "https://github.com/stan-ely/lakehouse-rag/blob/main/app/generation/prompt.py"
click node_sqltool "https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/service.py"
click node_catalog "https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/catalog.py"
click node_validator "https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/validator.py"
click node_executor "https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/executor.py"
click node_llm "https://github.com/stan-ely/lakehouse-rag/blob/main/app/llm/base.py"
click node_cost "https://github.com/stan-ely/lakehouse-rag/blob/main/app/llm/cost.py"
click node_spark "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/run.py"
click node_bronze "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/bronze.py"
click node_silver "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/silver.py"
click node_gold "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/gold.py"
click node_indexer "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/indexer/run.py"
click node_embed "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/indexer/embed.py"
click node_store "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/indexer/store.py"
click node_register "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/lambda_register/handler.py"
click node_pii "https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/pii.py"
click node_settings "https://github.com/stan-ely/lakehouse-rag/blob/main/app/settings.py"
click node_logging "https://github.com/stan-ely/lakehouse-rag/blob/main/app/observability/logging.py"
click node_tracing "https://github.com/stan-ely/lakehouse-rag/blob/main/app/observability/tracing.py"
click node_facts "https://github.com/stan-ely/lakehouse-rag/blob/main/data_gen/facts.py"
click node_models "https://github.com/stan-ely/lakehouse-rag/blob/main/data_gen/models.py"
click node_world "https://github.com/stan-ely/lakehouse-rag/blob/main/data_gen/world.py"
click node_golden "https://github.com/stan-ely/lakehouse-rag/blob/main/eval/golden.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_ui,node_api,node_auth,node_orchestrator,node_router,node_retrieval,node_answer,node_prompt,node_sqltool,node_catalog,node_validator,node_executor,node_opsdb,node_llm toneBlue
class node_vectorstore,node_spark,node_bronze,node_silver,node_gold,node_indexer,node_embed,node_store,node_register,node_ingestsource toneAmber
class node_facts,node_models,node_world,node_golden toneMint
class node_cost,node_pii,node_settings,node_logging,node_tracing toneRose
class node_employee toneIndigo
```

## Components

### Query serving

- [Persona UI](https://github.com/stan-ely/lakehouse-rag/blob/main/ui/streamlit_app.py): `ui/streamlit_app.py`
- [Query API](https://github.com/stan-ely/lakehouse-rag/blob/main/app/api/main.py): `app/api/main.py`
- [JWT identity](https://github.com/stan-ely/lakehouse-rag/blob/main/app/auth.py): `app/auth.py`
- [Query orchestrator](https://github.com/stan-ely/lakehouse-rag/blob/main/app/orchestrator.py): `app/orchestrator.py`
- [Route classifier](https://github.com/stan-ely/lakehouse-rag/blob/main/app/router/classifier.py): `app/router/classifier.py`
- [Hybrid retrieval](https://github.com/stan-ely/lakehouse-rag/blob/main/app/retrieval/hybrid.py): `app/retrieval/hybrid.py`
- [Grounded answers](https://github.com/stan-ely/lakehouse-rag/blob/main/app/generation/answer.py): `app/generation/answer.py`
- [Answer prompting](https://github.com/stan-ely/lakehouse-rag/blob/main/app/generation/prompt.py): `app/generation/prompt.py`
- [SQL tool](https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/service.py): `app/sql_tool/service.py`
- [SQL catalog](https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/catalog.py): `app/sql_tool/catalog.py`
- [SQL validation](https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/validator.py): `app/sql_tool/validator.py`
- [SQL executor](https://github.com/stan-ely/lakehouse-rag/blob/main/app/sql_tool/executor.py): `app/sql_tool/executor.py`
- **Operations data**
- [LLM providers](https://github.com/stan-ely/lakehouse-rag/blob/main/app/llm/base.py): `app/llm/base.py`

### Lakehouse ingestion

- **Chunks and vectors**
- [Spark medallion job](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/run.py): `ingestion/spark/run.py`
- [Bronze objects](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/bronze.py): `ingestion/spark/bronze.py`
- [Silver documents](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/silver.py): `ingestion/spark/silver.py`
- [Gold chunks](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/spark/gold.py): `ingestion/spark/gold.py`
- [Incremental indexer](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/indexer/run.py): `ingestion/indexer/run.py`
- [Chunk embeddings](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/indexer/embed.py): `ingestion/indexer/embed.py`
- [Index store](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/indexer/store.py): `ingestion/indexer/store.py`
- [Event registration](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/lambda_register/handler.py): `ingestion/lambda_register/handler.py`
- **Source files**

### Data and evaluation

- [Business facts](https://github.com/stan-ely/lakehouse-rag/blob/main/data_gen/facts.py): `data_gen/facts.py`
- [Generated data models](https://github.com/stan-ely/lakehouse-rag/blob/main/data_gen/models.py): `data_gen/models.py`
- [Synthetic world](https://github.com/stan-ely/lakehouse-rag/blob/main/data_gen/world.py): `data_gen/world.py`
- [Golden evaluation](https://github.com/stan-ely/lakehouse-rag/blob/main/eval/golden.py): `eval/golden.py`

### Runtime safeguards

- [Usage costing](https://github.com/stan-ely/lakehouse-rag/blob/main/app/llm/cost.py): `app/llm/cost.py`
- [PII masking](https://github.com/stan-ely/lakehouse-rag/blob/main/ingestion/pii.py): `ingestion/pii.py`
- [Runtime settings](https://github.com/stan-ely/lakehouse-rag/blob/main/app/settings.py): `app/settings.py`
- [Structured logging](https://github.com/stan-ely/lakehouse-rag/blob/main/app/observability/logging.py): `app/observability/logging.py`
- [Optional tracing](https://github.com/stan-ely/lakehouse-rag/blob/main/app/observability/tracing.py): `app/observability/tracing.py`

### Other components

- **Employee**

## Connections

- Employee → Persona UI: asks through (evidence: `README.md`)
- Persona UI → Query API: submits query (evidence: `README.md`)
- Query API → JWT identity: decodes token (evidence: `app/api/main.py`)
- Query API → Query orchestrator: serves query (evidence: `app/api/main.py`)
- Query orchestrator → Route classifier: routes question (evidence: `app/orchestrator.py`)
- Query orchestrator → SQL tool: runs SQL leg (evidence: `app/orchestrator.py`)
- Query orchestrator → Grounded answers: requests answer (evidence: `app/orchestrator.py`)
- Grounded answers → Hybrid retrieval: searches sources (evidence: `app/generation/answer.py`)
- Grounded answers → Answer prompting: builds prompt (evidence: `app/generation/answer.py`)
- Grounded answers → LLM providers: generates response (evidence: `app/generation/answer.py`)
- Hybrid retrieval → Chunks and vectors: queries chunks (evidence: `README.md`)
- SQL tool → SQL catalog: loads schema (evidence: `app/sql_tool/service.py`)
- SQL tool → LLM providers: writes SQL (evidence: `app/sql_tool/service.py`)
- SQL tool → SQL validation: validates query (evidence: `app/sql_tool/service.py`)
- SQL tool → SQL executor: runs validated SQL (evidence: `app/sql_tool/service.py`)
- SQL executor → Operations data: queries views (evidence: `README.md`)
- Query orchestrator → Usage costing: totals request cost (evidence: `app/orchestrator.py`)
- Source files → Event registration: raises event (evidence: `README.md`)
- Event registration → Bronze objects: records manifest (evidence: `README.md`)
- Spark medallion job → Bronze objects: builds bronze (evidence: `README.md`)
- Spark medallion job → Silver documents: builds silver (evidence: `README.md`)
- Spark medallion job → Gold chunks: builds gold (evidence: `README.md`)
- Bronze objects → Silver documents: parses and tags (evidence: `README.md`)
- Silver documents → Gold chunks: forms chunks (evidence: `README.md`)
- Gold chunks → Incremental indexer: feeds changes (evidence: `README.md`)
- Incremental indexer → Chunk embeddings: creates embeddings (evidence: `README.md`)
- Incremental indexer → Index store: writes index (evidence: `README.md`)
- Index store → Chunks and vectors: stores vectors (evidence: `README.md`)
- Grounded answers → PII masking: masks answer (evidence: `app/generation/answer.py`)
- Runtime settings → Optional tracing: configures optionally (evidence: `app/observability/tracing.py`)
- Optional tracing → PII masking: masks trace content (evidence: `app/observability/tracing.py`)
- Query API → Structured logging: configures logging (evidence: `app/api/main.py`)
- Business facts → Synthetic world: informs data world (evidence: `data_gen/world.py`)
- Business facts → Golden evaluation: defines expectations (evidence: `README.md`)
- Synthetic world → Golden evaluation: supplies expected data (evidence: `README.md`)
- Generated data models → Synthetic world: models generated entities (evidence: `data_gen/world.py`)
