DocAgent
Enables document retrieval, OCR, web search, and calculator tools via a RAG pipeline and LangGraph agent, all running locally with Ollama.
README
DocAgent — RAG + Agent System with Document AI
An end-to-end retrieval-augmented generation (RAG) pipeline plus a tool-using LangGraph agent over your own documents. Upload PDFs, scanned images, or text files; DocAgent chunks and embeds them into Qdrant, retrieves and reranks relevant context, and answers with citations — either via a simple grounded QA endpoint, or via an agent that can also call a calculator, search the web, and OCR documents on demand.
Built for ML/GenAI engineer portfolios: RAG, agents, Document AI, local inference, and observability, all running fully offline via Ollama.
Architecture
┌─────────────┐ ┌──────────────┐
PDF/image/text →│ Ingestion │→ chunks→│ Qdrant │
│ (OCR via │ │ (vector DB) │
│ Tesseract) │ └──────┬───────┘
└─────────────┘ │ similarity search
▼
┌───────────────┐
│ Cross-encoder │
│ reranker │
└──────┬────────┘
▼
FastAPI ── /query ─────────► Grounded QA (Ollama, JSON + Pydantic,
citations)
── /agent/chat ────► LangGraph ReAct agent
tools: retrieve_documents, calculator,
web_search (Tavily), ocr_scan
└─ also exposed via MCP (mcp_server.py)
└─ every run logged to runs/*.jsonl
Streamlit UI ── talks to FastAPI, shows answers + citations + tool calls
Tech stack
Python, FastAPI, Pydantic v2, LangChain + LangGraph, Ollama (local LLM +
embeddings), Qdrant (vector DB), a small HF sentence-transformers
cross-encoder for reranking, Tesseract OCR, MCP (Model Context Protocol),
Streamlit, Docker Compose.
Quickstart (Docker Compose — easiest)
cp .env.example .env # edit if you want a different model or a Tavily key
docker compose up -d qdrant ollama backend streamlit
./scripts/pull_ollama_models.sh # pulls the LLM + embedding model into Ollama
Then open:
- Streamlit UI: http://localhost:8501
- API docs: http://localhost:8000/docs
macOS tip: running Ollama natively (
brew install ollama, thenollama serve) is noticeably faster than the containerizedollamaservice since it gets Metal acceleration. If you do that, stop theollamaservice in compose and setOLLAMA_BASE_URL=http://host.docker.internal:11434in.env.
Local dev (no Docker for the backend)
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt
docker compose up -d qdrant ollama # or run both natively
./scripts/pull_ollama_models.sh
uvicorn app.main:app --reload
# in another terminal:
streamlit run streamlit_app/app.py
Requires tesseract and poppler on PATH for OCR (brew install tesseract poppler on macOS).
API
POST /ingest— multipart file upload (pdf,png/jpg/tiff/bmp,txt/md). Scanned PDF pages and images are OCR'd automatically. Returnsdoc_id.POST /query—{"question": "...", "doc_id": "optional"}→ grounded, Pydantic-validated answer with citations (AnswerResponse). No tool use.POST /agent/chat—{"message": "...", "doc_id": "optional"}→ LangGraph agent response, may callretrieve_documents,calculator,web_search,ocr_scanacross multiple steps. Returns citations + a tool-call trace.GET /health— reports whether Qdrant and Ollama are reachable.
MCP server
The same four tools are exposed as an MCP server for external MCP clients (e.g. Claude Desktop):
python -m app.mcp_server
Run tracing
Every /query and /agent/chat call appends a structured JSON record
(retrieved chunks, tool calls, latencies, final answer) to runs/<date>.jsonl
— no external service required. Set LANGCHAIN_API_KEY in .env to
additionally send traces to LangSmith.
Tests
pytest # unit tests always run; live-service API test
# auto-skips unless Qdrant + Ollama are reachable
Notes on deviations from a pure Ollama stack
- Reranking uses a small local HF cross-encoder
(
cross-encoder/ms-marco-MiniLM-L-6-v2) since Ollama has no reranking model type — it's a separate, tiny CPU model, not a generation backend. - Web search (
web_searchtool) uses Tavily and requiresTAVILY_API_KEYin.env; without it the tool reports itself unavailable and the agent falls back to documents/general knowledge.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。