docmind / README.md
mnoorchenar's picture
Sync from GitHub 6e7e4e3: README: reliable Star/Fork buttons
b2893bf
|
Raw History Blame Contribute Delete
11.8 kB
metadata
title: DocMind-Agentic-Research
colorFrom: blue
colorTo: indigo
sdk: docker

🧠 DocMind β€” Agentic Research Platform

Typing SVG

Python LangGraph LangChain Flask Docker Status


Live Demo Source Code


🧠 DocMind β€” A clean, minimal agentic document research platform. Five specialized LangGraph agents plan, retrieve, grade, generate, and critique answers from uploaded PDFs and web pages using hybrid search and Qwen 2.5-7B β€” all running free on HuggingFace Spaces.



Table of Contents


✨ Features

🧠 LangGraph State MachineFive agents wired into a linear StateGraph β€” Planner β†’ Retriever β†’ Grader β†’ Generator β†’ Critic.
πŸ” Hybrid RAG (FAISS + BM25)Semantic vector search combined with BM25 keyword search, fused via Reciprocal Rank Fusion for precision retrieval.
πŸ€– Multi-Agent OrchestrationPlanner, Retriever, Grader, Generator, and Critic agents each with specialized roles β€” only 3 LLM calls per query.
⚑ Score-Based GradingGrader uses hybrid search scores + keyword overlap β€” no LLM call needed, instant and deterministic relevance scoring.
πŸ“„ PDF & URL IngestionUpload PDF files up to 10 MB or paste any public URL β€” both are chunked, embedded, and indexed automatically.
πŸ”’ Secure by DesignStateless REST backend, no user data persisted, HF token kept server-side only.
🐳 Containerized DeploymentDocker-first with Gunicorn, embedding model pre-downloaded at build time for fast cold starts.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   DocMind β€” LangGraph Flow                    β”‚
β”‚                                                              β”‚
β”‚  PDF / URL ──▢ Ingestor ──▢ FAISS+BM25 Hybrid Vector Store  β”‚
β”‚                                    β”‚                         β”‚
β”‚  User Query ──▢ [PLANNER Agent]    β”‚   (Qwen 2.5-7B, 0.3)   β”‚
β”‚                      β”‚             β”‚                         β”‚
β”‚                 [RETRIEVER] β—€β”€β”€β”€β”€β”€β”€β”˜  (FAISS+BM25+RRF)      β”‚
β”‚                      β”‚                                       β”‚
β”‚                 [GRADER]  (score-based, no LLM call)         β”‚
β”‚                      β”‚                                       β”‚
β”‚                 [GENERATOR]         (Qwen 2.5-7B, 0.4)       β”‚
β”‚                      β”‚                                       β”‚
β”‚                  [CRITIC]           (Qwen 2.5-7B, 0.1)       β”‚
β”‚                      β”‚                                       β”‚
β”‚                  [OUTPUT]  Flask API + Single-Page UI         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

  • Python 3.10+ Β· Docker Β· Git Β· Free HuggingFace account

Local Installation

git clone https://github.com/mnoorchenar/docmind.git
cd docmind

python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

pip install -r requirements.txt

cp .env.example .env
# Edit .env β€” set HF_TOKEN to your free HuggingFace Read token

python app.py

Open http://localhost:7860 πŸŽ‰

Getting your free HuggingFace token

  1. Create a free account at huggingface.co
  2. Go to Settings β†’ Access Tokens β†’ New Token β†’ Role: Read
  3. Copy the token and set it as HF_TOKEN in your .env file or Space secrets

🐳 Docker Deployment

docker build -t docmind .
docker run -p 7860:7860 -e HF_TOKEN=hf_your_token_here docmind

πŸ“Š App Modules

Module Description Status
πŸ“€ Upload & Index PDF / URL ingest, chunk, embed (local BAAI model), FAISS+BM25 index βœ… Live
πŸ” Research Query LangGraph 5-agent pipeline with real-time trace log βœ… Live

🧠 ML Models

stack = {
    # ── LLM (LangChain LCEL chains) ──────────────────────────────────────────
    "llm":             "Qwen/Qwen2.5-7B-Instruct",         # via HF Router
    "lcel_chain":      "ChatPromptTemplate | ChatOpenAI | StrOutputParser",
    "retry":           "ChatOpenAI.with_retry(stop_after_attempt=2)",

    # ── RAG (LangChain + custom hybrid) ──────────────────────────────────────
    "splitter":        "RecursiveCharacterTextSplitter (langchain-text-splitters)",
    "documents":       "langchain_core.documents.Document",
    "embeddings":      "HuggingFaceEmbeddings (BAAI/bge-small-en-v1.5, local)",
    "vector_index":    "FAISS IndexFlatIP (cosine)",
    "keyword_index":   "BM25Okapi (rank-bm25)",
    "fusion":          "Reciprocal Rank Fusion (RRF k=60)",
    "grader":          "score-based (hybrid score Γ— 0.7 + keyword overlap Γ— 0.3)",

    # ── Orchestration (LangGraph) ─────────────────────────────────────────────
    "graph":           "LangGraph 0.2 StateGraph β€” 5 nodes, linear pipeline",
}

πŸ“ Project Structure

docmind/
β”‚
β”œβ”€β”€ πŸ“‚ agents/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ critic.py
β”‚   β”œβ”€β”€ generator.py
β”‚   β”œβ”€β”€ grader.py
β”‚   β”œβ”€β”€ llm_factory.py
β”‚   β”œβ”€β”€ planner.py
β”‚   └── … 1 more
β”œβ”€β”€ πŸ“‚ data/
β”‚   β”œβ”€β”€ processed/
β”‚   └── raw/
β”œβ”€β”€ πŸ“‚ docs/
β”‚   └── 013-docmind.html
β”œβ”€β”€ πŸ“‚ graph/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── research_graph.py
β”œβ”€β”€ πŸ“‚ rag/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ embeddings.py
β”‚   β”œβ”€β”€ ingestor.py
β”‚   └── vector_store.py
β”œβ”€β”€ πŸ“‚ templates/                 # HTML templates
β”‚   └── index.html
β”œβ”€β”€ πŸ“‚ tools/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ calculator.py
β”‚   β”œβ”€β”€ code_tool.py
β”‚   └── web_search.py
β”œβ”€β”€ πŸ“‚ tracing/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── tracer.py
β”œβ”€β”€ πŸ“„ .env.example               # Environment variable template
β”œβ”€β”€ πŸ“„ Dockerfile                 # Port 7860, embedding model pre-downloaded
β”œβ”€β”€ πŸ“„ app.py                     # Flask entry point, 5 REST routes
β”œβ”€β”€ πŸ“„ code.txt
β”œβ”€β”€ πŸ“„ requirements.txt           # Python dependencies
└── πŸ“„ write_html.py

πŸ‘¨β€πŸ’» Author

Mohammad Noorchenarboo

Mohammad Noorchenarboo

Data Scientist  |  AI Researcher  |  Biostatistician

πŸ“  Ontario, Canada    πŸ“§  mohammadnoorchenarboo@gmail.com

──────────────────────────────────────

LinkedIn  Personal Site  HuggingFace  Google Scholar  GitHub


🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

⚠️ Disclaimer

This project is developed strictly for educational and research purposes. All LLM outputs are AI-generated and may contain inaccuracies. No real user data is stored. Provided "as is" without warranty of any kind.


πŸ“œ License

Distributed under the MIT License.


Star on GitHub Fork on GitHub

The name "DocMind β€” Agentic Research Platform" is used purely for academic and research purposes. Any similarity to existing product names or trademarks is entirely coincidental. This project has no affiliation with any commercial entity.