Enterprise Internal Knowledge Base: Production-Ready RAG + MCP

io.github.kimsb2429由 GitHub 账号 kimsb2429 发布v0.1.0更新于 Oct 24, 2026

Production-ready RAG + MCP demo: eval-in-CI merge gate, Langfuse traces, structure-aware chunking.

已验证STDIO仅桌面知识与记忆AI 与机器学习

概览

AI 生成的概览

一个本地 RAG 演示型 MCP 服务器,基于公开的退伍军人事务部教育手册语料回答问题,返回带引用的排序片段。

可以做什么
通过单个 query 工具和按来源 ID 访问的文档资源,在 pgvector 存储的 VA 教育手册语料中检索并返回带引用的排序片段。提供引用提示词,便于把回答建立在检索到的片段上。
适用场景
适合体验或研究带评估、追踪和结构化切分的生产级 RAG 流程,或就内置的 VA 教育手册示例语料提问。
运行要求
以 Python 脚本通过 stdio 在本机运行。需要 Python 及仓库依赖、Docker 运行监听 5433 端口的 Postgres 加 pgvector,并恢复固定数据库转储。生成使用 Claude Sonnet,意味着需要 Anthropic API 密钥;追踪使用 Langfuse Cloud。
安装前请注意
语料是公开示例内容,并非真实内部文档。生成调用 Claude Sonnet 会产生 API 费用,可选的上下文化处理约需 12 美元的 Anthropic 批量调用。追踪记录在 Langfuse 上公开分享。auth_context 参数存在但未使用,租户访问控制尚未实现。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Enterprise Internal Knowledge Base: Production-Ready RAG + MCP,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Enterprise Internal Knowledge Base — Production-Ready RAG + MCP

A public Retrieval-Augmented Generation pipeline exposed as an MCP server. Sample content from Veterans Affairs education manuals.

The repo implements evaluation, observability, and structure-aware ingestion. Cost/latency tuning, tenant-level access control, and other production concerns are discussed in the article linked below.

📖 Full writeup in Towards AI: Enterprise Internal Knowledge Base RAG MCP: POC-to-Production


Why this exists

RAG demos tend to focus on the quality of the retrieval pipeline, without recognizing that production RAG fails on the next ten steps: prompt or model changes that pass code review but tank answer quality, cost and latency drift that cannot be traced to specific queries, cross-tenant leakage that only surfaces in audit. This repo shows what catching them looks like in practice.

The corpus is public (VA Education manuals — 238 documents, 9,000+ chunks) so anyone can clone, run, and adapt the pipeline.


Quickstart

bash
git clone https://github.com/kimsb2429/internal-knowledge-basecd internal-knowledge-base
# 1. Start Postgres + pgvectordocker compose up -d
# 2. Python env + dependenciespython3 -m venv .venv && source .venv/bin/activatepip install -r requirements.txt
# 3. Restore corpus fixture (~2 min — 238 docs + 9k chunks pre-embedded)docker exec -i ikb_pgvector pg_restore -U ikb -d ikb < evals/fixture_v1.dump
# 4. Smoke-test the MCP serverpython scripts/test_mcp_server.py     # 7/7 tests pass
# 5. Start the MCP server (stdio transport)python scripts/mcp_server.py

Consuming from Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

json
{  "mcpServers": {    "ikb": {      "command": "python",      "args": ["/absolute/path/to/internal-knowledge-base/scripts/mcp_server.py"]    }  }}

Then ask Claude things like "What RPO handles GI Bill claims in Texas?" — the MCP server returns ranked chunks with citations.


Architecture

Ingestion (one-time per corpus):

mermaid
graph LR    A[KnowVA crawler<br/>HTML + PDF] --> B[Source-specific<br/>preprocessor]    B --> C[Structure-aware<br/>chunker]    C --> D[mxbai-embed-large<br/>local, 1024-dim]    D --> E[(pgvector)]    F[Anthropic Contextual<br/>Retrieval] -.-> E    E -.-> F    style E fill:#e1f5fe

Query (per MCP tool call):

mermaid
graph LR    A[Claude Desktop<br/>MCP client] --> B[FastMCP server]    B --> C[pgvector top-K]    C --> D[Reranker<br/>mxbai or FlashRank]    D --> E[Claude Sonnet<br/>generation]    E --> A    E --> F[Langfuse trace]    style F fill:#fff9c4

Stack:

  • Vector store: Postgres + pgvector (Docker, port 5433); content_tsv GIN index for hybrid-ready
  • Embeddings: mxbai-embed-large (1024 dims, local via sentence-transformers) — $0 API cost
  • Reranker: mxbai-rerank-base-v2 (full eval) / FlashRank MiniLM (CI fast mode, 22M ONNX, ~2s/query)
  • Generation: Claude Sonnet
  • MCP server: FastMCP 3.2.4 — Tools (query), Resources (document://{source_id}), Prompts (cite_from_chunks)
  • Observability: Langfuse Cloud, per-trace public sharing
  • Eval: DeepEval + 110-query golden set + GitHub Actions merge gate

Eval scores

Full 110-question golden set, contextualized chunks + reranker:

MetricScore
Faithfulness0.95
Answer Relevance0.91
Context Precision0.61
Context Recall0.52
Context Relevance0.56

🔗 Live Langfuse trace (public, no login).

Notable result: Anthropic's Contextual Retrieval pattern produced modest lift on top of reranking (+4.8pp AnsRel, +4.1pp CtxPrec) at this scale — well short of the +35% recall their published numbers suggested. Reported as found; juiced numbers would defeat the point.


Eval-in-CI as a merge gate

Every PR runs the golden set in fast mode (FlashRank reranker, ~3-4 min wall, $0.30 in Sonnet calls) against a fixture DB. PRs that regress more than ±5pp on top1/topk/keyword_recall, or +10pp on idk_rate, are blocked.

Forever-artifact: PR #5 — a deliberate failing-then-passing PR. Red CI catches a 20pp top1 regression; green CI confirms the fix. The Actions tab is the proof.

Workflow: .github/workflows/eval-gate.yml.


What this repo doesn't cover

A few production-shape items are seams, not implementations:

  • Multi-tenant scoping — auth_context parameter present on every MCP tool, typed, currently unused (labels the SSO/ACL seam)
  • Ingestion concurrency — single-threaded chunker + embedder; production would use a modulus-distributed worker pool
  • Hybrid search wiring — content_tsv GIN index is live; BM25 + RRF fusion at query time stays a post-launch addition

The writeup linked above covers these topics.


Repo layout

docs/                    Research, evidence base, deep-divesdata/                    Crawled corpus + golden query setscripts/  crawl_knowva.py            eGain v11 API crawler  enrich_metadata.py         Headings, ACL, authority tier, content_category  knowva_preprocess.py       Source-specific HTML normalization  chunk_documents.py         Structure-aware splitter (preserves table colspan/rowspan)  embed_and_store.py         mxbai-embed-large → pgvector  contextualize_chunks.py    Anthropic Batches API for Contextual Retrieval  rerank.py                  mxbai-rerank + FlashRank  retrieve.py / generate.py  RAG path  mcp_server.py              FastMCP exposure  run_eval.py / score_eval.py / check_regression.py   Eval harness + CI gateevals/                   Fixture DB dump + baseline JSON.github/workflows/       eval-gate.yml — merge-gate workflow

Reproducing from raw corpus (~30 min)

Each script is idempotent and resume-safe.

bash
python scripts/crawl_knowva.py            # Crawl raw HTML (skip if data/knowva_manuals/articles/ exists)python scripts/enrich_metadata.py         # Add headings, ACL, authority tierpython scripts/knowva_preprocess.py       # Normalize HTML quirkspython scripts/chunk_documents.py         # Structure-aware splitpython scripts/embed_and_store.py         # mxbai → pgvectorpython scripts/contextualize_chunks.py    # Anthropic Batches API (~$12, optional but recommended)

Then python scripts/run_eval.py --fast to verify the eval baseline reproduces.


Further reading


License

MIT — see LICENSE.

来源:README.md,提交 e1bd519

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分