secondbrain-search-init
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInitialize Semantic Search
初始化语义搜索
Set up qmd semantic search for an existing secondbrain project.
为现有的secondbrain项目设置qmd语义搜索。
Prerequisites
前提条件
- Secondbrain project exists: Check for
.claude/data/config.yaml - qmd installed: Check with
which qmd
- 已存在secondbrain项目:检查是否存在文件
.claude/data/config.yaml - 已安装qmd:使用命令检查
which qmd
Workflow
工作流程
Step 1: Validate Environment
步骤1:验证环境
bash
undefinedbash
undefinedCheck secondbrain exists
检查secondbrain是否存在
ls .claude/data/config.yaml
ls .claude/data/config.yaml
Check qmd installation
检查qmd安装情况
which qmd
If secondbrain not found:No secondbrain project found in current directory.
Run to create a new project first.
/secondbrain-init
If qmd not installed:which qmd
如果未找到secondbrain:当前目录下未找到secondbrain项目。
请先运行创建新项目。
/secondbrain-init
如果未安装qmd:qmd Not Installed
qmd未安装
qmd is required for semantic search. Install it:
语义搜索需要依赖qmd。请按照以下方式安装:
Using Bun (Recommended)
使用Bun(推荐)
bun install -g qmd
bun install -g qmd
Using npm
使用npm
npm install -g qmd
After installation, run this skill again.
Note: First run will download ~1.5GB of embedding models.
undefinednpm install -g qmd
安装完成后,请重新运行此技能。
注意:首次运行会下载约1.5GB的嵌入模型。
undefinedStep 2: Check Existing Search
步骤2:检查现有搜索设置
bash
ls .claude/search/ 2>/dev/nullIf search already initialized:
undefinedbash
ls .claude/search/ 2>/dev/null如果搜索已初始化:
undefinedSearch Already Initialized
搜索已初始化
Search is already configured for this project.
Index location: .claude/search/
Last indexed: 2026-01-15 10:30
当前项目已配置搜索功能。
索引位置:.claude/search/
最后索引时间:2026-01-15 10:30
Options
可选操作
-
Rebuild index — Re-index all documents
/secondbrain-search-init --rebuild -
Search now — Start searching
/secondbrain-search "your query" -
Check status — View index statistics
qmd status
undefined-
重建索引 — 重新索引所有文档
/secondbrain-search-init --rebuild -
立即搜索 — 开始搜索
/secondbrain-search "your query" -
检查状态 — 查看索引统计信息
qmd status
undefinedStep 3: Create Search Configuration
步骤3:创建搜索配置
Create directory and qmd config:
.claude/search/bash
mkdir -p .claude/searchGenerate in project root:
qmd.config.jsonjson
{
"name": "{{project_name}}-secondbrain",
"paths": ["docs"],
"ignore": [
"**/node_modules/**",
"**/.vitepress/cache/**",
"**/.vitepress/dist/**",
"**/TEMPLATE.md"
],
"indexDir": ".claude/search",
"chunk": {
"size": 800,
"overlap": 0.15
},
"metadata": {
"extractFrontmatter": true,
"includeFileMetadata": true
}
}创建目录和qmd配置文件:
.claude/search/bash
mkdir -p .claude/search在项目根目录生成:
qmd.config.jsonjson
{
"name": "{{project_name}}-secondbrain",
"paths": ["docs"],
"ignore": [
"**/node_modules/**",
"**/.vitepress/cache/**",
"**/.vitepress/dist/**",
"**/TEMPLATE.md"
],
"indexDir": ".claude/search",
"chunk": {
"size": 800,
"overlap": 0.15
},
"metadata": {
"extractFrontmatter": true,
"includeFileMetadata": true
}
}Step 4: Update .gitignore
步骤4:更新.gitignore
Add search index to (index should not be committed):
.gitignoreundefined将搜索索引添加到(索引文件不应提交):
.gitignoreundefinedSemantic search index (regenerate with /secondbrain-search-init)
语义搜索索引(可通过/secondbrain-search-init重新生成)
.claude/search/
qmd.config.json
undefined.claude/search/
qmd.config.json
undefinedStep 5: Build Initial Index
步骤5:构建初始索引
Run initial indexing:
bash
qmd indexShow progress:
undefined运行初始索引构建:
bash
qmd index进度展示:
undefinedBuilding Search Index
正在构建搜索索引
Scanning docs/...
Found 47 documents
Indexing:
[████████████████████░░░░░░░░░░] 35/47 documents
Downloading models (first run only):
- embedding-gemma-300M... done
- qwen3-reranker... done
Building embeddings:
[██████████████████████████████] 47/47 documents
Index built successfully!
- Documents: 47
- Chunks: 312
- Index size: 2.4 MB
- Location: .claude/search/
undefined扫描docs/目录...
找到47份文档
索引中:
[████████████████████░░░░░░░░░░] 35/47 份文档
下载模型(仅首次运行):
- embedding-gemma-300M... 完成
- qwen3-reranker... 完成
构建嵌入向量:
[██████████████████████████████] 47/47 份文档
索引构建成功!
- 文档数量:47
- 分片数量:312
- 索引大小:2.4 MB
- 存储位置:.claude/search/
undefinedStep 6: Register Hook (Optional)
步骤6:注册钩子(可选)
Ask user if they want automatic index updates:
undefined询问用户是否需要自动更新索引:
undefinedAutomatic Index Updates
自动索引更新
Would you like to automatically update the search index
when documents are modified?
[x] Yes, add PostToolUse hook (Recommended)
- Updates index incrementally on file changes
- Adds ~0.5s to Write/Edit operations
[ ] No, I'll rebuild manually
- Run or
qmd index/secondbrain-search-init --rebuild
If yes, add hook to `.claude/settings.local.json`:
```json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "python3 \"${CLAUDE_PROJECT_DIR}/.claude/hooks/search-index-update.py\"",
"timeout": 30000
}
]
}
]
}
}Copy hook script:
bash
cp "${CLAUDE_PLUGIN_ROOT}/hooks/search-index-update.py" .claude/hooks/当文档被修改时,是否需要自动更新搜索索引?
[x] 是,添加PostToolUse钩子(推荐)
- 文件变更时增量更新索引
- 会为写入/编辑操作增加约0.5秒耗时
[ ] 否,我将手动重建
- 运行或
qmd index/secondbrain-search-init --rebuild
如果用户选择是,将钩子添加到`.claude/settings.local.json`:
```json
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "python3 \"${CLAUDE_PROJECT_DIR}/.claude/hooks/search-index-update.py\"",
"timeout": 30000
}
]
}
]
}
}复制钩子脚本:
bash
cp "${CLAUDE_PLUGIN_ROOT}/hooks/search-index-update.py" .claude/hooks/Step 7: Show Summary
步骤7:显示总结
undefinedundefinedSearch Initialized Successfully!
搜索初始化成功!
Project: my-knowledge-base
Documents indexed: 47
Index location: .claude/search/
项目名称:my-knowledge-base
已索引文档数量:47
索引存储位置:.claude/search/
Quick Start
快速开始
Search your knowledge base:
/secondbrain-search "kubernetes deployment strategies"
Search with filters:
/secondbrain-search --entity=adrs "database"
/secondbrain-search --recent=30d "authentication"
搜索你的知识库:
/secondbrain-search "kubernetes deployment strategies"
带过滤条件的搜索:
/secondbrain-search --entity=adrs "database"
/secondbrain-search --recent=30d "authentication"
Index Management
索引管理
Rebuild index:
qmd index --rebuild
Check status:
qmd status
View recent searches:
qmd history
重建索引:
qmd index --rebuild
检查状态:
qmd status
查看最近搜索记录:
qmd history
Automatic Updates
自动更新
Index updates: Enabled (PostToolUse hook)
Documents in docs/ will be re-indexed on save.
undefined索引更新:已启用(PostToolUse钩子)
docs/目录中的文档在保存时会自动重新索引。
undefinedOptions
可选参数
--rebuild
--rebuild
Force rebuild of entire index:
bash
qmd index --rebuild强制重建整个索引:
bash
qmd index --rebuild--no-hook
--no-hook
Skip adding the automatic update hook:
/secondbrain-search-init --no-hook跳过添加自动更新钩子:
/secondbrain-search-init --no-hookTroubleshooting
故障排除
Models Download Stuck
模型下载卡住
If model download hangs:
bash
undefined如果模型下载停滞:
bash
undefinedClear cache and retry
清除缓存并重试
rm -rf ~/.cache/qmd/models/
qmd index
undefinedrm -rf ~/.cache/qmd/models/
qmd index
undefinedIndex Corruption
索引损坏
If search returns errors:
bash
undefined如果搜索返回错误:
bash
undefinedRemove and rebuild
删除现有索引并重建
rm -rf .claude/search/
qmd index
undefinedrm -rf .claude/search/
qmd index
undefinedSlow Indexing
索引速度慢
For large document sets (>500 docs):
- Initial indexing may take several minutes
- Consider using for progress visibility
--batch-size=50
对于大型文档集(>500份文档):
- 初始索引可能需要几分钟
- 建议使用参数以查看进度
--batch-size=50
Related Skills
相关技能
- secondbrain-search — Search your knowledge base
- secondbrain-init — Create new secondbrain project
- secondbrain-search — 搜索你的知识库
- secondbrain-init — 创建新的secondbrain项目