Skip to content

LSM_VECTOR accepts an all-zero vector and then never returns its record, also under EUCLIDEAN where it is the nearest one, while a vector with NaN or Infinity components is accepted and returned (under DOT_PRODUCT ahead of every finite record) #8962

Closed

Description

@tae898

put() checks only the length of a vector (LSMVectorIndex.java#L8389), so an all-zero vector is stored without an error, but every read path then drops it as unscorable (ArcadePageVectorValues.java#L311, and the comment at LSMVectorIndex.java#L5991: "an all-zero one, is not something this index can score against"). That holds for COSINE, where the similarity of a zero vector is undefined, but the rule is applied to EUCLIDEAN too, where the origin has a well-defined distance: in the repro the record at [0, 0] is the nearest one to [0.01, 0.01] and is missing from a k = 10 answer over 5 records, with nothing logged about it at insert or at the graph build (which logs Building graph with 4 vectors for the 5 records). The search instead logs Graph search returned only 3 results (expected 4, available 4) ... falling back to brute-force scan (graph may need rebuilding) at WARNING.

The opposite holds for non-finite components: a vector with a NaN or an Infinity is accepted, indexed, and returned, with a distance of NaN, -Infinity, or 3.4028235E38. Under DOT_PRODUCT the [Infinity, 1] record is the first hit, at -Infinity; its dot product with any query whose first component is positive is +Infinity, so it comes first for every such query.

Repro

javac -cp 'lib/*' -d cls ZeroVectorNeverReturned.java
java -Xmx8g -XX:+UseCompactObjectHeaders --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp 'lib/*:cls' ZeroVectorNeverReturned /tmp/zero-db

lib/ holds the engine jar and its dependencies. On Temurin 21 the same command without -XX:+UseCompactObjectHeaders.

import com.arcadedb.database.*;
import com.arcadedb.query.sql.executor.*;
import java.util.*;

public class ZeroVectorNeverReturned {
  public static void main(String[] args) {
    DatabaseFactory factory = new DatabaseFactory(args[0]);
    if (factory.exists())
      factory.open().drop();
    Database db = factory.create();
    for (String similarity : List.of("EUCLIDEAN", "DOT_PRODUCT", "COSINE")) {
      String type = "P" + similarity.charAt(0);
      db.command("sql", "CREATE DOCUMENT TYPE " + type);
      db.command("sql", "CREATE PROPERTY " + type + ".name STRING");
      db.command("sql", "CREATE PROPERTY " + type + ".vector ARRAY_OF_FLOATS");
      db.command("sql", "CREATE INDEX ON " + type + " (vector) LSM_VECTOR METADATA { \"dimensions\": 2, \"similarity\": \"" + similarity + "\" }");
      db.transaction(() -> {
        db.newDocument(type).set("name", "origin", "vector", new float[] { 0f, 0f }).save();
        db.newDocument(type).set("name", "near", "vector", new float[] { 0.1f, 0.1f }).save();
        db.newDocument(type).set("name", "far", "vector", new float[] { 3f, 4f }).save();
        db.newDocument(type).set("name", "nan", "vector", new float[] { Float.NaN, 1f }).save();
        db.newDocument(type).set("name", "inf", "vector", new float[] { Float.POSITIVE_INFINITY, 1f }).save();
      });
      float[] query = { 0.01f, 0.01f };
      List<String> hits = new ArrayList<>();
      ResultSet rs = db.query("sql", "SELECT name, distance FROM (SELECT expand(vectorNeighbors('" + type + "[vector]', ?, 10)))", query);
      while (rs.hasNext()) {
        Result r = rs.next();
        hits.add(r.getProperty("name") + " " + r.getProperty("distance"));
      }
      System.out.println(similarity + ", 5 records, k = 10, query [0.01, 0.01]: " + hits);
    }
    db.close();
  }
}

Output on main at bda510bca0, embedded, identical on Temurin 25 (with compact object headers) and Temurin 21:

EUCLIDEAN, 5 records, k = 10, query [0.01, 0.01]: [near 0.016199946, far 24.860199, inf 3.4028235E38, nan 3.4028235E38]
DOT_PRODUCT, 5 records, k = 10, query [0.01, 0.01]: [inf -Infinity, far -0.535, near -0.501, nan NaN]
COSINE, 5 records, k = 10, query [0.01, 0.01]: [near 0.0, far 0.010050535, inf NaN, nan NaN]

Versions affected: main 417314c18 (2026-09-17) and 26.9.1 print the same three lines.

Also on main at 9319980f60 (2026-10-02, after #8947): the same output on Temurin 25 and Temurin 21.

Expected: under EUCLIDEAN, origin is the first hit (squared distance 0.0002), ahead of near. Whatever the rule for zero vectors under COSINE (and DOT_PRODUCT, which requires unit vectors), a vector the index will never return would better be rejected at put() with an error, as a wrong dimension is, rather than stored and silently left out of every answer; the same check could reject NaN and Infinity components, which no similarity can rank.

Activity

  1. added
    severity:minor
    vector
    on Oct 2, 2026
  2. self-assigned this
    on Oct 2, 2026
  3. added
    in progress
    on Oct 2, 2026
  4. added this to the 26.10.1 milestone on Oct 2, 2026
  5. added a commit that references this issue on Oct 2, 2026
  6. lvca commented on Oct 2, 2026

    @lvca
    Member

    Confirmed and fixed in #8969 (26.10.1). A vector with a NaN or Infinity component is now rejected with an IllegalArgumentException on insert, and so is a NaN or Infinity query vector. Under EUCLIDEAN an all-zero vector is now indexed and returned (the origin is a valid point). Under COSINE and DOT_PRODUCT zero vectors are still accepted but not returned, since inserting a zero placeholder and updating it later is a common pattern and their similarity is undefined.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Oct 2, 2026
  8. tae898 commented on Oct 3, 2026

    @tae898
    ContributorAuthor

    Verified on main at 66541f57d9 (which carries the #8969 merge a556c94456 and the #8971 merge 66541f57d9) against bda510bca0, the build this was filed on, with the issue's reproduction, on Temurin 25 with -XX:+UseCompactObjectHeaders and on Temurin 21, same results on both. The filed program now stops at its NaN insert, which is the fix, so I ran it with the three finite records in one transaction and the NaN and Infinity vectors each tried in its own:

    query [0.01, 0.01], k = 10 bda510bca0 66541f57d9
    EUCLIDEAN [near, far, inf, nan] (origin missing) [origin 0.0002, near, far]
    DOT_PRODUCT [inf -Infinity, far, near, nan] [far, near]
    COSINE [near, far, inf, nan] [near, far]
    inserting [NaN, 1] / [Infinity, 1] accepted IllegalArgumentException: Vector components must be finite numbers

    Under DOT_PRODUCT and COSINE the zero vector is accepted and not returned, as you describe for the placeholder pattern. The Python bindings suite is green on a wheel built with that engine. Thanks!

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

Metadata

Metadata

Assignees

Labels

bugseverity:minorvector

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions