@dreb/semantic-search

中文文档
2.83.0发布于 2026/11/13MITTypeScriptES Module构建来源已验证近 30 天下载 3768

Semantic codebase search engine with embedding-based ranking and MCP server

原始使用文档
文档目录8 节
  1. Requirements
  2. Installation
  3. Claude Code Plugin
  4. MCP Server
  5. How Ranking Works
  6. Library API
  7. What Gets Indexed
  8. License

@dreb/semantic-search

Semantic codebase search engine with embedding-based ranking and an MCP server. Extracts and indexes code using tree-sitter for AST-aware chunking and a transformer embedding model (all-MiniLM-L6-v2), then ranks results using 6-signal fusion via POEM.

Requirements

  • Node.js 26 LTS (^26.13.0) — uses the built-in node:sqlite module

Installation

npm install @dreb/semantic-search

Claude Code Plugin

The package ships as a Claude Code plugin. Add the dreb marketplace and install:

/plugin marketplace add aebrer/dreb
/plugin install semantic-search@dreb

Or from the CLI outside a session:

claude plugin marketplace add aebrer/dreb
claude plugin install semantic-search@dreb

Alternatively, register the MCP server directly without the plugin system:

claude mcp add --transport stdio semantic-search -- npx @dreb/semantic-search semantic-search-mcp

For local development from a cloned repo:

claude --plugin-dir ./packages/semantic-search

MCP Server

The package exposes a search tool over the Model Context Protocol (stdio transport). The tool accepts:

ParameterRequiredDescription
queryyesNatural language, identifier, or path query
searchDiryesDirectory to index and search — each unique value gets its own independent index
restrictToDirnoFilter results to files under this path within the already-built index (does not affect indexing)
limitnoMaximum results to return (default: 20)
rebuildnoForce a clean index rebuild (default: false)

Start the server standalone:

npx @dreb/semantic-search semantic-search-mcp

How Ranking Works

Results are ranked by fusing 6 independent signals using POEM (Pareto-Optimal Embedded Modeling) weights that vary per query type:

SignalDescription
BM25Keyword matching via FTS5 full-text search
Cosine similarityEmbedding-based semantic similarity using all-MiniLM-L6-v2
Path matchQuery terms appearing in the file path
Symbol matchQuery terms matching function, class, or type names
Import graphProximity to high-scoring files in the import/dependency graph
Git recencyRecently modified files ranked higher

Queries are automatically classified as identifier, natural language, or path queries, and each type applies different POEM column weights. POEM constructs a Pareto front over all signal dimensions and assigns ranks based on dominance depth — no manual weight tuning required. See Pareto-Optimal Embedded Modeling for the theoretical foundation.

Library API

import { SearchEngine } from "@dreb/semantic-search";

const engine = new SearchEngine("/path/to/project", {
  indexDir: "/custom/index/path",         // default: <projectRoot>/.search-index
  globalMemoryDir: "~/.dreb/memory",      // additional directory to index
  modelCacheDir: "~/.cache/models",       // default: ~/.cache/semantic-search/models
  visibleDirs: (root) => [`${root}/.special`], // extra dirs (bypasses .gitignore)
});

// First call builds the index (10-60s); subsequent calls are fast
const results = await engine.search("where is auth handled", {
  limit: 20,
  pathFilter: "src/",
  onProgress: (phase, current, total) => console.log(`${phase}: ${current}/${total}`),
});

const stats = engine.getStats();    // { files, chunks } | null
await engine.resetIndex();          // delete index, next search rebuilds
await engine.close();               // dispose resources
SearchEngine.isAvailable();         // check for node:sqlite

What Gets Indexed

  • Code — tree-sitter AST chunks (functions, classes, methods, interfaces, etc.). TypeScript, JavaScript, Python, Go, Rust, Java, C, C++, GDScript.
  • Text — Markdown (by heading), YAML/TOML (by key), JSON, plaintext (by paragraph). Also indexes Godot scene (.tscn), resource (.tres), and project (.godot) files as plaintext.
  • Extra directories — via globalMemoryDir or visibleDirs, scanned even if gitignored.

The index is stored in .search-index/search.db at the project root (add .search-index/ to .gitignore).

License

MIT

版本与发布记录

@dreb/semantic-search 共发布 159 个版本,首次发布于 2026/04/09;过去 12 个月发布了 159 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.83.0latest2026/11/13今天
2.82.02026/11/112 天前
2.81.02026/11/102 天前
2.80.02026/11/103 天前
2.79.12026/11/103 天前
2.79.02026/11/076 天前

关于 @dreb/semantic-search 的常见问题

@dreb/semantic-search 是什么?

Semantic codebase search engine with embedding-based ranking and MCP server

如何安装 @dreb/semantic-search?

在项目目录运行 npm install @dreb/semantic-search,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 semantic-search-mcp,可以用 npx semantic-search-mcp 直接运行。

@dreb/semantic-search 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dreb/semantic-search 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dreb/semantic-search 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^26.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dreb/semantic-search 可以商用吗?

@dreb/semantic-search 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dreb/semantic-search 的下载量有多少?

根据 npm 官方下载统计,@dreb/semantic-search 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,768 次,日均约 126 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dreb/semantic-search 还在维护吗?

最新版本 2.83.0 发布于 2026/11/13(今天);至今共发布 159 个版本,其中过去 12 个月发布了 159 个;首次发布于 2026/04/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。