返回顶部
c

codebase-search代码库语义搜索

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

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
133
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

codebase-search

代码库搜索

在Python源文件上构建持久的ChromaDB向量索引,支持通过自然语言查询进行语义搜索。

快速开始

1. 安装脚本

将scripts/codechunker.py和scripts/codeindex.py复制到你的项目中。除chromadb外无其他依赖(使用pip install chromadb安装)。

2. 构建索引

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()速度很快——仅索引新增/变更的文件。

3. 搜索

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})

便捷API(集成到项目时)

如果codechunker.py和codeindex.py作为模块存在于项目中,可使用单例辅助函数:

python
from prsm.compute.nwtn.corpus import search_codebase

results = await searchcodebase(circuit breaker, topk=3)

关键选项

参数默认值描述
topk5返回结果数量
symboltype
无 | 过滤为class或function | | force_rebuild | False | 清除并重建整个索引 | | exclude_patterns | 见下方 | 跳过的目录 |

默认排除项:pycache、.venv、migrations、tests、scripts、.git、nodemodules、.codebaseindex

工作原理

  1. 1. 分块 — CodeChunker使用Python的ast模块从每个.py文件中提取所有顶级类和函数。捕获名称、类型、文档字符串、行号和源代码。
  2. 索引 — ChromaDB将每个块存储为文档:{symbol_name}: {docstring or source first 300 chars}。使用ChromaDB默认的嵌入函数(无需API密钥)。
  3. 搜索 — 余弦相似度查询返回带文件路径、符号名称、行号、文档字符串和相关度评分的排序SearchResult对象。

.gitignore

始终将.codebase_index/添加到.gitignore中——它是本地产物,而非源代码。

参考

集成模式请参见references/integration.md,包括如何将语义搜索接入子代理委派提示。

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 codebase-search-1775940150 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 codebase-search-1775940150 技能

通过命令行安装

skillhub install codebase-search-1775940150

下载

⬇ 下载 codebase-search v1.0.0(免费)

文件大小: 6.17 KB | 发布时间: 2026-4-12 09:30

v1.0.0 最新 2026-4-12 09:30
- Initial release of codebase-search: build and persist a semantic vector index over a Python codebase for natural language search.
- Enables retrieval of relevant classes, functions, or modules by meaning, not just exact name matches.
- Fast incremental indexing with support for filtering by symbol type, customizing exclusions, and easy integration into agentic workflows.
- Designed for Python projects; not intended for non-Python codebases or exact-string/grep searches.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部