Chat with any document. Get answers grounded in verified, page-level citations β powered by a self-correcting AI agent that runs 100% locally.
DocQuery is a full-stack Generative AI application that turns a pile of documents into an intelligent, queryable knowledge base. Upload PDFs containing text, tables, or scanned images, ask questions in plain English, and get accurate answers with inline citations pointing to the exact source and page. When your documents fall short, an autonomous AI agent decides β on its own β to search the web or run code to find the answer.
The entire system runs locally and free of charge on open-source Large Language Models (LLMs) via Ollama β no API keys, no recurring cloud bills, and complete data privacy. This makes it a realistic reference architecture for privacy-first, on-premise enterprise AI in regulated domains like finance, healthcare, and legal.
In one line: A local, citation-grounded, Retrieval-Augmented Generation (RAG) platform with a self-correcting agentic reasoning loop and a real-time streaming chat UI.
- Zero hallucination by design β answers are strictly grounded in retrieved context, with explicit
has_sufficient_contextrefusal when the documents don't contain the answer. - Self-correcting agent β instead of a single retrieval pass, a LangGraph state machine grades its own results and reformulates the query until confidence is high (up to 3 attempts).
- Truly multimodal β parses plain text, extracts tables to Markdown, and uses a vision-language model to caption charts, diagrams, and scanned images.
- Production patterns, not a toy β async task queues, WebSocket streaming, health checks, typed schemas, and a Gitflow-based delivery process.
| Feature | Tech | |
|---|---|---|
| π | Multimodal document ingestion β text, tables, image captions | PyMuPDF Β· Camelot Β· Vision LLM |
| π§ | Semantic search / RAG over a persistent vector store | ChromaDB Β· nomic-embed-text |
| π€ | Self-correcting agentic RAG loop with query reformulation | LangGraph |
| π§ | LLM task router β docs vs. web search vs. code execution | Ollama Β· LangGraph |
| π§ | Tool-calling via Model Context Protocol (MCP) | MCP Python SDK |
| π | Verified page-level citations with confidence scores | Pydantic |
| β‘ | Async background ingestion + auto-ingest file watcher | Celery Β· Redis Β· Watchdog |
| π | Real-time token streaming chat interface | FastAPI WebSockets Β· Next.js |
| π | 100% local & private β no data leaves your machine | Ollama |
AI / Machine Learning
Large Language Models (LLM) Β· Retrieval-Augmented Generation (RAG) Β· LangGraph Β· Agentic AI Β· Vector Embeddings Β· Semantic Search Β· ChromaDB Β· Ollama Β· llama3.2-vision Β· nomic-embed-text Β· Multimodal AI Β· Computer Vision Β· Model Context Protocol (MCP) Β· Prompt Engineering Β· NLP
Backend
Python Β· FastAPI Β· WebSockets Β· Celery Β· Redis Β· Pydantic Β· PyMuPDF Β· Camelot Β· Watchdog Β· DuckDuckGo Search
Frontend
Next.js (App Router) Β· React Β· TypeScript Β· Tailwind CSS
Infrastructure / DevOps
Docker Β· Docker Compose Β· Git / Gitflow Β· Microservices Β· Async Task Queues
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Next.js + TypeScript + Tailwind β
β Streaming Chat Β· Drag-Drop Upload Β· Cites β
ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββββ
REST / WebSocket β multipart upload
βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β /chat /chat/stream /documents /health β
βββββββββ¬βββββββββββββββββββββββββ¬ββββββββββββββ
β β enqueue job
query (RAG) βΌ βΌ
ββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β LangGraph Agentic Core β β Celery + Redis Workers β
β β β (async ingestion) β
β planner_node (router) β βββββββββββββββ¬ββββββββββββββ
β ββββββββ¬ββββββββ¬βββββββ β βΌ
β docs web code β ββββββββββββββββββββββββββββ
β retrieve search exec β β Ingestion Pipeline β
β evaluate β β β β Load β Extract (text + β
β requery ββββ βββ β β tables) β Vision Caption β
β ββββββΊ generate ββββββββ β β Chunk β Embed β Store β
β (cited answer) β βββββββββββββββ¬ββββββββββββββ
ββββββββββββββ¬ββββββββββββββ β upsert
β embed + search βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β ChromaDB Vector Store (local) β
β vectors + metadata + page-level citations β
ββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
β² inference
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Ollama β llama3.2-vision Β· nomic-embed β
ββββββββββββββββββββββββββββββββββββββββββββββββ
- Plan β an LLM classifies the query β
answer_from_docsΒ·search_webΒ·run_code - Retrieve β semantic vector search pulls the most relevant chunks from ChromaDB
- Evaluate β the agent grades retrieval confidence; if low, it rewrites the query and retries (max 3 loops)
- Generate β produces a grounded, cited answer with a confidence score β and refuses to answer when context is insufficient
| Tool | Version |
|---|---|
| Ollama | latest |
| Python | 3.11+ |
| Node.js | 18+ |
| Docker + Compose | latest |
Pull the models (one-time):
ollama pull llama3.2-vision:11b # multimodal LLM (text + vision)
ollama pull nomic-embed-text # embedding modelgit clone <your-repo-url> docquery && cd docquery
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtollama serve # 1. LLM server
docker compose up -d # 2. Redis broker
uvicorn api.main:app --reload # 3. API β :8000/docs
celery -A tasks.ingest_task worker --loglevel=info --concurrency=1 # 4. Workercd frontend && npm install && npm run dev # 5. UI β :3000- Go to http://localhost:3000/documents β drag-drop a PDF β wait for β Ready
- Open the chat page β ask a question β watch the answer stream live with citations
Prefer the CLI?
python3 scripts/ingest.py --file uploads/your.pdf
python3 scripts/ask.py "What does the document say about revenue?" --verbose| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health of Ollama, ChromaDB, Redis |
POST |
/documents/upload |
Upload a file β async ingestion |
GET |
/documents |
List ingested documents + stats |
DELETE |
/documents/{filename} |
Delete a document and its vectors |
POST |
/chat |
Ask a question β cited answer (agent) |
WS |
/chat/stream |
Stream answer tokens + final citations |
Interactive Swagger docs: http://localhost:8000/docs
docquery/
βββ ingestion/ # loader Β· extractor (PyMuPDF/Camelot) Β· vision captioner Β· chunker
βββ embeddings/ # Ollama embedding client (batched, 768-dim)
βββ vectordb/ # ChromaDB store + semantic search
βββ rag/ # citation schema Β· retriever Β· cited-answer generator
βββ agent/ # LangGraph nodes Β· state machine Β· planner Β· file watcher
βββ mcp_tools/ # MCP server: web_search Β· run_python Β· read_file
βββ tasks/ # Celery async ingestion (+ LLM summarization)
βββ api/ # FastAPI app Β· routes Β· Pydantic schemas
βββ scripts/ # CLI: ingest.py Β· search.py Β· ask.py
βββ frontend/ # Next.js + TypeScript + Tailwind UI
βββ docker-compose.yml
- Retrieval-Augmented Generation (RAG): chunking with overlap, dense embeddings, vector indexing, similarity thresholding, context injection
- Agentic AI: LangGraph stateful graphs, cyclic self-correction, conditional routing, multi-step tool-using agents
- Tool-Augmented LLMs: Model Context Protocol (MCP), web search, sandboxed Python execution, safe file access
- Multimodal AI / Computer Vision: vision-language captioning of charts, diagrams, and scanned pages
- Prompt Engineering: structured JSON outputs, anti-hallucination grounding, query reformulation
- AI Infrastructure / MLOps: local model serving (Ollama), async queues (Celery/Redis), Docker, health checks
- Full-Stack Engineering: typed REST + WebSocket APIs, real-time React streaming UI, drag-and-drop UX
- Evaluation harness β RAGAS metrics (faithfulness, answer relevance, context precision) in CI
- Auth & multi-tenancy β JWT + per-user isolated vector collections
- Cloud deployment β containerized stack on GPU instances
- Cross-encoder re-ranking for higher retrieval precision
- Multi-turn conversation memory
Built to demonstrate end-to-end AI Engineering β document ingestion β agentic reasoning β streaming production UI.
Recruiters & engineers: thanks for visiting! Feel free to open an issue or reach out. π