使用说明
RAG驱动的MCP服务器,用于文档问答
生产准备就绪 检索增强生成(RAG) 管道暴露在外 模型上下文协议(MCP) 服务器——使Claude Desktop能够直接从您的私人文档集合中回答问题。
使用FAISS矢量搜索、句子转换器和Groq LLM构建。
特性
- 检索增强生成(RAG)管道
- FAISS向量相似性搜索
- 句子转换器嵌入
- Groq LLaMA快速响应推理
- Streamlit聊天界面
- 克劳德桌面MCP集成
- 基于来源的答案(无幻觉)
- 可调节的检索深度
这有什么作用
您为其提供PDF文件→ 它对它们进行语义索引→ Claude Desktop可以通过MCP工具调用实时查询它们。
问克劳德 “Transformer论文对多头注意力有什么看法?” 它从你的文档中检索出确切的相关段落,并生成一个有根据的答案——没有幻觉,没有猜测。
建筑
PDFs
↓ PyMuPDF extracts text
Text Chunks (500 words each)
↓ Sentence Transformers embeds
FAISS Index (local vector store)
--- At query time ---
User Question → Claude Desktop
↓ MCP tool call
server.py receives question
↓ embeds question
FAISS finds Top 5 similar chunks
↓ chunks stuffed into prompt
Groq LLaMA generates grounded answer
↓
Answer returned to Claude Desktop
技术栈
| 组件 | 技术 | 目的 |
|---|---|---|
| PDF解析 | PyMuPDF | 从PDF中提取原始文本 |
| 嵌入 | 句子转换器(全MiniLM-L6-v2) | 将文本转换为语义向量 |
| 矢量存储 | 失败(元) | 快速相似性搜索 |
| LLM | Groq(LLaMA 3.3 70B) | 从检索到的块中生成答案 |
| MCP服务器 | FastMCP(Python SDK) | 将RAG作为Claude桌面工具公开 |
流线型Web界面
该项目还包括一个互动 Streamlit聊天界面 这允许用户直接从浏览器查询他们的文档。
特征:
•聊天风格界面
•基于来源的答案
•可调节的检索深度
•检索文件块检查
截图
项目结构
rag-mcp-server/
│
├── documents/ ← Put your PDFs here
│ ├── 1706.03762v7.pdf (Attention Is All You Need)
│ ├── 1810.04805v2.pdf (BERT)
│ └── 2005.11401v4.pdf (RAG paper by Meta)
│
├── assets/
│ ├── demo.png (Claude Desktop answering from papers)
│ ├── mcp_running.png (MCP server running in Claude settings)
│ └── architecture.png
│
├── ingest.pynb ← Run once: chunks + embeds PDFs → FAISS index
├── rag.py ← Core RAG logic: retrieve + generate
├── server.py ← MCP server: exposes RAG as Claude tool
│
├── chunks.json ← Auto-generated by ingest.py
├── faiss_index.bin ← Auto-generated by ingest.py
│
├── requirements.txt
└── README.md
├── streamlit_app.py ← Streamlit web interface
设置
1.克隆仓库
git clone https://github.com/TanmayRawal/rag-mcp-server.git
cd rag-mcp-server
2.创建Python 3.11环境
conda create -n ragmcp python=3.11
conda activate ragmcp
3.安装依赖项
pip install -r requirements.txt
4.获得免费Groq API密钥
- 首选 console.groq.com
- 注册并创建API密钥
- 将其添加到两者中
rag.py和server.py:
os.environ["GROQ_API_KEY"] = "your_key_here"
5.将PDF添加到 documents/
将任何PDF放入 documents/ 文件夹。推荐论文:
6.运行摄入
python ingest.py
读取所有PDF,拆分为500个单词块,嵌入句子转换器,保存FAISS索引。运行一次(或添加新文档时)。
7.直接测试RAG
python rag.py
连接到克劳德桌面
1.编辑MCP配置
- 窗户:
C:\Users\<you>\AppData\Roaming\Claude\claude_desktop_config.json - 雨衣:
~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"rag-knowledge-base": {
"command": "/path/to/conda/envs/ragmcp/python",
"args": ["/path/to/rag-mcp-server/server.py"]
}
}
}
### 2. Restart Claude Desktop
Fully quit and reopen. Go to **Settings → Developer** — you should see `rag-knowledge-base` with status **running**.
### 3. Ask Claude anything about your documents
Transformer论文对多头注意力有什么看法? 哪些数据集用于评估RAG? 解释BERT预培训目标。
Claude automatically calls your `query_knowledge_base` tool and answers from your actual documents.
---
## How RAG Works
1. **Retrieve** — embed the question, search FAISS for top 5 semantically similar chunks
2. **Augment** — inject those chunks into the LLM prompt as context
3. **Generate** — LLM reads chunks and generates a grounded answer
No fine-tuning. No training. Just smart search + generation.
---
## Example Questions
Try asking questions like:
- What does the Transformer paper say about multi-head attention?
- What are the pre-training objectives used in BERT?
- How does Retrieval Augmented Generation work?
- What datasets were used to evaluate the RAG model?
---
## Requirements
pymupdf 句子变换器 faiss cpu 格罗克 主控程序
Python 3.11+ required.
---
## Future Improvements
- Support more formats (`.txt`, `.docx`, `.md`)
- Hybrid search (BM25 + semantic)
- Conversation memory across queries
- Streamlit web UI
- Multiple independent knowledge bases
---
## License
MIT