Skip to content

[Bug] HNSW index omits rows inserted after index creation #25610

Closed

Description

@Ariznawlll

Summary

After an HNSW index is created, MatrixOne accepts a subsequent INSERT into the indexed table but the vector KNN query does not include the new row. The index becomes stale while the base table remains writable, so a query can return fewer rows than the table contains.

Reproduction

At commit 7821d21c723372e45a8f65da3bbb896a157b1036, through proxy 6001:

CREATE DATABASE hnsw_repro;
USE hnsw_repro;
SET experimental_hnsw_index = 1;
CREATE TABLE t(a BIGINT PRIMARY KEY, v VECF32(3));
INSERT INTO t VALUES
  (1,'[1,1,1]'),(2,'[2,2,2]'),(3,'[3,3,3]'),(4,'[8,8,8]');
CREATE INDEX idx USING HNSW ON t(v)
  OP_TYPE 'vector_l2_ops' M=4 EF_CONSTRUCTION=64 EF_SEARCH=32;
INSERT INTO t VALUES (5,'[1.01,1.01,1.01]');
SELECT a, L2_DISTANCE(v,'[1,1,1]') AS d
FROM t ORDER BY L2_DISTANCE(v,'[1,1,1]') ASC LIMIT 5;
SELECT COUNT(*) FROM t;

Observed KNN output contains only ids 1,2,3,4, while COUNT(*) is 5; the newly inserted nearest row 5 is absent. The same HNSW table accepts UPDATE/DELETE as well, so this is silent index/data divergence rather than a rejected unsupported write.

Expected

Either keep the HNSW index synchronized for accepted INSERT/UPDATE/DELETE operations, or reject writes to an HNSW-indexed column/table with a clear error and documented rebuild workflow. KNN results must not silently omit committed rows.

References

Activity

  1. added this to the MO-202607 milestone on Jul 11, 2026
  2. added
    kind/bug
    on Jul 11, 2026
  3. added theissue type on Jul 11, 2026
  4. Ariznawlll commented on Jul 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    Revalidated against commit 7821d21c723372e45a8f65da3bbb896a157b1036. HNSW is intentionally AlwaysAsync through ISCP CDC. The inserted row is absent immediately after INSERT, but the same KNN query includes it after the CDC catches up (about 5 seconds in the local CN/DN/logservice/proxy cluster). The repository's vector_hnsw_async.sql and vector_hnsw_modern_dml.sql also treat HNSW DML/index maintenance as asynchronous. This is an expected consistency window rather than a permanent omission, so closing this issue; the async visibility contract should still be made clearer in the user-facing docs.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions