Skip to content

fix(search): label vector hits and keep overlapping neighbors - #413

Open
ruan-cat wants to merge 4 commits into
AVIDS2:mainfrom
ruan-cat:fix/vector-label-and-neighbor
Open

ruan-cat wants to merge 4 commits into
AVIDS2:mainfrom
ruan-cat:fix/vector-label-and-neighbor

Conversation

@ruan-cat

@ruan-cat ruan-cat commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

审核时先看的边界

这支基于 v1.10.5(96ed8b77,#411)。Lance 合并键仍是 project_id + observation_id。补写、缓存和按项目删除都沿用 1.10.5。这支不恢复 deleteMismatchedProjectRows。

近邻去重用 makeEntryKey(projectId, observationId),不用纯 observation 编号占位。小库融合门槛只属于 #412。这支不改 searchPersistentSemantically 的调用条件。

2026-11-27 第一版把词法补词加到了每一次带项目的检索上,CI 三端各失败 15 条。修复提交是 09af2468。补词现在只发生在 Lance 向量序已经接管结果的时候,补进行还要过项目、可见性、状态和 probe 过滤。修复后的运行 46027621476 七项检查都通过。

前因

向量序已经把一条记忆排进窗口,标题却对不上问话词时,原因列表里没有向量标记,最后被写成 fuzzy。调用方无法区分「向量排上来的」和「只是模糊词法蹭上的」。

另一条是窗口。项目过滤或会话去重会超取再截断。截断前留下的候选不够时,窗口外标题更贴题的卡进不来。memorix memory search 和顶层 search 收下了 --status,没有传给检索,archived 记录在默认的 active 过滤下不可见。

这次改了什么

src/search/match-reasons.ts

  • labelMatchReasons:模式是 vector、vector-only… 或 vector … 时,没有字段贴上问话,原因写 vector,不再只写 fuzzy。已经有 title、entity 等字段命中时,再追加一个 vector。hybrid 且没有字段命中,仍然是 fuzzy。
  • promoteOverlappingNeighbors:第 1 名不动。从第 2 名起到窗口末尾,词重叠更少的位置换成窗口外重叠严格更多的卡。重叠数相同就保持原顺序。只看标题和实体名。
  • queryOverlapTokens:按 Unicode 字母数字切词,中文再切成两字。三对近邻词写在这个文件里:密钥 对应 凭据 / credential / secret,泄露 对应 leak,复盘 对应 收尾。覆盖的是问话和卡片用了不同写法的情况。

src/store/orama-store.ts

  • 项目过滤或会话去重需要超取时,请求条数至少 40。原来是 limit * 3。
  • 只有 lanceOrderUsed 为真,也就是这次结果来自 Lance 向量序时,才再取一轮词法命中,把窗口里还没有的卡补到候选尾部,然后做近邻交换。
  • 补进行必须:项目在本次 projectIds 里;canReadObservation 通过;状态符合本次过滤;caller 没有显式要 probe 时不收 probe;source 与 caller 一致。同一条候选用 makeEntryKey(projectId, observationId) 识别。
  • 词法和 hybrid 不再走这轮补词。它们自己的候选已经在主结果里。再搜一次会把 probe、个人可见性和仓库里的会话重放基线改掉。

src/cli/commands/memory.ts 和 src/cli/index.ts:memory search 和顶层 search 把 --status(active、resolved、archived)传进检索。以前参数被收下后丢掉。

余弦权重不动。窗口宽度仍是调用方的 limit。

第一版为什么被 CI 打回来

第一版的条件是「有查询、有原文、有 projectIds」就补一轮词法。主结果上的可见性、probe 和状态过滤发生在这轮之前,补进来的行没有再走一遍。失败都在本仓库的测试里:

  • tests/memory/probe-observation.test.ts:默认搜索收进了 probe。期望 0,实际 1。
  • tests/cli/identity-command.test.ts:身份清除后,个人记忆仍出现在项目搜索里。期望 0 条,实际 1 条。
  • tests/integration/visibility-boundary.test.ts:第三方搜索能看到只应给发送方和接收方的交接。
  • tests/evaluation/session-replay-evaluation.test.ts:重复率从测试里写死的基线 0.25 变成 0.125。命中率仍是 4/4,但去重考试不再低于基线。
  • tests/search/persistent-semantic-recovery.test.ts:多了一次 searchLexical。期望 2 次,实际 3 次。
  • tests/sdk/memory-client.test.ts:9 条失败是前面的检索把不该看见的记录带进来之后,同一进程里的客户端收尾被带倒。

修复把补词收进向量序,并补上同一套过滤。提交前重跑这 7 个文件,64 条通过。GitHub 运行 46027621476:Ubuntu、macOS、Windows 测试,加上 typecheck、docker、native-sqlite、mcp-registry,七项都成功。

明确不碰

和相邻拉取请求

验收

这些断言都在本仓库的测试里,审核时可以直接打开:

  • tests/search/match-reasons.test.ts 覆盖标记和近邻交换这两个纯函数。
  • 向量序结果里,没有字段贴上问话的命中,原因里有 vector。
  • memorix memory search --status archived 能把 archived 传进检索。
  • tests/memory/probe-observation.test.ts:默认搜索仍排除 probe。
  • tests/cli/identity-command.test.ts:身份清除后,个人记忆不出现在项目搜索里。
  • tests/integration/visibility-boundary.test.ts:定向交接不出现在第三方搜索里。
  • tests/evaluation/session-replay-evaluation.test.ts:重复率基线保持 0.25,去重考试仍低于基线。这是补词不再介入纯词法检索的结果。
  • tests/search/semantic-index.test.ts:同编号两项目的向量行都还在。

ruan-cat and others added 4 commits November 26, 2026 20:06
Vector-mode hits were stored as fuzzy, and a closer title outside the window could not replace a weaker card already inside it. Search now forwards status and keeps enough candidates for that exchange.

Co-authored-by: Cursor <cursoragent@cursor.com>
Assisted-by: Cursor / Grok 4.7
The neighbor pass was skipping candidates by observation number alone. Use the same project-scoped key as the rest of search so one project's row cannot occupy another's slot.

Co-authored-by: Cursor <cursoragent@cursor.com>
The extra lexical pass ran for every project search, so probes, personal memories, and the session-replay baseline changed. Only Lance vector order adds neighbors, and those rows pass the same visibility filters as the main result.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant