How devhong96/rag works
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: rag.ts RAG orchestration · ask.ts Ask endpoint · llm.ts Ollama chat · chroma.ts Vector database
Components 25
API and conversation
- REST server
src/server/index.ts - Ask endpoint
src/server/routes/ask.ts - Chat CLI
src/chat.ts - Conversation state
src/lib/conversation.ts - SQLite history
src/sqlite/conversation-store.ts
RAG foundation
- RAG orchestration
src/lib/rag.ts - Document service
src/lib/documents.ts - Text chunking
src/lib/chunking/fixed.ts - Vector database
src/lib/chroma.ts - Ollama embeddings
src/lib/ollama-embedding.ts - Ollama chat
src/lib/llm.ts - Citation checks
src/lib/citations.ts
Content pipelines
- Wiki pipeline
src/wiki/pipeline.ts - Wiki collection
src/wiki/fetch.ts - OCR pipeline
src/ocr/pipeline.ts - OCR engine
src/ocr/engine.ts
Search and graph
- Graph search
src/graph-db/search.ts - Neo4j client
src/graph-db/client.ts - Neo4j database
- SQLite vector search
src/sqlite/vector-store.ts
Routing and evaluation
- Query router
src/lib/router.ts - Routing demo
src/route-demo.ts - Answer evaluation
src/eval/answer-eval.ts - LLM judge
src/lib/eval/judge.ts
Other components
- API client
Connections 29
- API client → REST server: sends requests
README.md - REST server → Ask endpoint: registers route
src/server/index.ts - Ask endpoint → RAG orchestration: requests answers
src/server/routes/ask.ts - Ask endpoint → SQLite history: persists history
README.md - Ask endpoint → Conversation state: uses conversation
src/server/routes/ask.ts - Ask endpoint → RAG orchestration: checks safeguards
src/server/routes/ask.ts - Chat CLI → RAG orchestration: runs conversational RAG
README.md - RAG orchestration → Document service: searches documents
src/lib/rag.ts - RAG orchestration → Ollama chat: generates answers
src/lib/rag.ts - RAG orchestration → Citation checks: checks citations
src/lib/rag.ts - Document service → Text chunking: chunks text
src/lib/documents.ts - Document service → Vector database: queries and stores
src/lib/documents.ts - Vector database → Ollama embeddings: embeds documents
src/lib/chroma.ts - Ollama chat → API client: calls model service
src/lib/llm.ts - Wiki pipeline → Wiki collection: uses fetched articles
src/wiki/ingest.ts - Wiki pipeline → Vector database: indexes chunks
README.md - Wiki pipeline → Text chunking: chunks sections
src/wiki/pipeline.ts - OCR pipeline → OCR engine: extracts text
src/ocr/pipeline.ts - OCR pipeline → Ollama chat: restores document structure
src/ocr/pipeline.ts - OCR pipeline → Vector database: indexes chunks
README.md - Graph search → Neo4j client: queries graph
src/graph-db/search.ts - Neo4j client → Neo4j database: reads graph data
README.md - Routing demo → Query router: plans route
src/route-demo.ts - Routing demo → RAG orchestration: runs vector RAG
src/route-demo.ts - Query router → Ollama chat: classifies questions
src/lib/router.ts - Answer evaluation → RAG orchestration: evaluates answers
src/eval/answer-eval.ts - Answer evaluation → LLM judge: scores answers
src/eval/answer-eval.ts - LLM judge → Ollama chat: requests judgments
src/lib/eval/judge.ts - SQLite vector search → API client: supports semantic search
README.md