本地RAG堆栈

一个本地RAG(检索增强生成)堆栈,通过模型上下文协议(MCP)将Qdrant向量搜索和Ollama LLM工具直接暴露给VS Code中的GitHub Copilot Chat。

  • by Polskipepek
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Polskipepek/qdrant-mcp

使用说明

qdrant mcp

本地RAG(检索增强生成)堆栈,将Qdrant矢量搜索和Ollama LLM工具直接暴露给 GitHub Copilot 聊天助手 通过VS Code 模型上下文协议(MCP).

所有存储库共享 一个Qdrant系列 (codebase 默认情况下)。每个区块携带 repo, source, language,以及 branch 有效载荷字段。每个搜索和回答工具都可以限定在一个仓库中,也可以一次跨所有仓库运行。


建筑

VS Code Copilot Chat
        │  MCP (stdio)
        ▼
   MCP Server (Node.js / TypeScript)
    ├── embed(text)  ──►  Ollama :11434  (nomic-embed-text)
    ├── generate()   ──►  Ollama :11434  (llama3.2)
    └── qdrant.*     ──►  Qdrant :6333
                               │
                    shared collection 'codebase'
                    payload fields: repo, source, language, branch
                    payload indexes: repo ✓  source ✓  language ✓

Auto-ingest paths:
  git post-commit hook  ──►  scripts/ingest.ts  (per changed file)
  scripts/watcher.ts   ──►  chokidar multi-dir watcher (on save)

用户故事和接受标准

US-1--当地基础设施运行可靠

作为一个 开发商, 我想要 Qdrant和Ollama自动启动Docker Compose, 以便 我不必手动管理它们。

  • [x] docker compose up -d 开始 qdrant (v1.17.0)以及 ollama 容器
  • [x] Qdrant可达 http://localhost:6333
  • [x] Ollama可达 http://localhost:11434
  • [x] 数据在容器重启过程中持续存在
  • [x] 除非明确停止,否则两个容器都会重新启动
  • [x] 通过NVIDIA容器工具包实现RTX卡的GPU直通

US-2--VS代码副本可以管理Qdrant

  • [x] qdrant_health 返回版本和状态
  • [x] ollama_health 返回Ollama状态
  • [x] qdrant_list_collections 列出收藏
  • [x] qdrant_create_collection / qdrant_delete_collection 管理收藏
  • [x] 所有工具在失败时返回结构化错误

US-3——具有每个仓库过滤的共享集合

作为一个 开发人员在多个repos上工作, 我想要 所有存储库共享一个Qdrant集合,但能够将搜索范围限定到单个存储库, 以便 我有一个数据库需要维护,但需要时可以集中回答。

  • [x] 单一收藏(codebase)存储所有存储库中的块
  • [x] 每个区块都有 repo, source, language, branch 有效载荷字段
  • [x] 有效载荷指数 repo, source, language 用于快速过滤搜索
  • [x] rag_search 和 rag_ask 接受可选 repo 参数
  • [x] 何时 repo 省略,搜索覆盖所有存储库
  • [x] rag_list_repos 返回集合中不同的仓库名称
  • [x] rag_delete_repo 删除给定仓库的所有向量

US-4--从Copilot聊天中获取的文件

  • [x] rag_ingest 接受 text, repo, source,可选 language, branch, chunkSize
  • [x] 文本拆分为重叠的500个字符块(重叠10%)
  • [x] 每个块嵌入 nomic-embed-text
  • [x] 大块被打乱了 wait: true
  • [x] 完成时报告块计数

US-5--来自Copilot Chat的语义搜索

  • [x] rag_search 接受 query,可选 repo,可选 topK
  • [x] 结果显示分数、仓库名称和源文件路径
  • [x] 在空集合上返回“未找到结果”

US-6--副驾驶用当地骆驼回答问题

  • [x] rag_ask 接受 question,可选 repo,可选 topK
  • [x] 检索前K个块,传递给 llama3.2 为了世代
  • [x] 将答案+来源作为结构化内容返回

US-7-git提交时自动摄取(所有repos)

作为一个 开发商, 我想要 每次提交时自动摄取更改的文件, 以便 RAG DB总是反映我的最新代码,无需手动步骤。

  • [x] scripts/install-hooks.ps1 安装全局git post-commit 挂在Windows上
  • [x] scripts/install-hooks.sh 在Linux/MOSC/WSL上安装挂钩
  • [x] Hook从以下位置读取更改的文件 git diff-tree,按分机号、呼叫进行筛选 scripts/ingest.ts --file
  • [x] 摄入在后台运行(&)因此提交不会被阻止
  • [x] 适用于机器上的每个仓库 git init 重新运行

US-8--通过监视器实时保存文件(多仓库)

作为一个 开发商, 我想要 RAG DB在我保存文件时进行更新, 以便 Copilot总是有最新的上下文,甚至在我提交之前。

  • [x] scripts/watcher.ts 监视中定义的多个目录 watcher-config.json
  • [x] 快速减持(默认1500ms)
  • [x] 在重新接收更改之前,删除文件的过时向量
  • [x] 删除文件时删除向量
  • [x] 读取每个更改文件的当前git分支
  • [x] npm run watch 从项目根启动守护进程

先决条件


设置

1.克隆和配置

git clone https://github.com/Polskipepek/qdrant-mcp.git
cd qdrant-mcp
copy .env.example .env
# Edit .env if needed

2.启动基础设施

docker compose up -d
docker exec -it ollama ollama pull nomic-embed-text
docker exec -it ollama ollama pull llama3.2

3.构建MCP服务器

npm install
npm run build

4.配置VS代码

Ctrl+Shift+P → MCP:打开用户配置:

{
  "servers": {
    "qdrantGlobal": {
      "type": "stdio",
      "command": "C:\\Program Files\\nodejs\\node.exe",
      "args": ["C:\\Dev\\VS\\qdrant-mcp\\dist\\server.js"],
      "env": {
        "QDRANT_URL": "http://localhost:6333",
        "OLLAMA_URL": "http://localhost:11434",
        "EMBEDDING_MODEL": "nomic-embed-text",
        "CHAT_MODEL": "llama3.2",
        "COLLECTION_NAME": "codebase",
        "VECTOR_SIZE": "768",
        "SEARCH_TOP_K": "5"
      }
    }
  }
}

自动摄取设置

选项A——Git钩子(提交时摄取)

# Run once from qdrant-mcp root
.\scripts\install-hooks.ps1

# Then in each existing repo:
cd C:\Dev\VS\BB.Pay
git init   # copies hook from template

从现在开始,每 git commit 在任何repo中,都会自动在后台摄取更改的文件。

选项B——文件监视器(保存时摄取)

# 1. Copy and edit the config
copy watcher-config.example.json watcher-config.json
# Edit watcher-config.json with your repo paths

# 2. Start the watcher
npm run watch

将观察器作为后台进程或Windows服务运行,以实现始终在线的摄取。

首次大量摄入

npm run ingest -- --dir C:\Dev\VS\BB.Pay --repo bb-pay
npm run ingest -- --dir C:\Dev\VS\qdrant-mcp --repo qdrant-mcp

可用的MCP工具

工具 描述 关键参数
qdrant_health 检查Qdrant --
ollama_health 检查Ollama -
qdrant_list_collections 列出集合 --
qdrant_create_collection 创建收藏 name, size, distance
qdrant_delete_collection 删除收藏 name
rag_list_repos 列出摄入的存储库 --
rag_ingest 摄入文本 text, repo, source
rag_delete_repo 删除repo的所有向量 repo
rag_search 语义搜索 query, repo?, topK?
rag_ask RAG与Llama的回答 question, repo?, topK?

发展

npm run dev   # hot-reload MCP server via tsx
npm run watch # start file watcher daemon