本地KB
用于本地知识库操作的MCP(模型上下文协议)服务器。LocalKB允许代理使用语义搜索和文档分块创建、管理和搜索个人知识库。
在使用LocalKB之前,请下载所需的模型以避免启动延迟:
pip install huggingface-hub
huggingface-cli download Qwen/Qwen3-Embedding-0.6B
huggingface-cli download Qwen/Qwen3-Reranker-0.6B基于我的M1 Max MacBook Pro的预期时间:
- 第一次使用
add_text_to_kb或search_kb在会话中,将模型加载到内存中,大约需要额外10秒。 - 搜索大约需要10秒(结果在大约0.5秒内检索到,然后重新排序模型花费大约1.5-2秒对每个结果进行评分。)
可用工具
知识库管理
list_kbs -列出所有可用的知识库
- 没有自变量
create_kb -创建新的知识库
kb_name(string):知识库的名称description(string):知识库的描述
内容管理
add_text_to_kb -将文本内容直接添加到知识库中
kb_name(string):要向其中添加内容的知识库的名称source(string):文本内容的唯一标识符(例如,文件名、文档标题)text(string):要添加到知识库的文本内容metadata(object,可选):附加到所有内容的可选元数据字典
search_kb -使用语义搜索搜索相关内容
kb_name(string):要搜索的知识库的名称query(string):搜索查询字符串filters(object,可选):可选ChromaDB元数据过滤器,用于缩小搜索范围
添加到克劳德
添加到您的Claude Code MCP配置中:
claude mcp add-json -s user LocalKB '{"command": "uvx", "args": ["--from", "git+https://github.com/RoryMB/LocalKB@main", "localkb"]}'添加到您的Claude Desktop MCP配置中:
{
"mcpServers": {
"LocalKB": {
"command": "uvx",
"args": ["--from", "git+https://github.com/RoryMB/LocalKB@main", "localkb"]
}
}
}手动使用
命令行
运行此命令打开一个交互式菜单,其中包含使用各种工具的选项:
uvx --from git+https://github.com/RoryMB/LocalKB@main localkb --cliPython导入
如果不想克隆仓库,请使用以下命令运行Python文件:
uv run --with git+https://github.com/RoryMB/LocalKB@main file.pyPython文件示例:
from localkb.tools import (
create_kb,
add_text_to_kb,
search_kb,
list_kbs
)
def main():
# Create a knowledge base
result = create_kb("my-docs", "Project documentation")
print(result)
# Add content
result = add_text_to_kb(
"my-docs",
"installation-guide",
"To install this project, run: pip install -e ."
)
print(result)
# Search for content
results = search_kb("my-docs", "how to install")
for result in results:
print(f"Content: {result['content']}")
print(f"Source: {result['metadata']['source']}")
# Run the function
main()