MCPcopy Create free account
hub / github.com/aieng-abdullah/production-rag-assistant

github.com/aieng-abdullah/production-rag-assistant @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
290 symbols 948 edges 45 files ⚖ MIT 67 documented · 23% ● updated 36d ago★ 5516 open issues

Browse by type

⨍ Functions 205◇ Types & classes 20↳ Endpoints 65
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

artificial-intelligence

GroundedAI

Citation-enforced RAG research assistant for legal & academic

GroundedAI (repo: production-rag-assistant)

RAG Workspaces CI Python LangChain React FastAPI Groq Langfuse Ragas

Your RAG research assistant where citations are enforced by code, not requested by prompts.

Ask your statutes, contracts, and papers questions. Grounded answers scoped to the legal or academic workspace — every claim carries a verbatim quote, checked against the source it cites.

Try the live →

liveground


The problem

AI assistants answer questions about your documents — and then guess.

  • LLMs fabricate. Ask about a paper, statute, or contract and you get a confident answer that isn't in the source. You find out too late.
  • "Cite sources" prompts don't work. Models sprinkle citations on some sentences and skip others. Partial hallucination looks verified.
  • Manual reading doesn't scale. Researchers skim dozens of PDFs. Lawyers grep through acts and case law. Students re-read the same chapter hoping to find the one passage that matters.
  • Wrong citations carry real risk. Academic integrity violations. Misquoted statutes. Bad advice built on a paragraph that never said that.

ChatGPT guesses. GroundedAI verifies — every claim, against the source, before you see it.


How it works

Retrieval-Augmented Generation (RAG) with a citation validation gate on top: retrieve only your document's passages, ground the answer on them, then reject any sentence that isn't cited.

Upload a PDF → ask a question → get an answer where every factual sentence carries a page-level [SOURCE N] citation, validated by schema before the answer reaches you.

Step What happens Why it matters
1. Ingest PyMuPDF parses pages, text split into tight 256-char chunks, embedded, stored with tenant isolation Page numbers survive to citation time
2. Retrieve BM25 (exact keywords) ∥ vector (semantic) → Reciprocal Rank Fusion → cross-encoder rerank Right passage found even when wording differs
3. Answer LLM grounded on retrieved chunks only; identifies sources first, then answers Model reasons over evidence, not memory
4. Validate Pydantic requires every claim to carry a citation, and checks each quote appears verbatim in the chunk it cites Uncited or misquoted claims are rejected before you see them
5. Abstain Sources insufficient → "I don't have enough information" Honesty over completeness

Validation is a code-level gate, not a prompt instruction. The model cannot skip it.


Why people use GroundedAI

You need GroundedAI
Answers in your domain Two workspaces on one engine: legal reports what statutes say (no legal advice, strict abstain); academic answers from your papers with provenance
Trustworthy answers Faithfulness 1.00 (n=5) on golden set — every claim grounded in your corpus, or the system says so
Verifiable citations Per-sentence [SOURCE N] + page numbers — click through to the source text
Honesty by default Abstains instead of fabricating when your corpus lacks the answer
Choice of models Groq (free) → Anthropic → OpenAI failover; add your own key in the sidebar
Privacy Multi-tenant isolation (your docs invisible to others) or self-host entirely
Free to start Live demo free; no card required
Yours to run Open source core — FastAPI + React + Qdrant Cloud in one deploy

What makes this different from another RAG demo

Differentiator What most demos do What this does
Citation enforcement Prompt says "cite sources" Pydantic requires a citation on every claim; quote containment checked against the cited chunk
Retrieval Vector-only BM25 ∥ vector → RRF → cross-encoder rerank
Latency forensics Guess at slowness Langfuse traces (n=141, local cross-encoder, 2026-06): reranker is the bottleneck — measured, not guessed
Provider resilience Single LLM, dies on rate limit Groq → Anthropic → OpenAI failover with retry + exponential backoff

Who it's for

If you are... This solves...
A researcher Cross-paper synthesis without manual skimming; every claim traceable to a page
A grad student Citeable answers you can actually reference in writing
An engineer Extracting implementation details from technical papers
A lawyer / legal team Statute and contract Q&A with report-not-advice discipline and strict abstain
An academic Literature review support that won't invent citations

Workspaces

One engine, domain-specific profiles — prompt behavior, citation format, and retrieval tuned per workspace.

Workspace Status What it does
Academic 🟢 Live Paper citation, cross-paper synthesis, provenance on every claim
Legal 🟢 Live Statute-focused reporting, no legal advice, strict abstain when sources don't support an answer
Medical 📋 Phase 2 Clinical guidelines, PubMed corpus, ICD-10 coding assistance — citation-verified medical Q&A
Bangla 📋 Phase 2 Multilingual embeddings (multilingual-e5) + Bangla OCR for scanned legal docs

The core engine (hybrid retrieval + citation verification + workspace profiles) is domain-agnostic. Future domains change prompt profiles and chunk metadata — not the pipeline.


Star History

Star History Chart


Features

  • Citation-verified answers — every claim carries a verbatim quote, checked against the chunk it cites, page-level provenance
  • Hybrid retrieval — BM25 + vector, fused with RRF, reranked by cross-encoder
  • Graceful abstention — "not enough information" instead of confident guessing
  • Google login — OAuth; guest mode without an account
  • Free-tier quotas — daily query, document, and storage limits with upgrade path
  • Provider failover — Groq → Anthropic → OpenAI with exponential backoff
  • Provenance traces — queries, chunks, and verification stored with each answer
  • Observability — Langfuse traces on retrieval, prompt build, LLM call, validation
  • Multi-tenant isolation — Qdrant payload tenant_id filter on every read path
  • Self-host ready — local mode or Docker Compose; your data stays yours

Technology — the RAG pipeline

Hybrid Retrieval-Augmented Generation stack. How each piece solves part of the problem:

Layer Technology Problem it solves
PDF parsing PyMuPDF Page-aware extraction → real page numbers in citations
Chunking LangChain RecursiveCharacterTextSplitter 256-char chunks, 100 overlap → tight context, less noise to fabricate from
Embeddings Voyage AI voyage-4-lite API-only semantic search; Render-safe
Vector store Qdrant Cloud Managed similarity search + payload filters for tenant/workspace isolation
Sparse retrieval BM25 Exact keyword match for terms like "scaled dot-product attention"
Fusion Reciprocal Rank Fusion Combines keyword + semantic rankings without score normalization
Reranker Voyage AI voyage-rerank-3-lite API-only cross-encoder reranking
LLM Groq / Anthropic / OpenAI Fast default (free Groq), user choice, failover on rate limits
Orchestration LangChain Provider-agnostic chains, retries, structured output
Validation Pydantic Hard gate: uncited sentence → rejected response
UI React SPA + FastAPI Modern frontend, scoped API, Render Docker + static deploy
Observability Langfuse (opt-in/sampled) Production-safe tracing; off by default, sampled when enabled
Evaluation Citation gates + Ragas Quote-containment, recall and abstention gates on an 8-item adversarial set; Ragas metrics over the 29-item corpus when keys are funded
CI GitHub Actions ruff + fast tests on every PR and push to main (slow embedder tests skipped)

Pipeline

PDF Upload
    ↓
PyMuPDF Parser — page-aware extraction
    ↓
RecursiveCharacterTextSplitter — 256 character chunks, 100 overlap
    ↓
Voyage AI `voyage-4-lite` embeddings
    ↓
Qdrant Cloud — managed vector store (tenant-isolated via payload filters)
    ↓
User Query
     ├── BM25 Search (Top 20)
     ├── Vector Search (Top 20)
     ↓
Reciprocal Rank Fusion (score = 1 / (k + rank), k=60)
     ↓
Voyage AI `voyage-rerank-3-lite` reranker
     ↓
Top 5 Chunks → Citation Prompt Builder (workspace profile)
     ↓
LLM Provider Chain (retry + exponential backoff + failover)
     ├── Groq (default llama-3.1-8b-instant) — free
     ├── Anthropic (Claude) — optional, user-provided key
     └── OpenAI (GPT-4o) — optional, user-provided key
     ↓
Pydantic Citation Validator — every claim must cite; quotes checked against the chunk
     ↓
Final Response with page-level citations

Plans

Matches the in-app pricing modal:

Free (live) Pro (coming soon)
Price $0 $9 / mo
Verified answers/day 10 100
Documents 5 50
Storage 100 MB 1 GB
Support Community Priority

Teams ($29/mo, admin + SSO) planned with billing activation (Stripe; Bangladesh-local rails alongside).


Roadmap

Domain / capability Status Notes
Medical domain Planned Clinical guidelines, PubMed corpus, ICD-10 coding assistance; citation-verified medical Q&A
Bangla support Planned Multilingual embeddings (multilingual-e5) + Bangla OCR for scanned legal docs
Legal domain expansion Planned Contract Act 1872, Companies Act 1994, case law corpus; section-aware retrieval
Reflective retrieval (T2) Designed LangGraph orchestrator: query → retrieve → reflect → re-retrieve → answer
Workflow agents (T3) Designed Domain agents: contract review, literature review, compliance check
bKash payments Planned Bangladesh-local payment rail alongside Stripe
Teams / orgs Planned Shared workspaces, admin controls, SSO
SSE streaming Planned Token-by-token answer streaming with citation markers
SPA frontend Done React/Vite SPA replaces Streamlit for production UX

The engine stays shared; only prompt profiles, chunk metadata schemas, and citation formats change per domain (Legal / Academic / Medical / Bangla).

---

For engineers

Results (citation gates — enforced, runs today)

python3 eval/verify_eval.py, 8 adversarial cases over data/verify_eval.json:

Gate Score Threshold Status
Citation precision 1.00 1.00 PASS
Citation recall 1.00 0.75 PASS
Abstention accuracy 1.00 1.00 PASS

Citation precision 1.00 — every quoted phrase appears verbatim in the chunk it cites.

Citation recall 1.00 — every expected citation is present (was 0.83 before deterministic verification landed).

Abstention accuracy 1.00 — out-of-corpus questions abstain instead of guessing.

Cases: 2 out-of-corpus, 2 conflicting-sources, 2 proviso, 1 missing-cross-reference, 1 grounded-cite. Deliberately adversarial rather than a broad sample — n=8 is small, and these target the failure modes that matter for legal text.

Per-case outcome: 6 verified, 1 partial (legal-conflicting-101), 2 abstained (both out-of-corpus, correctly). The partial is a real gap, not noise — see Known limitations.

Ragas metrics (last run: n=5, stale)

Metric Score Threshold Status
Faithfulness 1.00 0.75 PASS
Answer relevancy 0.88 0.75 PASS
Context recall 1.00 0.70 PASS
Context precision 0.375 0.70 FAIL

**Fai

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 131
Method 74
Route 65
Class 20

Languages

Python100%

Modules by API surface

tests/test_generate.py36 symbols
tests/test_pipeline_ingest.py26 symbols
tests/test_config.py24 symbols
tests/test_providers.py21 symbols
tests/test_retrieval_pipeline.py20 symbols
tests/test_chroma_client.py20 symbols
tests/test_langfuse_tracer.py13 symbols
tests/test_cross_encoder.py12 symbols
tests/test_bm25.py12 symbols
tests/test_chain_utils.py9 symbols
app.py9 symbols
src/db/chroma_client.py8 symbols

For agents

$ claude mcp add production-rag-assistant \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page