How theothernico27/rag-doc-qa works
RAG Document Q&A ingests one text-based PDF at a time, extracts page text, chunks it with page metadata, embeds the chunks locally, and replaces the stored vectors. For questions, the server embeds the query, retrieves the top matching passages, builds a constrained prompt, and asks a local LLM to answer from those passages. The UI presents the answer alongside retrieved excerpts, page numbers, and similarity scores. The route and core library excerpts support the wiring shown; persistence is an in-memory store backed by a JSON file, as documented.
Main entry points: query/route.ts Query route · upload/route.ts Upload route · page.tsx Upload and Q&A · embeddings.ts Embedding client
Components 10
Browser UI
- Upload and Q&A
app/page.tsx
API routes
- Upload route
app/api/upload/route.ts - Query route
app/api/query/route.ts
RAG pipeline
- PDF extraction
app/api/upload/route.ts - Page chunking
src/lib/chunking.ts - Embedding client
src/lib/embeddings.ts - Vector search and store
src/lib/vectorStore.ts - Grounded prompt
src/lib/prompt.ts
Local infrastructure
- Ollama models
Other components
- User
Connections 13
- User → Upload and Q&A: uses
- Upload and Q&A → Upload route: POST upload
- Upload and Q&A → Query route: POST question
- Upload route → PDF extraction: extracts pages
- Upload route → Page chunking: chunks pages
- Upload route → Embedding client: embeds chunks
- Upload route → Vector search and store: replaces vectors
- Query route → Vector search and store: checks and searches
- Query route → Embedding client: embeds question
- Query route → Grounded prompt: assembles context
- Query route → Ollama models: generates answer
- Embedding client → Ollama models: requests embeddings
- Query route → Upload and Q&A: returns answer and sources