Skip to content

fix(search): fuse Lance with FTS for projects under 10000 - #412

Open
ruan-cat wants to merge 2 commits into
AVIDS2:mainfrom
ruan-cat:fix/small-corpus-lance-fallback
Open

ruan-cat wants to merge 2 commits into
AVIDS2:mainfrom
ruan-cat:fix/small-corpus-lance-fallback

Conversation

@ruan-cat

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

Copy link
Copy Markdown
Contributor

审核时先看的边界

这支基于 v1.10.5(96ed8b77,#411)。1.10.5 已经把 Lance 行的身份改成联合键 project_id + observation_id,补写和缓存按 projectId:observationId 判断,按项目删除只带项目条件。deleteMismatchedProjectRows 不在这支里,也不会被加回来。

这支只放宽「小项目能不能走进已有的 searchPersistentSemantically」。融合函数本身仍先看 Lance 的项目,再要求 canonical SQLite 的 projectId 与之相同。对不上的错标行不进排序。

近邻重排、vector 匹配标记、--status 传递在 #413,不在这支。

前因

[retrieval] cjk = "vector" 时,searchLanceInVectorOrder 没有 10000 条门槛。小库上的中文查询可以走出向量序。

10000 挡住的是下一条。近邻返回空之后,融合检索还要过 shouldUsePersistentSearch。默认门槛是 MEMORIX_ORAMA_HYDRATION_THRESHOLD,不设就是 10000。条数低于这条线的项目,融合检索不跑。

回退落到当次 Orama。一次性 CLI 调用 prepareSearchIndex({ skipCachedVectors: true }),Orama 文档的 embedding 是空的。近邻为空时,窗口只剩词法和 fuzzy。正文已经在 SQLite 里,搜索却回不到刚写入的那条。

ascii = "hybrid" 更直接:它不进 searchLanceInVectorOrder。小库同样过不了 10000,Lance 和 FTS 不会融合。

刚写入、Lance 还没 backfill 到的行,近邻路径本来就会空。这不是这支要修的门槛。

这次改了什么

src/store/orama-store.ts 里,10000 继续只决定要不要把全库灌进 Orama。它不再决定「有查询向量时能不能读已有的 Lance」。

查询向量已经算出来,并且 lexicalReady || persistentCorpusEligible 时,调用现有的 searchPersistentSemantically(options, projectIds, ...)。词法索引就绪的小项目因此也能融合。Lance 调用返回 null(表不可用、重建中)时,仍退回现有 Orama。

skipCachedVectors 仍是 true。近邻分数 1 / (1 + 名次) 不动。ascii 的默认值仍是 hybrid,不改成 vector。

新测试是 tests/search/small-corpus-lance-fallback.test.ts。它不靠把 MEMORIX_ORAMA_HYDRATION_THRESHOLD 设成 1 来假装小库。tests/search/orama-store-lexical-fallback.test.ts 和 tests/search/persistent-semantic-recovery.test.ts 里仍有把门槛设成 1 的旧用例,这支没有改那些断言。

明确不碰

和相邻拉取请求

验收

  1. 项目少于 10000 条,cjk = "vector",Lance 近邻有命中:结果仍来自 searchLanceInVectorOrder,模式仍是 vector。
  2. 同一项目,近邻返回空、词法索引里有对得上的行:融合检索仍被调用,不再因为 10000 直接掉进无向量的 Orama。
  3. Lance 抛错或返回 null:退回现有 Orama。
  4. prepareSearchIndex({ skipCachedVectors: true }) 仍在。Orama 批量插入时缓存向量仍是空。
  5. 同编号的两个项目行都还在。按项目删除只影响目标项目。这是 1.10.5 里 tests/search/semantic-index.test.ts 的回归,这支没有放宽它。

提交前在本机跑过 tests/search/semantic-index.test.ts 和 tests/search/small-corpus-lance-fallback.test.ts,8 条通过。GitHub 运行 46025892008 的 7 项检查都成功,含 Ubuntu、Windows、macOS 测试。

ruan-cat and others added 2 commits November 26, 2026 19:13
The hydration threshold was also blocking the fallback after an empty Lance neighbor list, so small projects dropped into an Orama index with no vectors.

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