# devhong96/rag architecture

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

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

## Overview

This is a RAG study and pipeline playground. Its central user-to-result path is an API question routed through request safeguards, document retrieval, and LLM answer generation with citation checks. The repository also provides distinct wiki and OCR ingestion/search pipelines, graph search, conversational RAG, query routing, and answer evaluation. The graph emphasizes runtime product components rather than lecture scripts. Some subsystem links are documented in the README or SOURCE INDEX; unsampled implementations are not assumed to have unshown call relationships.

Main entry points: [`src/lib/rag.ts`](https://github.com/devhong96/rag/blob/master/src/lib/rag.ts) (RAG orchestration), [`src/server/routes/ask.ts`](https://github.com/devhong96/rag/blob/master/src/server/routes/ask.ts) (Ask endpoint), [`src/lib/llm.ts`](https://github.com/devhong96/rag/blob/master/src/lib/llm.ts) (Ollama chat), [`src/lib/chroma.ts`](https://github.com/devhong96/rag/blob/master/src/lib/chroma.ts) (Vector database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and conversation"]
  node_server["REST server<br/>[index.ts]"]
  node_ask["Ask endpoint<br/>[ask.ts]"]
  node_chat["Chat CLI<br/>[chat.ts]"]
  node_conversation["Conversation state<br/>[conversation.ts]"]
  node_conversationdb[("SQLite history")]
end

subgraph group_rag["RAG foundation"]
  node_rag["RAG orchestration<br/>[rag.ts]"]
  node_documents["Document service<br/>[documents.ts]"]
  node_chunking["Text chunking<br/>[fixed.ts]"]
  node_chroma[("Vector database<br/>[chroma.ts]")]
  node_embedding["Ollama embeddings"]
  node_llm["Ollama chat<br/>[llm.ts]"]
  node_citations["Citation checks<br/>[citations.ts]"]
end

subgraph group_ingestion["Content pipelines"]
  node_wiki["Wiki pipeline<br/>[pipeline.ts]"]
  node_wikifetch["Wiki collection<br/>[fetch.ts]"]
  node_ocr["OCR pipeline<br/>[pipeline.ts]"]
  node_ocrengine["OCR engine<br/>[engine.ts]"]
end

subgraph group_search["Search and graph"]
  node_graphsearch["Graph search<br/>[search.ts]"]
  node_graphclient["Neo4j client<br/>[client.ts]"]
  node_neo4j[("Neo4j database")]
  node_sqlitevector[("SQLite vector search<br/>[vector-store.ts]")]
end

subgraph group_quality["Routing and evaluation"]
  node_routing["Query router<br/>[router.ts]"]
  node_routeapp["Routing demo<br/>[route-demo.ts]"]
  node_evaluation["Answer evaluation<br/>[answer-eval.ts]"]
  node_judge["LLM judge<br/>[judge.ts]"]
end

node_user(("API client"))

node_user -->|"sends requests"| node_server
node_server -->|"registers route"| node_ask
node_ask -->|"requests answers"| node_rag
node_ask -->|"persists history"| node_conversationdb
node_ask -->|"uses conversation"| node_conversation
node_ask -->|"checks safeguards"| node_rag
node_chat -->|"runs conversational RAG"| node_rag
node_rag -->|"searches documents"| node_documents
node_rag -->|"generates answers"| node_llm
node_rag -->|"checks citations"| node_citations
node_documents -->|"chunks text"| node_chunking
node_documents -->|"queries and stores"| node_chroma
node_chroma -->|"embeds documents"| node_embedding
node_llm -->|"calls model service"| node_user
node_wiki -->|"uses fetched articles"| node_wikifetch
node_wiki -->|"indexes chunks"| node_chroma
node_wiki -->|"chunks sections"| node_chunking
node_ocr -->|"extracts text"| node_ocrengine
node_ocr -->|"restores document structure"| node_llm
node_ocr -->|"indexes chunks"| node_chroma
node_graphsearch -->|"queries graph"| node_graphclient
node_graphclient -->|"reads graph data"| node_neo4j
node_routeapp -->|"plans route"| node_routing
node_routeapp -->|"runs vector RAG"| node_rag
node_routing -->|"classifies questions"| node_llm
node_evaluation -->|"evaluates answers"| node_rag
node_evaluation -->|"scores answers"| node_judge
node_judge -->|"requests judgments"| node_llm
node_sqlitevector -.->|"supports semantic search"| node_user

click node_server "https://github.com/devhong96/rag/blob/master/src/server/index.ts"
click node_ask "https://github.com/devhong96/rag/blob/master/src/server/routes/ask.ts"
click node_chat "https://github.com/devhong96/rag/blob/master/src/chat.ts"
click node_conversation "https://github.com/devhong96/rag/blob/master/src/lib/conversation.ts"
click node_conversationdb "https://github.com/devhong96/rag/blob/master/src/sqlite/conversation-store.ts"
click node_rag "https://github.com/devhong96/rag/blob/master/src/lib/rag.ts"
click node_documents "https://github.com/devhong96/rag/blob/master/src/lib/documents.ts"
click node_chunking "https://github.com/devhong96/rag/blob/master/src/lib/chunking/fixed.ts"
click node_chroma "https://github.com/devhong96/rag/blob/master/src/lib/chroma.ts"
click node_embedding "https://github.com/devhong96/rag/blob/master/src/lib/ollama-embedding.ts"
click node_llm "https://github.com/devhong96/rag/blob/master/src/lib/llm.ts"
click node_citations "https://github.com/devhong96/rag/blob/master/src/lib/citations.ts"
click node_wiki "https://github.com/devhong96/rag/blob/master/src/wiki/pipeline.ts"
click node_wikifetch "https://github.com/devhong96/rag/blob/master/src/wiki/fetch.ts"
click node_ocr "https://github.com/devhong96/rag/blob/master/src/ocr/pipeline.ts"
click node_ocrengine "https://github.com/devhong96/rag/blob/master/src/ocr/engine.ts"
click node_graphsearch "https://github.com/devhong96/rag/blob/master/src/graph-db/search.ts"
click node_graphclient "https://github.com/devhong96/rag/blob/master/src/graph-db/client.ts"
click node_routing "https://github.com/devhong96/rag/blob/master/src/lib/router.ts"
click node_routeapp "https://github.com/devhong96/rag/blob/master/src/route-demo.ts"
click node_evaluation "https://github.com/devhong96/rag/blob/master/src/eval/answer-eval.ts"
click node_judge "https://github.com/devhong96/rag/blob/master/src/lib/eval/judge.ts"
click node_sqlitevector "https://github.com/devhong96/rag/blob/master/src/sqlite/vector-store.ts"

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_server,node_ask,node_chat,node_conversation,node_conversationdb,node_user toneBlue
class node_rag,node_documents,node_chunking,node_chroma,node_embedding,node_llm,node_citations toneAmber
class node_wiki,node_wikifetch,node_ocr,node_ocrengine toneMint
class node_graphsearch,node_graphclient,node_neo4j,node_sqlitevector toneRose
class node_routing,node_routeapp,node_evaluation,node_judge toneIndigo
```

## Components

### API and conversation

- [REST server](https://github.com/devhong96/rag/blob/master/src/server/index.ts): `src/server/index.ts`
- [Ask endpoint](https://github.com/devhong96/rag/blob/master/src/server/routes/ask.ts): `src/server/routes/ask.ts`
- [Chat CLI](https://github.com/devhong96/rag/blob/master/src/chat.ts): `src/chat.ts`
- [Conversation state](https://github.com/devhong96/rag/blob/master/src/lib/conversation.ts): `src/lib/conversation.ts`
- [SQLite history](https://github.com/devhong96/rag/blob/master/src/sqlite/conversation-store.ts): `src/sqlite/conversation-store.ts`

### RAG foundation

- [RAG orchestration](https://github.com/devhong96/rag/blob/master/src/lib/rag.ts): `src/lib/rag.ts`
- [Document service](https://github.com/devhong96/rag/blob/master/src/lib/documents.ts): `src/lib/documents.ts`
- [Text chunking](https://github.com/devhong96/rag/blob/master/src/lib/chunking/fixed.ts): `src/lib/chunking/fixed.ts`
- [Vector database](https://github.com/devhong96/rag/blob/master/src/lib/chroma.ts): `src/lib/chroma.ts`
- [Ollama embeddings](https://github.com/devhong96/rag/blob/master/src/lib/ollama-embedding.ts): `src/lib/ollama-embedding.ts`
- [Ollama chat](https://github.com/devhong96/rag/blob/master/src/lib/llm.ts): `src/lib/llm.ts`
- [Citation checks](https://github.com/devhong96/rag/blob/master/src/lib/citations.ts): `src/lib/citations.ts`

### Content pipelines

- [Wiki pipeline](https://github.com/devhong96/rag/blob/master/src/wiki/pipeline.ts): `src/wiki/pipeline.ts`
- [Wiki collection](https://github.com/devhong96/rag/blob/master/src/wiki/fetch.ts): `src/wiki/fetch.ts`
- [OCR pipeline](https://github.com/devhong96/rag/blob/master/src/ocr/pipeline.ts): `src/ocr/pipeline.ts`
- [OCR engine](https://github.com/devhong96/rag/blob/master/src/ocr/engine.ts): `src/ocr/engine.ts`

### Search and graph

- [Graph search](https://github.com/devhong96/rag/blob/master/src/graph-db/search.ts): `src/graph-db/search.ts`
- [Neo4j client](https://github.com/devhong96/rag/blob/master/src/graph-db/client.ts): `src/graph-db/client.ts`
- **Neo4j database**
- [SQLite vector search](https://github.com/devhong96/rag/blob/master/src/sqlite/vector-store.ts): `src/sqlite/vector-store.ts`

### Routing and evaluation

- [Query router](https://github.com/devhong96/rag/blob/master/src/lib/router.ts): `src/lib/router.ts`
- [Routing demo](https://github.com/devhong96/rag/blob/master/src/route-demo.ts): `src/route-demo.ts`
- [Answer evaluation](https://github.com/devhong96/rag/blob/master/src/eval/answer-eval.ts): `src/eval/answer-eval.ts`
- [LLM judge](https://github.com/devhong96/rag/blob/master/src/lib/eval/judge.ts): `src/lib/eval/judge.ts`

### Other components

- **API client**

## Connections

- API client → REST server: sends requests (evidence: `README.md`)
- REST server → Ask endpoint: registers route (evidence: `src/server/index.ts`)
- Ask endpoint → RAG orchestration: requests answers (evidence: `src/server/routes/ask.ts`)
- Ask endpoint → SQLite history: persists history (evidence: `README.md`)
- Ask endpoint → Conversation state: uses conversation (evidence: `src/server/routes/ask.ts`)
- Ask endpoint → RAG orchestration: checks safeguards (evidence: `src/server/routes/ask.ts`)
- Chat CLI → RAG orchestration: runs conversational RAG (evidence: `README.md`)
- RAG orchestration → Document service: searches documents (evidence: `src/lib/rag.ts`)
- RAG orchestration → Ollama chat: generates answers (evidence: `src/lib/rag.ts`)
- RAG orchestration → Citation checks: checks citations (evidence: `src/lib/rag.ts`)
- Document service → Text chunking: chunks text (evidence: `src/lib/documents.ts`)
- Document service → Vector database: queries and stores (evidence: `src/lib/documents.ts`)
- Vector database → Ollama embeddings: embeds documents (evidence: `src/lib/chroma.ts`)
- Ollama chat → API client: calls model service (evidence: `src/lib/llm.ts`)
- Wiki pipeline → Wiki collection: uses fetched articles (evidence: `src/wiki/ingest.ts`)
- Wiki pipeline → Vector database: indexes chunks (evidence: `README.md`)
- Wiki pipeline → Text chunking: chunks sections (evidence: `src/wiki/pipeline.ts`)
- OCR pipeline → OCR engine: extracts text (evidence: `src/ocr/pipeline.ts`)
- OCR pipeline → Ollama chat: restores document structure (evidence: `src/ocr/pipeline.ts`)
- OCR pipeline → Vector database: indexes chunks (evidence: `README.md`)
- Graph search → Neo4j client: queries graph (evidence: `src/graph-db/search.ts`)
- Neo4j client → Neo4j database: reads graph data (evidence: `README.md`)
- Routing demo → Query router: plans route (evidence: `src/route-demo.ts`)
- Routing demo → RAG orchestration: runs vector RAG (evidence: `src/route-demo.ts`)
- Query router → Ollama chat: classifies questions (evidence: `src/lib/router.ts`)
- Answer evaluation → RAG orchestration: evaluates answers (evidence: `src/eval/answer-eval.ts`)
- Answer evaluation → LLM judge: scores answers (evidence: `src/eval/answer-eval.ts`)
- LLM judge → Ollama chat: requests judgments (evidence: `src/lib/eval/judge.ts`)
- SQLite vector search → API client: supports semantic search (evidence: `README.md`)
