npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mem0-hybrid-search

v0.2.0

Published

中文记忆混合检索增强层:CJK bigram 中文分块 + 加权 RRF 融合 + MMR 去重 + 时间衰减。零依赖、纯函数,可插到任何本地记忆库(mem0 / opencode-mem0 / SQLite + 向量)之上。附带标准 MCP 记忆服务接线说明(memory_search/sync/stats)。

Readme

mem0-hybrid-search

中文记忆混合检索增强层:CJK bigram 中文分块 + 加权 RRF 融合 + MMR 去重 + 时间衰减。

零依赖、纯函数,可插到任何纯向量检索的记忆库(mem0 / opencode-mem0 / SQLite+向量)之上,专治中文检索「记得住但搜不出」——人名、编号、短词。

English README · npm · MIT

为什么需要它

纯向量检索对中文有三个盲区:

| 查询 | 纯向量 | 本包 | |:-----|:------:|:----:| | 林小满(人名) | ❌ 搜不到 | ✅ bigram 拆成 林小/小满 命中 | | 4747(纯数字/编号) | ❌ 搜不到 | ✅ FTS 通道分词命中 | | 库存对不上(口语) | ⚠️ 语义漂移 | ✅ FTS 关键词 + bigram 双精确通道 |

架构

① FTS5 trigram 关键词检索 → 精确匹配
② 向量余弦相似度检索   → 语义匹配(可选,无向量自动降级)
③ CJK bigram 中文分块  → 中文场景补盲(人名/编号/短词)
        ↓
加权 RRF 融合(精确通道 ×2,修等权稀释 bug)
        ↓
MMR 去重 + 时间衰减 + 阈值过滤 + 归一化

安装

npm install mem0-hybrid-search

用法

const { hybridFuse, extractCjkBigrams } = require("mem0-hybrid-search");

// 1. 三路候选(来自你自己的检索:FTS / 向量 / bigram)
const candidates = [
  [{ id: "a", score: 0.9 }, { id: "b", score: 0.7 }],  // FTS 通道
  [{ id: "b", score: 0.8 }, { id: "c", score: 0.6 }],  // 向量通道
  [{ id: "a", score: 0.5 }],                            // bigram 通道
];

// 2. 每条候选的元数据(供时间衰减 & MMR)
const meta = {
  a: { createdAt: Date.now() - 86400000,     vector: [0.1, 0.2] },
  b: { createdAt: Date.now() - 86400000 * 7, vector: [0.3, 0.1] },
  c: { createdAt: Date.now(),                vector: [0.2, 0.2] },
};

// 3. 融合排序
const hits = hybridFuse(candidates, { maxResults: 3 }, meta);

// 4. 单独用 CJK bigram 提取
const bigrams = extractCjkBigrams("林小满"); // → ["林小", "小满"]

API

| 函数 | 说明 | |:-----|:-----| | hybridFuse(candidates, opts, meta) | 六步流水线:RRF → MMR → 时间衰减 → 阈值 → 归一化 | | rrfFuse(lists, k, weights) | 加权 Reciprocal Rank Fusion | | mmrRerank(candidates, getEmbedding, lambda, topK) | MMR 多样性重排 | | applyRecencyDecay(candidates, halfLifeDays) | 指数时间衰减(半衰期 14 天) | | extractCjkBigrams(query) | CJK 2 字滑窗提取(含 CJK 扩展区) |

与 mem0 官方的关系

  • RRF / FTS5 / 向量融合:行业已有方案,mem0 官方同样提供混合检索。本包的融合框架与之同源。
  • 本包增量价值:① CJK bigram 中文分块通道(专治中文人名/编号盲区)② 精确通道 2x 加权(修等权稀释 bug:25 条向量噪声淹没 2 条精确命中)。这两点是纯中文场景的补课,独立于任何记忆库。

MCP 集成

同一引擎已封装为标准 MCP(Model Context Protocol)记忆服务——一套代码,任何支持 MCP 的客户端通用(opencode / DeepSeek Harness / Claude Desktop / Cursor):

{
  "mcp": {
    "mem0-hybrid-search": {
      "type": "local",
      "command": ["node", "/path/to/mem0-hybrid-search/mcp-server.js"],
      "environment": {}
    }
  }
}

工具:memory_search(混合检索)、memory_sync(增量同步索引)、memory_stats(索引状态)。数据不出本地——索引库与 mem0 分片库只在本机读写。

完整 sidecar(引擎 + MCP server + opencode 插件)位于 ~/.config/opencode/plugins/mem0-hybrid-search/。本 npm 包发布纯算法层。

测试

npm test

12 项断言:bigram 提取 / 加权 RRF vs 等权 RRF 对照 / 全流水线 / 时间衰减 / MMR。

License

MIT