Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” DocQuery

Enterprise AI Document Intelligence & Agentic RAG Platform

Chat with any document. Get answers grounded in verified, page-level citations β€” powered by a self-correcting AI agent that runs 100% locally.

Python FastAPI Next.js TypeScript LangGraph ChromaDB Ollama Celery Docker License: MIT


🎯 What is DocQuery?

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.


πŸ’‘ Why it stands out

  • Zero hallucination by design β€” answers are strictly grounded in retrieved context, with explicit has_sufficient_context refusal 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.

✨ Features

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

🧰 Tech Stack

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


πŸ—οΈ Architecture

                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚        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     β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Agentic RAG Loop

  1. Plan β€” an LLM classifies the query β†’ answer_from_docs Β· search_web Β· run_code
  2. Retrieve β€” semantic vector search pulls the most relevant chunks from ChromaDB
  3. Evaluate β€” the agent grades retrieval confidence; if low, it rewrites the query and retries (max 3 loops)
  4. Generate β€” produces a grounded, cited answer with a confidence score β€” and refuses to answer when context is insufficient

πŸš€ Quick Start

Prerequisites

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 model

Setup

git clone <your-repo-url> docquery && cd docquery

python3 -m venv venv
source venv/bin/activate           # Windows: venv\Scripts\activate
pip install -r requirements.txt

Launch (one terminal per service)

ollama 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. Worker
cd frontend && npm install && npm run dev                            # 5. UI β†’ :3000

Use it

  1. Go to http://localhost:3000/documents β†’ drag-drop a PDF β†’ wait for βœ… Ready
  2. 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

πŸ“‘ API Reference

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


πŸ“‚ Project Structure

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

πŸŽ“ Skills & Concepts Demonstrated

  • 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

πŸ—ΊοΈ Roadmap

  • 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

πŸ“„ License

MIT


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. πŸ‘‹

About

Your local document chat with memory.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages