跳到正文
Skillpedia
● 免费开源💻 本地🔓 无需 API 密钥数据与数据库

MCP Local RAG

让你的智能体在本地搜索你自己的 PDF、Word、Markdown 和文本文件,无需把它们发送到任何嵌入 API。

429 GitHub 星标作者 shinpr许可证 MIT更新于 19天前

如何安装

这个 MCP 是本地的:在你的电脑上运行。

适用于电脑上安装的应用(Claude Desktop、Claude Code、Cursor、VS Code 等)。选择你的应用:

粘贴到终端:

claude mcp add local-rag -- npx -y mcp-local-rag

需要填写的内容

名称用途必填
BASE_DIRBase directory for document storage (defaults to current working directory). Ignored when BASE_DIRS is set.否
BASE_DIRSJSON array of base directories (e.g. '["/a","/b"]'). Takes precedence over BASE_DIR.否
IGNORE_PATHSJSON array of glob patterns for files to keep out of the index, each matched against the file's path relative to its root (e.g. '["plugs/**","**/*.draft.md"]').否
DB_PATHPath to LanceDB database directory (defaults to ./lancedb/)否
CACHE_DIRDirectory where Transformers.js models are cached (defaults to ./models/)否
HF_ENDPOINTHugging Face model download endpoint. Set this to a mirror URL when direct downloads are blocked (defaults to https://huggingface.co).否
MODEL_NAMEEmbedding model name (defaults to Xenova/all-MiniLM-L6-v2)否
MAX_FILE_SIZEMaximum file size in bytes (defaults to 104857600 / 100MB)否
RAG_MAX_DISTANCEMaximum distance threshold for filtering search results. Results with distance greater than this value will be excluded. Lower values mean stricter filtering (e.g., 0.5 for high relevance only)否
RAG_GROUPINGGrouping mode for quality filtering. 'similar' returns only the most similar group (stops at first distance jump). 'related' includes related groups (stops at second distance jump). Unset means no grouping filter否
RAG_MAX_FILESMaximum number of files to keep in search results. Results are filtered to include only chunks from the top N best-scoring files. For example, 1 returns only the single best-matching file's chunks. Unset means no file filtering.否
CHUNK_MIN_LENGTHMinimum chunk length in characters (1-10000, defaults to 50). Chunks shorter than this threshold are filtered out during ingestion.否
STORE_IMAGESStore supported PDF and DOCX images during ingestion and return them with matched chunks (defaults to false).否
EMBED_TITLE_PREFIXEmbed each chunk together with its document title, which can help when passages don't restate the topic the title names (defaults to false). After changing it, use a new DB_PATH or delete the index and re-ingest.否
EMBED_HEADING_PREFIXAdd section headings to chunk embeddings when they fit (defaults to false). Independent of EMBED_TITLE_PREFIX. Re-ingest documents after changing it.否
RAG_DEVICEExecution device for the embedder (defaults to cpu). Passed straight to ONNX Runtime; see the Transformers.js device source for the supported backend names. If the requested device fails to initialize, the server throws an error.否
RAG_DTYPEEmbedding quantization dtype for the embedder (defaults to fp32). Opt-in and pass-through; accepts any dtype the chosen model provides (fp32, fp16, q8, int8, ...). If the model has no variant for the requested dtype, the server throws an error. Changing this changes the embedding space — re-ingest existing data.否
RAG_HYBRID_WEIGHTKeyword boost factor for hybrid search (0.0-1.0, defaults to 0.6). 0 means semantic similarity only; higher values increase the keyword-match contribution to the final score.否
RAG_RERANK_CMDExternal reranker command template. Use {query} and {top} for query text and result count; unset disables reranking.否
RAG_RERANK_TIMEOUT_MSTime budget per rerank call in milliseconds (100-600000, defaults to 10000). On timeout the spawned command is killed and the pre-rerank ordering is returned.否

好了!现在试试

重启应用,把下面任意一条请求粘贴到聊天里:

同步已配置文件夹中的所有文档,并在完成后告诉我。
API 文档中关于身份验证是怎么说的?

简介

这个服务器在你的电脑上为文档建立索引,并同时按含义和精确关键词进行搜索。结果会包含来源段落,以及在可用时的标题、行号或页码。模型首次下载完成后,建立索引和搜索都可以离线进行。

它能做什么

  • sync_start: 让索引与你的文件夹保持同步
  • sync_status: 检查正在运行的同步
  • ingest_file: 添加或替换一个文件
  • ingest_data: 添加客户端持有的文本、Markdown 或 HTML
  • query_documents: 按含义和关键词匹配进行搜索
  • read_chunk_neighbors: 读取搜索结果周围的文字
  • list_files: 显示文件及其索引状态
  • delete_file: 删除已索引的文件

什么时候用

  • ›当你希望就一个私人文档文件夹提问时
  • ›当你既需要 API 名称或错误代码这样的精确匹配,也需要基于含义的搜索时
  • ›当你希望答案附有页码或行号,以便核对来源时

你需要准备

Node.js 22.20 或更高版本,并将文档文件夹设置为 BASE_DIR。首次需要联网下载软件包和约 90 MB 的嵌入模型。无需 API 密钥、Docker 或 Python。

搭配的技能

⭐ Skillpedia MCP · 免费你的智能体自己找到合适的技能安装我们的 MCP,智能体需要时会在 15,000+ 个技能中搜索。免费安装 →

常见问题

我的数据会被上传到云端吗?

不会。它不使用嵌入 API,模型下载后可以离线工作。

支持哪些文件?

PDF、DOCX、TXT 和 Markdown,以及客户端传入的 HTML 或文本。Excel、PowerPoint、图片和源代码文件不受支持。

我需要 API 密钥吗?

不需要。无需 API 密钥、Docker、Python 或外部数据库。

有命令行吗?

有。你可以使用 npx mcp-local-rag 运行 ingest、query、sync、list、status 和 delete。

它如何限制文件访问?

BASE_DIR 是文件操作的安全边界,MCP 文件路径必须是绝对路径,并且位于已配置的根目录之内。

我能更换模型吗?

可以,使用 MODEL_NAME 设置。更换模型后,请在新的 DB_PATH 下重新建立索引。

如果不能用

  • ›将 BASE_DIR、DB_PATH 和 CACHE_DIR 设置为绝对路径,避免每个项目都创建一份索引。
  • ›首次同步可能需要 1 到 2 分钟,因为模型正在下载。
  • ›如果 Hugging Face 下载被阻止,请将 HF_ENDPOINT 设置为镜像网址。

每周 5 个新技能,1 分钟读完。