Skip to content

HNSW index returns only 1 result regardless of LIMIT on small tables (<100 rows) #171

@stuinfla

Description

@stuinfla

Description

HNSW index scan returns only 1 result regardless of the LIMIT clause on tables with fewer than ~100 rows. Sequential scan on the same data returns the correct number of results.

Environment

  • Extension: ruvector v0.1.0 (engine v2.0.1)
  • Docker image: ruvnet/ruvector-postgres:latest (built 2026-02-13)
  • Platform: macOS Darwin 25.3.0, Docker Desktop
  • SIMD: x86_64 AVX2 + FMA + SSE4.2

Reproduction

-- Table: 56 rows, all with ruvector(384) embeddings
-- Column type: ruvector(384) (atttypmod correctly set)
-- Index: USING hnsw (embedding ruvector_cosine_ops) WITH (m=16, ef_construction=128)

-- WITH HNSW index: Returns 1 row (wrong)
SET ruvector.ef_search = 64;
SELECT title, category
FROM openclaw_memory.operational_knowledge
ORDER BY embedding <=> embed_text('What projects does Stuart work on?')
LIMIT 8;
-- Returns: 1 row

-- WITHOUT HNSW index (sequential scan): Returns 8 rows (correct)
DROP INDEX idx_opknowledge_embedding_hnsw;
SELECT title, category
FROM openclaw_memory.operational_knowledge
ORDER BY embedding <=> embed_text('What projects does Stuart work on?')
LIMIT 8;
-- Returns: 8 correct rows, properly ranked by relevance

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions