Skip to content

[Feature Request]: WAND-based retrieval index — BM25 top-K retrieval without full-scan #25541

Closed

Description

@cpegeric

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

WAND — the algorithm

WAND = Weak AND (a.k.a. Weighted AND). It's a document-at-a-time (DAAT) top-K retrieval algorithm — the standard fast way to answer "give me the K highest-BM25-scoring documents for this multi-term query" without scoring every matching document. Introduced by Broder et al. (2003); the Block-Max WAND (BMW) refinement is Ding & Suel (2011). It is what the retrieval fulltext index uses.

The problem it solves

A query like MATCH(txt) AGAINST('red apple banana') is an OR over terms: a document matches if it contains any term, and its rank is score(d) = Σ_t score(t, d) (BM25 per term). The naive plan scores every document containing any query term, then sorts and takes the top-K. On a large corpus with common terms, that scores most of the collection — and you only wanted K rows. WAND skips the documents that provably cannot enter the top-K.

The core idea: a threshold + upper bounds

Two ingredients:

  1. A running threshold θ = the K-th best score seen so far (the smallest score currently in a size-K min-heap). A document can only matter if its score can beat θ.

  2. A per-term score upper bound UB(t) = the maximum score term t can contribute to any document (precomputed from its posting list — for BM25, roughly idf(t) × max-tf-component). Then for any document d:

    score(d) ≤ Σ_{t ∈ query, t ∈ d} UB(t)
    

If that upper bound < θ, the document cannot reach the top-K → skip it, never score it.

The mechanism: pivoting over sorted cursors

Each query term keeps a cursor over its posting list (posting lists are sorted by doc id). One DAAT step:

  1. Sort the cursors by their current doc id (ascending).
  2. Find the pivot. Walk the cursors in doc-id order, accumulating UB(t). The first term at which the running sum exceeds θ is the pivot term; its current doc id is the pivot doc — the smallest doc id whose upper bound could possibly beat θ (everything before it has too few high-value terms).
  3. Act on the pivot:
    • If every cursor before the pivot is already at the pivot doc → all those terms are present in the pivot doc → fully score it; if its real score > θ, push it into the heap and raise θ.
    • Otherwise → the lagging cursors are on smaller doc ids that cannot win, so advance them forward to (at least) the pivot doc — jumping over a whole run of hopeless documents.

As the heap fills, θ rises monotonically, which makes the upper-bound test stricter, which makes the pivot jumps larger — the search accelerates as it goes. Only the documents that could plausibly enter the top-K are ever fully scored.

Block-Max WAND (the refinement in use)

A single global UB(t) is loose — one outlier posting inflates it everywhere. BMW divides each posting list into blocks and stores a max score per block. The pivot test then uses the block-local max for each cursor's current region, giving a much tighter upper bound → more aggressive skipping, and it can skip whole blocks at once. (In the index, this is the per-block metadata finalizeScoring computes alongside the postings.)

Why it is both fast and correct

  • Exact, not approximate. WAND/BMW only skips a document when its upper bound is below θ. Since the upper bound ≥ the true score, a skipped document truly could not have entered the top-K — the returned top-K is identical to the exhaustive-scoring result. (This is why the gold correctness test diff-checks WAND's top-K against a brute-force Σ tf·idf² reference.)
  • Fast because it evaluates a small fraction of the OR-matching documents — the win grows with corpus size and with how selective K is.

How it maps to the MO retrieval index

  • Storage = the postings (docID, tf) per term + docmap (pk, doc length) + per-block max scores, serialized into the tag=0 base sub-indexes (and tag=1 tail deltas). BM25 needs corpus stats N (doc count) and avgdl (average doc length), precomputed at load.
  • Query = the pushed-down top-K (LIMIT k → heap size K), an optional membership bitmap (the WHERE prefilter, AND-ed into the walk so filtered-out docs are skipped like non-matches), and the multi-segment liveness bitmap (deletes/updates). The engine runs the BMW walk over the live, filtered postings and returns the exact BM25 top-K directly — no SQL SORT node.

In one line

WAND is a safe top-K pruning strategy — keep a threshold of the current K-th best score, bound each candidate by the sum of its terms' max possible contributions, and skip every document whose bound cannot beat the threshold — so you score only the handful of documents that could actually win.

References

  • A. Z. Broder, D. Carmel, M. Herscovici, A. Soffer, J. Zien. Efficient Query Evaluation using a Two-Level Retrieval Process. CIKM 2003. (original WAND)
  • S. Ding, T. Suel. Faster Top-k Document Retrieval Using Block-Max Indexes. SIGIR 2011. (Block-Max WAND)

Describe the feature you'd like

Describe implementation you've considered

No response

Documentation, Adoption, Use Case, Migration Strategy

Additional information

No response

Activity

  1. changed the title [-][Feature Request]: WAND-based retrieval fulltext index — BM25 top-K retrieval without full-scan + SORT[/-] [+][Feature Request]: WAND-based retrieval index — BM25 top-K retrieval without full-scan[/+] on Jul 10, 2026
  2. added
    severity/s0
    on Jul 17, 2026
  3. cpegeric commented on Aug 17, 2026

    @cpegeric
    ContributorAuthor

    please verify

  4. XuPeng-SH commented on Aug 22, 2026

    @XuPeng-SH
    Contributor

    @cpegeric Please pass these issues to QA for testing going forward.

  5. VioletQwQ-0 commented on Aug 27, 2026

    @VioletQwQ-0
    Collaborator

    更正(2026-09-24):此评论为历史记录,原 freetier-01 / 两小时运行门槛不适用于本次 main WAND 验收。请以最新转测说明为准。


    自动化 QA handoff:PR #27663 已合并。

    • 合并信息:PR exact head 325686d29c17b3729f32b837b5bc2144d33f0a9b,merge commit 03ffd507597ded14abbce44c31616e5979463096,合并时间 2026-08-27T05:34:32Z。
    • 当前 main head:b0ae66c04d9a67175d2dfb8bf1c777fb888e1430。
    • 自动化证据:exact head 的 MatrixOne CI 中 shared build、Ubuntu UT、SCA、Compose/Standalone BVT、coverage 与校验任务通过;TKE 的镜像构建任务失败,原因为访问 registry-1.docker.io 的 BuildKit manifest 返回 EOF,因此后续 TKE 环境测试未开始,不能据此宣称产品验收通过。
    • 剩余场景:使用官方 immutable image/release 完成环境升级;通过 reviewed GitOps PR 升级 freetier-01;先执行唯一数据库、小语料、15 分钟 FULLTEXT2 shakeout,再由完整观测解锁低负载两小时 continuous run。
    • 预期结果:正确性 ledger 无错误,读写无 backlog,观测完整;任一错误、积压、环境不稳定或观测缺失均记为 FAIL,并保持 issue open。
    • tester 选择依据:选择 tester Ariznawlll。
      Issue 已保持 OPEN,并添加 phase/testing;请 QA 完成上述门禁后明确回复 PASS 或 FAIL。
  6. 7 remaining items

  7. slyunnn commented on Sep 28, 2026

    @slyunnn

    WAND QA acceptance run (attempt 1)

    Results:

    • INCONCLUSIVE — fixed-commit WAND mechanism gate did not reach the assertions. Its native dependency build failed because CC=clang was configured but clang was unavailable on the runner, so the required WAND/block-max evidence was not produced.
    • NOT_RUN — the real TKE SQL, update/delete/insert, two-CN, and CN-reload phase was gated by the mechanism failure and was not started.
    • INCONCLUSIVE — cleanup collected no complete CBS ownership ledger: it expected three run-owned LogService disk identities but none were available. The test namespace was absent, but this alone is not sufficient evidence to mark storage cleanup complete.

    Final acceptance result: INCONCLUSIVE. This run is an execution/control-environment blocker, not evidence of a WAND product failure or a pass. The issue remains in testing; after the runner toolchain and cleanup-evidence gate are corrected, rerun the same pinned workflow and record the three phase results before making a final conclusion.

  8. VioletQwQ-0 commented on Sep 28, 2026

    @VioletQwQ-0
    Collaborator

    更新(2026-09-29):本评论的控制 head e2be0625... 已过期。第二次 QA 运行仍为 INCONCLUSIVE;请以最新跟进为准。新 head 0e1cecabc12ac5a9b82973d4e8304ee95a576bab 已修补镜像身份采集,缺少 CBS 核验凭据时请勿触发 TKE 运行。


    @slyunnn 已处理 QA 第 1 次运行 的验收包问题。该次运行的结论保持 INCONCLUSIVE:机制 job 因 runner 没有配置的 clang 而未到达 WAND 断言;真实 TKE SQL / 增删改 / CN 重载为 NOT_RUN;清理 job 在从未部署的情况下仍要求三块 CBS 磁盘清单。本次没有 WAND 产品 PASS 或 FAIL 证据。

    修复已推到验收包 PR #1738,新的控制 head 为 e2be06253ec3b8dc8fc33560b5933a751de75313:

    • 机制 job 选择 runner 上可用的 GCC 并归档编译器版本,移除不可用的 clang 硬编码。
    • 只有 TKE job 被跳过且本次无 PV 时,清理才允许空 CBS 清单;仍独立核对 namespace、PV、COS。只要 TKE job 实际运行,仍要求至少三块 run-owned CBS DiskId 和云 API 删除证据,缺失则不能判清理通过。
    • 本地 19 项验收包测试、修改过的 workflow 的 actionlint、workflow graph 和 control contracts 通过;新 head 的 Linux contracts 与 validate 均通过。新 head 尚无 TKE 运行,Linux 机制测试仍需本次重跑验证。

    请从 codex/issue25541-wand-qa 再次单独触发 Test_list=fulltext2_wand_qa,仍使用 Repo=matrixorigin/matrixone、Branch=main、Commit_Id=95b1d2bfd9d756d08320569858080cb16f230fff。运行后先核对 Actions headSha 为上述新控制 SHA,再检查机制、SQL/CN 重载、清理三组 artifacts 并回填逐项结果。此前转测评论中的控制 SHA e00074d... 是第 1 次运行的历史版本,请勿用于下一次验收。

    Issue 继续保持 OPEN / phase/testing,待 QA 给出固定版本和环境上的实际终态结果。

  9. slyunnn commented on Sep 29, 2026

    @slyunnn

    @VioletQwQ-0

    WAND QA acceptance run (attempt 1, rerun)

    Results after inspecting wand-qa-mechanism-*, wand-qa-tke-*, wand-qa-cleanup-*, and the final summary artifact:

    • PASS — the fixed-commit mechanism phase selected GCC 13.3.0; the tokenizer fixture, WAND/Block-Max observations for build and loaded paths, independent PK/score oracle, tie oracle, and tail-liveness passed. The forced full-evaluator negative control failed as intended.
    • INCONCLUSIVE — TKE created the isolated namespace and reached eight Ready pods, but identity verification stopped at official image mismatch in nightly-regression-dis-dn-0. The artifact does not retain the observed Pod imageID or /mo-service -version before the assertion, so the required runtime identity cannot be independently established. SQL, update/delete/insert, direct-CN, and CN-reload checks were therefore not run.
    • INCONCLUSIVE — the exact-owner finalizer removed the namespace and MatrixOneCluster, and captured six run-owned PV identities; however, the independent CBS deletion verification could not run because the cloud CBS credential required by that check was unavailable. Storage cleanup is not accepted as complete without that evidence.

    The wrapper summary reports mechanism=PASS, tke=FAIL, cleanup=INCONCLUSIVE, and overall=FAIL. Per the acceptance classification, this is not a WAND SQL/product FAIL: the TKE identity evidence is insufficient and the SQL/CN-reload phase is NOT_RUN. Final QA conclusion: INCONCLUSIVE.

    Follow-up required before another acceptance run: make the deployment consume the pinned amd64 image digest (rather than relying on a mutable tag with IfNotPresent), record the expected and observed Pod image IDs plus binary version before any identity assertion, and provide the CBS verification credential or an approved equivalent independent deletion proof. Keep the issue OPEN / phase/testing.

  10. VioletQwQ-0 commented on Sep 29, 2026

    @VioletQwQ-0
    Collaborator

    @slyunnn 已检查本次 QA rerun 36403896142 的 artifacts,接受本次结论 INCONCLUSIVE。固定版本的 Linux WAND / Block-Max 机制证据为 PASS;TKE 虽达到八个 Ready Pod,但身份检查未保存实际 imageID / 二进制版本便中止,SQL、增删改和 CN 重载均为 NOT_RUN。Namespace / MatrixOneCluster 已由 finalizer 删除,但缺少 CBS 云 API 的独立删除证明,不能判清理完成。这不是 WAND SQL 产品 FAIL,也不是验收 PASS。

    验收包 Draft PR #1738 已更新至控制 head 0e1cecabc12ac5a9b82973d4e8304ee95a576bab:四类 MO 组件及 init 容器固定使用官方 amd64 digest,拉取策略为 Always;身份断言前归档每个 Pod 的预期/实际 imageID 和 /mo-service -version;缺少 CBS 核验凭据时,在创建集群前停止并记为 BLOCKED_ENVIRONMENT。本地 21 项测试、actionlint、workflow graph / contracts 和 diff 检查通过;新 head 的 PR CI 仍在运行。此修补尚无新的 TKE SQL / CN 重载结果。

    下一次 QA 运行的前提是由仓库/环境管理员安全配置 TKE_SECRET_ID、TKE_SECRET_KEY,并确保具备 CBS DescribeDisks 权限,或先落实经 QA 认可的等价独立删除证明。现在请勿盲目重跑:当前缺凭据时新流程会在部署前阻断。凭据就绪后仍按原固定 MatrixOne commit 95b1d2bfd9d756d08320569858080cb16f230fff 和 Test_list=fulltext2_wand_qa 触发,并核对控制 head 与三组 artifacts。Issue 保持 OPEN / phase/testing,等待正式 SQL、索引更新、重载与清理证据。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/featurephase/testingseverity/s0

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions