一个与平台无关的代码分析库,具有语义搜索功能,并支持MCP(模型上下文协议)服务器。此库提供智能代码索引、基于向量的语义搜索,并可以集成到各种开发工具和IDE中。
# 安装Ollama(macOS)
brew install ollama
# 启动Ollama服务
ollama serve
# 在新的终端中,拉取嵌入模型
ollama pull dengcao/Qwen3-Embedding-0.6B:Q8_0
ripgrep 是快速代码库索引所必需的。安装方法如下:
# 安装ripgrep(macOS)
brew install ripgrep
# 或在Ubuntu/Debian上
sudo apt-get install ripgrep
# 或在Arch Linux上
sudo pacman -S ripgrep
使用Docker启动Qdrant:
# 启动Qdrant容器
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant
或直接下载并运行Qdrant:
# 下载并运行Qdrant
wget https://github.com/qdrant/qdrant/releases/latest/download/qdrant-x86_64-unknown-linux-gnu.tar.gz
tar -xzf qdrant-x86_64-unknown-linux-gnu.tar.gz
./qdrant
# 检查Ollama
curl http://localhost:11434/api/tags
# 检查Qdrant
curl http://localhost:6333/collections
npm install -g @autodev/codebase
或者你可以本地安装:
git clone https://github.com/anrgct/autodev-codebase
cd autodev-codebase
npm install
npm run build
npm link
CLI提供了两种主要模式:
# 基本用法:将当前文件夹作为代码库进行索引。
# 如果文件数量较多,请谨慎运行此命令。
codebase
# 自定义选项
codebase --demo # 创建本地演示目录并测试索引服务,推荐用于设置
codebase --path=/my/project
codebase --path=/my/project --log-level=info
# 启动长期运行的MCP服务器
cd /my/project
codebase mcp-server
# 自定义配置
codebase mcp-server --port=3001 --host=localhost
codebase mcp-server --path=/workspace --port=3002
该库使用分层配置系统,允许你在不同级别自定义设置。优先级顺序(从高到低)是:
--model,--ollama-url,--qdrant-url,--config等)./autodev-config.json)~/.autodev-cache/autodev-config.json)在较高层级指定的设置会覆盖较低层级的设置。这让你可以根据环境或项目需求定制行为。
配置文件位置:
~/.autodev-cache/autodev-config.json./autodev-config.json在 ~/.autodev-cache/autodev-config.json 创建一个全局配置文件:
{
"isEnabled": true,
"embedder": {
"provider": "ollama",
"model": "dengcao/Qwen3-Embedding-0.6B:Q8_0",
"dimension": 1024,
"baseUrl": "http://localhost:11434"
},
"qdrantUrl": "http://localhost:6333",
"qdrantApiKey": "your-api-key-if-needed",
"searchMinScore": 0.4
}
在 ./autodev-config.json 创建一个项目特定的配置文件:
{
"embedder": {
"provider": "openai-compatible",
"apiKey": "sk-xxxxx",
"baseUrl": "http://localhost:2302/v1",
"model": "openai/text-embedding-3-smallnpm",
"dimension": 1536,
},
"qdrantUrl": "http://localhost:6334"
}
| 选项 | 类型 | 描述 | 默认值 |
|---|---|---|---|
isEnabled | boolean | 开启/关闭代码索引功能 | true |
embedder.provider | string | 嵌入提供者(ollama,openai,openai-compatible) | ollama |
embedder.model | string | 嵌入模型名称 | dengcao/Qwen3-Embedding-0.6B:Q8_0 |
embedder.dimension | number | 向量维度大小 | 1024 |
embedder.baseUrl | string | 提供者API基础URL | http://localhost:11434 |
embedder.apiKey | string | API密钥(适用于OpenAI/兼容提供者) | - |
qdrantUrl | string | Qdrant向量数据库URL | http://localhost:6333 |
qdrantApiKey | string | Qdrant API密钥(如果启用身份验证) | - |
searchMinScore | number | 搜索结果的最小相似度分数 | 0.4 |
注意:isConfigured 字段根据配置的完整性自动计算,不应手动设置。系统将根据所选提供者的必要字段确定配置是否有效。
# 使用全局配置默认值
codebase
# 通过CLI覆盖模型(最高优先级)
codebase --model="custom-model"
# 使用项目配置并覆盖CLI
codebase --config=./my-config.json --qdrant-url=http://remote:6333
--path=<path> - 工作区路径(默认:当前目录)--demo - 在工作区创建演示文件--force - 忽略缓存强制重新索引--ollama-url=<url> - Ollama API URL(默认:http://localhost:11434)--qdrant-url=<url> - Qdrant向量DB URL(默认:http://localhost:6333)--model=<model> - 嵌入模型(默认:nomic-embed-text)--config=<path> - 配置文件路径--storage=<path> - 存储目录路径--cache=<path> - 缓存目录路径--log-level=<level> - 日志级别:error|warn|info|debug(默认:error)--help, -h - 显示帮助--port=<port> - HTTP服务器端口(默认:3001)--host=<host> - HTTP服务器主机(默认:localhost)配置你的IDE以连接到MCP服务器:
{
"mcpServers": {
"codebase": {
"url": "http://localhost:3001/sse"
}
}
}
对于不支持SSE MCP的客户端,可以使用以下配置:
{
"mcpServers": {
"codebase": {
"command": "codebase",
"args": [
"stdio-adapter",
"--server-url=http://localhost:3001/sse"
]
}
}
}
http://localhost:3001 - 服务器状态和配置http://localhost:3001/health - JSON状态端点http://localhost:3001/sse - SSE/HTTP MCP协议端点search_codebase - 通过你的代码库进行语义搜索
query(字符串),limit(数字),filters(对象)# 开发模式带演示文件
npm run dev
# 构建生产版本
npm run build
# 类型检查
npm run type-check
# 运行TUI演示
npm run demo-tui
# 启动MCP服务器演示
npm run mcp-server
主流嵌入模型性能
| 模型 | 维度 | 平均精度@3 | 平均精度@5 | 好查询(≥66.7%) | 失败查询(0%) |
|---|---|---|---|---|---|
| siliconflow/Qwen/Qwen3-Embedding-8B | 4096 | 76.7% | 66.0% | 5/10 | 0/10 |
| siliconflow/Qwen/Qwen3-Embedding-4B | 2560 | 73.3% | 54.0% | 5/10 | 1/10 |
| voyage/voyage-code-3 | 1024 | 73.3% | 52.0% | 6/10 | 1/10 |
| siliconflow/Qwen/Qwen3-Embedding-0.6B | 1024 | 63.3% | 42.0% | 4/10 | 1/10 |
| morph-embedding-v2 | 1536 | 56.7% | 44.0% | 3/10 | 1/10 |
| openai/text-embedding-ada-002 | 1536 | 53.3% | 38.0% | 2/10 | 1/10 |
| voyage/voyage-3-large | 1024 | 53.3% | 42.0% | 3/10 | 2/10 |
| openai/text-embedding-3-large | 3072 | 46.7% | 38.0% | 1/10 | 3/10 |
| voyage/voyage-3.5 | 1024 | 43.3% | 38.0% | 1/10 | 2/10 |
| voyage/voyage-3.5-lite | 1024 | 36.7% | 28.0% | 1/10 | 2/10 |
| openai/text-embedding-3-small | 1536 | 33.3% | 28.0% | 1/10 | 4/10 |
| siliconflow/BAAI/bge-large-en-v1.5 | 1024 | 30.0% | 28.0% | 0/10 | 3/10 |
| siliconflow/Pro/BAAI/bge-m3 | 1024 | 26.7% | 24.0% | 0/10 | 2/10 |
| ollama/nomic-embed-text | 768 | 16.7% | 18.0% | 0/10 | 6/10 |
| siliconflow/netease-youdao/bce-embedding-base_v1 | 1024 | 13.3% | 16.0% | 0/10 | 6/10 |
基于Ollama的嵌入模型性能
| 模型 | 维度 | 精度@3 | 精度@5 | 好查询(≥66.7%) | 失败查询(0%) |
|---|---|---|---|---|---|
| ollama/dengcao/Qwen3-Embedding-4B:Q4_K_M | 2560 | 66.7% | 48.0% | 4/10 | 1/10 |
| ollama/dengcao/Qwen3-Embedding-0.6B:f16 | 1024 | 63.3% | 44.0% | 3/10 | 0/10 |
| ollama/dengcao/Qwen3-Embedding-0.6B:Q8_0 | 1024 | 63.3% | 44.0% | 3/10 | 0/10 |
| ollama/dengcao/Qwen3-Embedding-4B:Q8_0 | 2560 | 60.0% | 48.0% | 3/10 | 1/10 |
| lmstudio/taylor-jones/bge-code-v1-Q8_0-GGUF | 1536 | 60.0% | 54.0% | 4/10 | 1/10 |
| ollama/dengcao/Qwen3-Embedding-8B:Q4_K_M | 4096 | 56.7% | 42.0% | 2/10 | 2/10 |
| ollama/hf.co/nomic-ai/nomic-embed-code-GGUF:Q4_K_M | 3584 | 53.3% | 44.0% | 2/10 | 0/10 |
| ollama/bge-m3:f16 | 1024 | 26.7% | 24.0% | 0/10 | 2/10 |
| ollama/hf.co/nomic-ai/nomic-embed-text-v2-moe-GGUF:f16 | 768 | 26.7% | 20.0% | 0/10 | 2/10 |
| ollama/granite-embedding:278m-fp16 | 768 | 23.3% | 18.0% | 0/10 | 4/10 |
| ollama/unclemusclez/jina-embeddings-v2-base-code:f16 | 768 | 23.3% | 16.0% | 0/10 | 5/10 |
| lmstudio/awhiteside/CodeRankEmbed-Q8_0-GGUF | 768 | 23.3% | 16.0% | 0/10 | 5/10 |
| lmstudio/wsxiaoys/jina-embeddings-v2-base-code-Q8_0-GGUF | 768 | 23.3% | 16.0% | 0/10 | 5/10 |
| ollama/dengcao/Dmeta-embedding-zh:F16 | 768 | 20.0% | 20.0% | 0/10 | 6/10 |
| ollama/znbang/bge:small-en-v1.5-q8_0 | 384 |