Skip to content

vector.* sparse/ANN: sparseDot rejects unequal inferred dims, sparseCreate rejects long[], neighbors lacks a k<=0 guard #6391

Closed

Description

@ruispereira

Summary

Three vector.* sparse/ANN functions throw raw exceptions (or impose an unnecessary restriction) on valid input, inconsistent with their own siblings.

Findings (all HEAD ca89f56)

  1. vector.sparseDot requires equal inferred dimensions — engine/src/main/java/com/arcadedb/function/sql/vector/SparseVector.java L142-144:
    public float dotProduct(final SparseVector other) {
      if (this.dimensions != other.dimensions)
        throw new IllegalArgumentException("Vector dimensions must match: " + this.dimensions + " vs " + other.dimensions);
    Dimensions are inferred from the max index, but a dot product only needs the common indices (it is 0 over non-overlapping ones). SELECT vector.sparseDot(vector.sparseCreate([0,2],[0.5,0.3]), vector.sparseCreate([1,5],[0.2,0.8])) → dims 3 vs 6 → throws, when the answer is 0.0. Fix: drop the equality requirement (design bug).
  2. vector.sparseCreate rejects long[] indices — engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorSparseCreate.java L81-108 has a private toIntArray that handles only int[] and Object[]; a long[] (how integer JSON arrays arrive from HTTP) matches neither and hits the throw new CommandSQLParsingException("Index values must be integers, found: long[]"). The shared VectorUtils.toIntArray already handles long[] (issue Bug: HTTP parameter binding loses int64 precision for ARRAY_OF_LONGS (distinct values can collapse onto the same output) #4148); this private copy shadows it. Fix: delegate to VectorUtils.toIntArray.
  3. vector.neighbors lacks a k <= 0 guard — engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorNeighbors.java reads limit (L83) with no <= 0 check; a negative k reaches new ArrayList<>(k) in LSMVectorIndex (sinks at L4115/4201/4619/4667; the L4358 comment itself notes a negative capacity "kills the search with an Illegal Capacity that names neither") → IllegalArgumentException. The siblings rerank/recommend/discover/sparseNeighbors all return empty on k <= 0. SELECT vector.neighbors('Doc[embedding]', :q, -1). Fix: return empty (or a typed error) on k <= 0, matching the siblings.

Scope / confidence

High confidence on #1 and #2 (read at HEAD). Medium on #3 (the missing guard and the new ArrayList<>(k) sink are both present; the exact reachable sink depends on the code path). Each has a sibling that behaves correctly, so the intended behavior is established.

Activity

  1. added this to the 26.9.1 milestone on Aug 18, 2026
  2. self-assigned this
    on Aug 19, 2026
  3. added theissue type on Aug 19, 2026
  4. added
    in progress
    on Aug 19, 2026
  5. added a commit that references this issue on Aug 19, 2026
  6. lvca commented on Aug 19, 2026

    @lvca
    Member

    Fixed in #6451 (merged).

  7. removed
    in progress
    on Aug 19, 2026
  8. added
    engine
    vector
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginevector

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions