secondbrain-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Semantic Search

语义搜索

Search your secondbrain knowledge base using semantic similarity (meaning-based) and full-text search.
使用语义相似度(基于语义)和全文搜索功能检索你的secondbrain知识库。

Prerequisites

前提条件

  1. qmd installed: Check with
    which qmd
    • Install:
      bun install -g qmd
      or
      npm install -g qmd
    • First run downloads ~1.5GB models
  2. Search initialized: Check for
    .claude/search/
    directory
    • If not initialized, suggest running
      /secondbrain-search-init
  1. 已安装qmd:使用
    which qmd
    命令检查
    • 安装方式:
      bun install -g qmd
      npm install -g qmd
    • 首次运行会下载约1.5GB的模型
  2. 已初始化搜索:检查是否存在
    .claude/search/
    目录
    • 若未初始化,建议运行
      /secondbrain-search-init

Usage

使用方法

/secondbrain-search "your natural language query"
/secondbrain-search --entity=adrs "database migration"
/secondbrain-search --recent=30d "authentication"
/secondbrain-search --status=active --tag=kubernetes "deployment"
/secondbrain-search "你的自然语言查询语句"
/secondbrain-search --entity=adrs "数据库迁移"
/secondbrain-search --recent=30d "身份验证"
/secondbrain-search --status=active --tag=kubernetes "部署"

Workflow

工作流程

Step 1: Validate Environment

步骤1:验证环境

bash
undefined
bash
undefined

Check qmd is installed

检查qmd是否已安装

which qmd
which qmd

Check search is initialized

检查搜索是否已初始化

ls .claude/search/

If qmd not installed:
qmd is not installed. Install it with: bun install -g qmd

or

npm install -g qmd
Then initialize search with: /secondbrain-search-init

If search not initialized:
Search not initialized for this project. Run: /secondbrain-search-init
undefined
ls .claude/search/

若未安装qmd:
qmd未安装。可通过以下命令安装: bun install -g qmd

npm install -g qmd
然后运行以下命令初始化搜索:/secondbrain-search-init

若未初始化搜索:
当前项目未初始化搜索功能。 请运行:/secondbrain-search-init
undefined

Step 2: Parse Query and Filters

步骤2:解析查询语句与筛选条件

Extract from user input:
FilterSyntaxExample
Entity
--entity=<type>
--entity=adrs,notes
Recent
--recent=<period>
--recent=7d
,
--recent=2w
,
--recent=1m
Date from
--from=<date>
--from=2025-01-01
Date to
--to=<date>
--to=2025-12-31
Status
--status=<status>
--status=active
,
--status=!archived
Tag
--tag=<tag>
--tag=kubernetes
Limit
--limit=<n>
--limit=10
(default: 5)
Format
--format=<fmt>
--format=brief
,
--format=detailed
,
--format=json
从用户输入中提取以下内容:
筛选条件语法示例
实体类型
--entity=<类型>
--entity=adrs,notes
时间范围(最近)
--recent=<周期>
--recent=7d
,
--recent=2w
,
--recent=1m
起始日期
--from=<日期>
--from=2025-01-01
结束日期
--to=<日期>
--to=2025-12-31
状态
--status=<状态>
--status=active
,
--status=!archived
标签
--tag=<标签>
--tag=kubernetes
结果数量限制
--limit=<数字>
--limit=10
(默认值:5)
输出格式
--format=<格式>
--format=brief
,
--format=detailed
,
--format=json

Step 3: Execute Search

步骤3:执行搜索

Run qmd search command:
bash
cd <project_root>
qmd query "<user_query>" --json --limit=<limit>
Parse JSON output:
json
{
  "results": [
    {
      "id": "docs/adrs/ADR-0012-kubernetes-deployment.md",
      "score": 0.92,
      "title": "Kubernetes Deployment Strategy",
      "excerpt": "We decided to use Blue-Green deployment for stateless services...",
      "metadata": {
        "frontmatter": {
          "status": "implemented",
          "created": "2025-12-15"
        }
      }
    }
  ]
}
运行qmd搜索命令:
bash
cd <项目根目录>
qmd query "<用户查询语句>" --json --limit=<数量限制>
解析JSON输出:
json
{
  "results": [
    {
      "id": "docs/adrs/ADR-0012-kubernetes-deployment.md",
      "score": 0.92,
      "title": "Kubernetes Deployment Strategy",
      "excerpt": "We decided to use Blue-Green deployment for stateless services...",
      "metadata": {
        "frontmatter": {
          "status": "implemented",
          "created": "2025-12-15"
        }
      }
    }
  ]
}

Step 4: Enrich with Metadata

步骤4:补充元数据

Load YAML records to add entity-specific metadata:
For each result:
  1. Determine entity type from file path (e.g.,
    docs/adrs/
    → ADRs)
  2. Load corresponding records from
    .claude/data/<entity>/records.yaml
  3. Match by file path and enrich with status, tags, dates, etc.
加载YAML记录以添加实体特定的元数据:
针对每个搜索结果:
  1. 根据文件路径确定实体类型(例如:
    docs/adrs/
    → ADRs)
  2. .claude/data/<实体类型>/records.yaml
    加载对应的记录
  3. 通过文件路径匹配,补充状态、标签、日期等信息

Step 5: Apply Post-Filters

步骤5:应用后置筛选

Filter results based on user criteria:
python
undefined
根据用户的条件筛选结果:
python
undefined

Pseudocode

伪代码

for result in results: if entity_filter and result.entity not in entity_filter: skip if status_filter and result.status != status_filter: skip if tag_filter and tag_filter not in result.tags: skip if date_filter and not in_date_range(result.date, from_date, to_date): skip
undefined
for result in results: if entity_filter and result.entity not in entity_filter: skip if status_filter and result.status != status_filter: skip if tag_filter and tag_filter not in result.tags: skip if date_filter and not in_date_range(result.date, from_date, to_date): skip
undefined

Step 6: Format Output

步骤6:格式化输出

Brief Format (default for >3 results)

简洁格式(结果数量>3时默认使用)

undefined
undefined

Search Results

搜索结果

Query: "kubernetes deployment" Results: 4 matches
  1. [ADR-0012] Kubernetes Deployment Strategy (0.92) Status: implemented | Updated: 2025-12-15
  2. [Note] Kubernetes Scaling Best Practices (0.87) Tags: kubernetes, scaling | Created: 2025-11-20
  3. [Discussion] Platform Team - Deployment Pipeline (0.79) Date: 2025-10-05 | Participants: Alice, Bob
  4. [Task] Implement Canary Deployments (0.71) Status: in_progress | Priority: high
undefined
查询语句: "kubernetes deployment" 匹配结果: 4条
  1. [ADR-0012] Kubernetes Deployment Strategy (0.92) 状态: implemented | 更新日期: 2025-12-15
  2. [Note] Kubernetes Scaling Best Practices (0.87) 标签: kubernetes, scaling | 创建日期: 2025-11-20
  3. [Discussion] Platform Team - Deployment Pipeline (0.79) 日期: 2025-10-05 | 参与人: Alice, Bob
  4. [Task] Implement Canary Deployments (0.71) 状态: in_progress | 优先级: high
undefined

Detailed Format (default for ≤3 results)

详细格式(结果数量≤3时默认使用)

undefined
undefined

Search Results

搜索结果

Query: "kubernetes deployment" Results: 2 matches

查询语句: "kubernetes deployment" 匹配结果: 2条

1. [ADR-0012] Kubernetes Deployment Strategy

1. [ADR-0012] Kubernetes Deployment Strategy

Score: 0.92 | Status: implemented | Category: infrastructure
File: ADR-0012-kubernetes-deployment.md
Excerpt:
We decided to use Blue-Green deployment for stateless services and Rolling updates for stateful workloads. This approach provides zero-downtime deployments while minimizing resource overhead...
Metadata:
  • Created: 2025-12-15
  • Author: sergey
  • Category: infrastructure

匹配得分: 0.92 | 状态: implemented | 分类: infrastructure
文件: ADR-0012-kubernetes-deployment.md
内容摘要:
We decided to use Blue-Green deployment for stateless services and Rolling updates for stateful workloads. This approach provides zero-downtime deployments while minimizing resource overhead...
元数据:
  • 创建日期: 2025-12-15
  • 作者: sergey
  • 分类: infrastructure

2. [Note] Kubernetes Scaling Best Practices

2. [Note] Kubernetes Scaling Best Practices

Score: 0.87 | Tags: kubernetes, scaling
File: 2025-11-20-kubernetes-scaling.md
Excerpt:
Key considerations for scaling Kubernetes deployments:
  1. Horizontal Pod Autoscaler configuration
  2. Resource requests and limits
  3. Pod disruption budgets...
Metadata:
  • Created: 2025-11-20
  • Status: active
undefined
匹配得分: 0.87 | 标签: kubernetes, scaling
文件: 2025-11-20-kubernetes-scaling.md
内容摘要:
Key considerations for scaling Kubernetes deployments:
  1. Horizontal Pod Autoscaler configuration
  2. Resource requests and limits
  3. Pod disruption budgets...
元数据:
  • 创建日期: 2025-11-20
  • 状态: active
undefined

JSON Format

JSON格式

json
{
  "query": "kubernetes deployment",
  "total": 4,
  "results": [
    {
      "entity": "adrs",
      "id": "ADR-0012",
      "title": "Kubernetes Deployment Strategy",
      "file": "docs/adrs/ADR-0012-kubernetes-deployment.md",
      "score": 0.92,
      "excerpt": "We decided to use Blue-Green deployment...",
      "metadata": {
        "status": "implemented",
        "category": "infrastructure",
        "created": "2025-12-15",
        "author": "sergey"
      }
    }
  ]
}
json
{
  "query": "kubernetes deployment",
  "total": 4,
  "results": [
    {
      "entity": "adrs",
      "id": "ADR-0012",
      "title": "Kubernetes Deployment Strategy",
      "file": "docs/adrs/ADR-0012-kubernetes-deployment.md",
      "score": 0.92,
      "excerpt": "We decided to use Blue-Green deployment...",
      "metadata": {
        "status": "implemented",
        "category": "infrastructure",
        "created": "2025-12-15",
        "author": "sergey"
      }
    }
  ]
}

Search Tips

搜索技巧

Display helpful tips when no results found:
undefined
当未找到结果时,显示实用提示:
undefined

No Results Found

未找到匹配结果

Query: "foobar nonexistent"
查询语句: "foobar nonexistent"

Tips

提示

  1. Try broader terms — Use general concepts instead of specific jargon
  2. Check spelling — Semantic search handles typos but exact terms may miss
  3. Remove filters — Try without --entity or --status filters first
  4. Use related concepts — "authentication" instead of "OAuth2"
  1. 尝试更宽泛的术语 — 使用通用概念而非特定行话
  2. 检查拼写 — 语义搜索可处理拼写错误,但精确术语可能仍会遗漏
  3. 移除筛选条件 — 先尝试不使用--entity或--status筛选条件
  4. 使用相关概念 — 用"身份验证"代替"OAuth2"

Alternative Actions

替代操作

  • /secondbrain-freshness
    — See all recent content
  • Run without filters:
    /secondbrain-search "foobar"
undefined
  • /secondbrain-freshness
    — 查看所有近期内容
  • 不使用筛选条件运行:
    /secondbrain-search "foobar"
undefined

Refine Search

优化搜索

After showing results, offer refinement options:
undefined
展示搜索结果后,提供优化选项:
undefined

Refine Search

优化搜索

  • --entity=adrs
    — Filter to ADRs only
  • --recent=30d
    — Limit to last 30 days
  • --status=active
    — Exclude archived items
  • "kubernetes AND deployment"
    — Boolean operators
undefined
  • --entity=adrs
    — 仅筛选ADRs内容
  • --recent=30d
    — 限制为最近30天的内容
  • --status=active
    — 排除已归档项目
  • "kubernetes AND deployment"
    — 使用布尔运算符
undefined

Related Skills

相关Skill

  • secondbrain-search-init — Initialize search for this project
  • secondbrain-freshness — View items by freshness/staleness
  • secondbrain-search-init — 初始化当前项目的搜索功能
  • secondbrain-freshness — 按新鲜度/过时程度查看内容