不和谐公会RAG系统
一个用于Discord消息的检索增强生成系统,允许您通过MCP(模型上下文协议)直接在Claude Desktop中用自然语言查询您的Discord公会历史。
特性
- 导出现有的Discord消息 来自指定频道
- 实时消息收集 通过Discord机器人
- 基于矢量的搜索 使用句子嵌入(ChromaDB)
- Claude桌面集成 -直接MCP服务器连接,实现无缝查询
- 丰富的CLI界面 具有过滤选项
- 无需复制粘贴 -Claude Desktop直接查询您的Discord数据库
快速开始
1.部署和测试
git clone https://github.com/keithah/discord-guild-rag.git
cd discord-guild-rag
./deploy.sh # Sets up environment and creates config template
./test.sh # Runs comprehensive system tests2.配置Discord
编辑 config/.env 使用您的Discord凭据:
DISCORD_BOT_TOKEN=your_bot_token
DISCORD_GUILD_ID=your_server_id
ALLOWED_CHANNELS=channel1,channel2,channel3看 Discord Bot设置 以下为详细说明。
Discord Bot设置
- 首选 Discord开发者门户
- 创建新应用
- 转到“Bot”部分并创建一个Bot
- 复制机器人令牌
- 在特权网关意图下启用“消息内容意图”
- 以“读取消息历史记录”权限邀请机器人到您的服务器
3.配置环境
编辑 config/.env 使用您的Discord凭据:
DISCORD_BOT_TOKEN=your_actual_bot_token_here
DISCORD_GUILD_ID=your_server_id_here
ALLOWED_CHANNELS=channel_id_1,channel_id_2,channel_id_3要获取ID:在Discord中启用开发人员模式→ 右击→ 复制ID
部署选项
- 快速测试:使用
./deploy.sh和./test.sh用于本地测试 - 码头工人:使用
docker-compose up -d用于集装箱化部署 - 生产:参见 部署.md 有关详细的部署指南
用法
初始设置-导出现有邮件
# Export all messages (first time setup)
python -m src.main export
# Export with limit for testing
python -m src.main export --limit 1000开始实时收集
# Start the Discord bot to collect new messages
python -m src.main bot搜索您的邮件
# Basic search
python -m src.main search "What did we decide about the server migration?"
# Filtered searches
python -m src.main search "project updates" --channel "dev-team" --author "john"
# Export formatted context for Claude
python -m src.main search "bug reports" --export
# Show context in terminal and export to file
python -m src.main search "team meeting notes" --show-context --export检查系统状态
python -m src.main statusClaude桌面集成
该系统提供了一个直接与Claude Desktop集成的MCP服务器,无需复制粘贴!
Claude桌面的快速设置
- 设置系统:按照上述安装步骤进行操作
- 配置Claude桌面:将MCP服务器添加到您的Claude Desktop配置中
- 开始查询:让Claude Desktop直接搜索您的Discord消息
有关详细的Claude Desktop设置说明,请参阅 CLAUDE_DESKTOP_SETUP.md
Claude桌面使用示例
配置后,您可以直接询问Claude Desktop:
- *“在我的Discord消息中搜索API性能讨论”*
- *“在#后端通道中查找有关部署问题的最新对话”*
- *“对数据库迁移提出的主要担忧是什么?”*
Claude Desktop将使用MCP服务器搜索您的Discord数据库并提供上下文响应。
CLI命令
| 命令 | 描述 |
|---|---|
export [--limit N] | 导出现有的Discord消息 |
bot | 开始实时消息收集 |
search QUERY [options] | 使用自然语言搜索邮件 |
mcp | 启动Claude Desktop的MCP服务器 |
status | 显示数据库统计信息 |
搜索选项
| 选项 | 描述 |
|---|---|
--channel, -c | 按频道名称筛选 |
--author, -a | 按作者姓名筛选 |
--results, -r | 结果数(默认值:10) |
--export, -e | 将Claude格式的上下文导出到文件 |
--show-context | 在终端中显示格式化的上下文 |
项目结构
discord-guild-rag/
├── src/
│ ├── database.py # ChromaDB operations
│ ├── rag_processor.py # Embeddings and search
│ ├── discord_exporter.py # Export existing messages
│ ├── discord_bot.py # Real-time collection
│ ├── query_interface.py # Search interface
│ └── main.py # CLI commands
├── data/
│ ├── exports/ # Raw Discord exports & Claude contexts
│ └── embeddings/ # ChromaDB storage
├── config/
│ ├── .env # Environment variables
│ └── config.yaml # Configuration settings
└── requirements.txt用例
调试过去的问题
python -m src.main search "database connection errors" --channel "backend" --export
# Copy to Claude: "What caused these database errors and how were they fixed?"团队决策评审
python -m src.main search "migration timeline" --author "tech-lead" --export
# Copy to Claude: "Summarize the migration timeline decisions and concerns raised"项目状态检查
python -m src.main search "feature release" --results 20 --export
# Copy to Claude: "What's the current status of our feature releases?"故障排除
常见问题
- Bot权限:确保机器人具有“读取消息历史记录”权限
- 频道ID:在Discord中使用开发人员模式复制频道ID
- 费率限制:Discord有速率限制-机器人会自动处理
- 内存使用:对于大型服务器,考虑批量处理
性能提示
- 从有限的导出开始测试系统
- 使用频道过滤来关注相关对话
- 监控数据库大小和嵌入存储
益处
- ✅ 直接克劳德桌面集成 -无需通过MCP进行复制粘贴
- ✅ 智能搜索 -RAG会自动查找最相关的消息
- ✅ 完整上下文 -Claude可以直接访问您的Discord历史记录
- ✅ 增量更新 -新消息会自动处理
- ✅ 隐私 -所有内容都在您的机器上本地运行
- ✅ 实时 -在Claude Desktop中自然提问
配置
嵌入模型
系统使用 all-MiniLM-L6-v2 默认情况下。您可以在中更改此设置 config/config.yaml:
rag:
embedding_model: "all-MiniLM-L6-v2" # or "all-mpnet-base-v2" for better quality数据库设置
database:
chroma_path: "./data/embeddings"
collection_name: "discord_messages"高级用法
自定义导出位置
# The system automatically creates timestamped export files
# Files are saved to: data/exports/claude_context_[query]_[timestamp].md按日期筛选
目前已实现以供将来使用,可以扩展到按日期范围过滤。
多个服务器
要处理多个Discord服务器,请创建单独的配置文件并运行多个实例。
