faq-rag
Enables answering natural-language questions from FAQ documents using vector search and LLM generation via an MCP tool.
README
FAQ RAG + MCP Tool
A RAG prototype that answers natural-language questions from FAQ documents using vector search and LLM generation, exposed as an MCP tool.
What We Built
A three-stage RAG pipeline:
- Ingest — FAQ markdown files are chunked (~200 chars), embedded with VoyageAI, and stored in MongoDB
- Retrieve — User questions are embedded and matched against stored chunks using MongoDB
$vectorSearch(cosine similarity) - Generate — Top matching chunks are passed as context to an LLM, which generates a cited answer
The whole thing is wrapped as an MCP tool (ask_faq) so any MCP-compatible client can call it directly.
Architecture
| Component | Choice | Why |
|---|---|---|
| Embeddings | VoyageAI voyage-3-lite (512d) |
Purpose-built for retrieval; outperforms OpenAI ada-002 on search benchmarks |
| Vector Store | MongoDB $vectorSearch |
Persistent, scalable, production-realistic — vs in-memory numpy which loses data on restart |
| LLM | OpenAI gpt-4o-mini |
Cost-efficient, fast, plenty capable for FAQ Q&A |
| MCP | stdio transport | Standard for local MCP tools |
How It Works
Question → VoyageAI embed → MongoDB $vectorSearch → Top-K chunks → OpenAI generate → Cited answer
- Chunking: Fixed ~200 character splits. Simple and predictable for a small corpus.
- Retrieval: Cosine similarity via MongoDB vector search index (HNSW). Returns top 4 chunks by default.
- Generation: System prompt enforces grounded answers — no hallucination, must cite source filenames, infers intent (e.g. "locked out" → password reset).
- Lazy client init: API clients connect on first query, not at server startup — so the MCP server registers tools cleanly before any API calls.
How to Run
1. Configure environment
cp .env.example .env
Set VOYAGE_API_KEY, OPENAI_API_KEY, and MONGODB_URI. That’s all that’s required.
2. Ingest the FAQ corpus
uv run ingest.py
3. Test via CLI
uv run rag_core.py
4. Run as MCP tool in Cursor
Add to .cursor/mcp.json:
{
"mcpServers": {
"faq-rag": {
"type": "stdio",
"command": "uv",
"args": ["run", "python", "${workspaceFolder}/mcp_server.py"],
"envFile": "${workspaceFolder}/.env"
}
}
}
Example Questions
These show the system understands intent, not just keywords:
| Question | What it tests |
|---|---|
| "How do I reset my password?" | Direct keyword match (faq_auth.md) |
| "I'm locked out of my account" | Semantic inference — no "password" or "reset" in query |
| "Can I take 3 weeks off in a row?" | Retrieves the 2-week approval rule from PTO policy |
| "When do my shares kick in?" | Maps "shares" → equity vesting schedule |
| "I want to use one login for everything" | Maps to SSO without mentioning it |
| "What do new employees need to know?" | Cross-document retrieval from multiple FAQ files |
Deviations from Starter Skeleton
The starter used OpenAI embeddings + in-memory numpy for cosine similarity. We replaced both:
- VoyageAI instead of OpenAI embeddings — Voyage models are purpose-built for retrieval and rank higher on search benchmarks (MTEB). Using a separate embedding provider also decouples retrieval quality from the LLM choice.
- MongoDB instead of numpy — A real vector database with persistence, indexing (HNSW), and
$vectorSearchaggregation. Data survives restarts, and the same approach scales to millions of documents without code changes. - Lazy client initialization — API clients connect on first tool call, not at import. This lets the MCP server start and register tools cleanly.
- Kept everything else simple — no LangChain, no caching layers, no retry logic. Clean Python with direct API calls.
Files
ingest.py # Build the index: read faqs/ → chunk → embed → store in MongoDB → ensure vector index
rag_core.py # Query path only: embed question → vector search → generate answer (no ingestion)
mcp_server.py # MCP server (exposes ask_faq, calls rag_core)
faqs/ # FAQ markdown corpus
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。