Build a persistent semantic vector index over a Python codebase and search it with natural language. Use when an agent needs to find relevant classes, functions, or modules by meaning rather than exact name — e.g. 'find all classes that handle token payments', 'where is rate limiting implemented?', 'which functions process webhook events?'. Also use when setting up codebase-search for the first time on a new repo, rebuilding a stale index, or integrating semantic search into an agentic coding wo
在Python源文件上构建持久的ChromaDB向量索引,支持通过自然语言查询进行语义搜索。
将scripts/codechunker.py和scripts/codeindex.py复制到你的项目中。除chromadb外无其他依赖(使用pip install chromadb安装)。
python
import asyncio
from code_index import CodebaseIndex
index = CodebaseIndex(repo_root=/path/to/repo)
count = asyncio.run(index.build())
print(f已索引 {count} 个符号)
索引持久化到{reporoot}/.codebaseindex/目录,重启后依然保留。后续调用build()速度很快——仅索引新增/变更的文件。
python
results = asyncio.run(index.search(token payment handling, top_k=5))
for r in results:
print(f[{r.score:.2f}] {r.symbolname} ({r.symboltype}) — {r.filepath}:{r.start_line})
如果codechunker.py和codeindex.py作为模块存在于项目中,可使用单例辅助函数:
python
from prsm.compute.nwtn.corpus import search_codebase
results = await searchcodebase(circuit breaker, topk=3)
| 参数 | 默认值 | 描述 |
|---|---|---|
| topk | 5 | 返回结果数量 |
| symboltype |
默认排除项:pycache、.venv、migrations、tests、scripts、.git、nodemodules、.codebaseindex
始终将.codebase_index/添加到.gitignore中——它是本地产物,而非源代码。
集成模式请参见references/integration.md,包括如何将语义搜索接入子代理委派提示。
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 codebase-search-1775940150 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 codebase-search-1775940150 技能
skillhub install codebase-search-1775940150
文件大小: 6.17 KB | 发布时间: 2026-4-12 09:30