SuperAPI AI 工具集

vector-search

数据与分析

查看项目

更新于 10-15 15:44

技能介绍

Vector Search

该插件包含两条不同的向量检索路径,需按需选择,二者不可互换。

路径 工具族 后端 容量 延迟

大规模语料 embeddings_* @claude-flow/memory HNSW(Rust/Native) 最多数百万向量 N=20k 时约 1.9 倍,N=5k 时约 3.2–4.7 倍于暴力检索(实测;recall@10 ≈ 0.99)。超过交叉点后 ANN 占优

热路径路由器 ruvllm_hnsw_* WASM 后端路由器(v2.0.1) 最多约 11 个模式(ruvllm-tools.ts:58) 亚毫秒级;面向高优先级路由,而非语料检索

“12,500×”这一数字适用于大规模 embeddings_search 路径。WASM 路由器不属于该路径。

适用场景

需求 路径

检索 N ≥ 500 篇文档的语料 embeddings_search

内存受限的语料(≥5,000 向量) RaBitQ 量化——见下文“量化检索”

比较两个字符串 embeddings_compare

层级/分类数据 embeddings_hyperbolic(Poincaré ball)

将查询路由到 ≤11 个热模式之一 ruvllm_hnsw_route

跨命名空间检索 memory_search_unified

标准检索

检查状态——mcp__plugin_ruflo-core_ruflo__embeddings_status 用于验证嵌入引擎。

初始化——若未启用,使用 mcp__plugin_ruflo-core_ruflo__embeddings_init。

生成——mcp__plugin_ruflo-core_ruflo__embeddings_generate 用于文本输入。

检索——mcp__plugin_ruflo-core_ruflo__embeddings_search 配合查询。

比较——mcp__plugin_ruflo-core_ruflo__embeddings_compare 用于度量相似度。

统一检索——mcp__plugin_ruflo-core_ruflo__memory_search_unified 用于跨命名空间。

量化检索(32 倍内存缩减)

对于 ≥5,000 向量的语料,和/或内存受限环境,使用 RaBitQ 1-bit 量化工作流。低于 5,000 向量时,重建成本超过节省,应改用标准路径。

步骤 工具 用途

1 embeddings_init 引擎预热

2 embeddings_rabitq_build 语料加载完成后一次性构建 1-bit 索引

3 embeddings_rabitq_search Hamming 预过滤返回 top-N 候选 ID(开销低)

4 embeddings_search 可选的候选集精确重排(全精度)

5 embeddings_rabitq_status 索引健康、内存占用、构建时间

注意:embeddings_rabitq_search 仅返回候选 ID——第 4 步的重排由用户负责(与 embeddings-tools.ts:911 的 docstring 一致)。不重排则结果为近似;重排后可获得全精度质量且内存降低 32 倍。

调优

HNSW 暴露三个在召回率与延迟间权衡的参数。“12,500×”这一数字假设使用默认值;请根据工作负载审慎调优:

配置 多 efSearch M 适用场景

召回优先 200 32 规划阶段的模式召回;质量比毫秒更重要

均衡(默认) 64 16 通用语义召回

延迟优先 16 8 p99 延迟敏感的热路径路由

efSearch 通过 ruvllm_hnsw_create 传入(ruvllm-tools.ts:64)。M 目前为注册表级别;若需 MCP 可调,可作为后续改进提升。efConstruction 在 lite 索引中默认 200(hnsw-index.ts:537)。

HNSW 模式路由器(WASM,≤11 个模式)

用于将少量高优先级模式进行路由:

mcp__plugin_ruflo-core_ruflo__ruvllm_hnsw_create——创建 WASM 索引(上限约 11)

mcp__plugin_ruflo-core_ruflo__ruvllm_hnsw_add——添加一个模式

mcp__plugin_ruflo-core_ruflo__ruvllm_hnsw_route——路由传入查询

这不是语料索引。应将其视为对一组精选模式进行快速分类的组件。

双曲嵌入

对于层级数据(代码树、组织图),使用 mcp__plugin_ruflo-core_ruflo__embeddings_hyperbolic,它映射到 Poincaré ball 空间。距离为测地距离,而非余弦距离。

CLI 替代方式

npx @claude-flow/cli@latest embeddings search --query "authentication patterns" npx @claude-flow/cli@latest embeddings init npx @claude-flow/cli@latest memory search --query "your query"

性能

实测数字(来源:scripts/benchmark-intelligence.mjs,ruvector NAPI 后端;recall@10 ≈ 0.99)。较早的“150×–12,500×”数字是暴力回退产生的伪影,已废弃——见项目 CLAUDE.md “V3 Performance Targets”。

方法 相对暴力检索的实测加速

暴力扫描 基线

HNSW(N=5,000) 约 3.2–4.7 倍更快

HNSW(N=20,000) 约 1.9 倍更快

HNSW(低于交叉点,小 N) 与暴力检索持平/更慢

RaBitQ 量化 32 倍内存缩减;N≈14.7k 时 0.60 ms/query

ruvllm_hnsw_route(n≤11) 每次路由亚毫秒,固定开销