Skip to content

Conversation

@Maxxen
Copy link
Member

@Maxxen Maxxen commented Sep 23, 2024

This PR adds an optimizer rule to use the HNSW index to accelerate lateral vss joins, e.g.

CREATE TABLE a (a_vec FLOAT[3], a_id INT);
CREATE TABLE b (b_vec FLOAT[3], b_str VARCHAR);

SELECT * FROM a, LATERAL (
  SELECT * FROM b ORDER BY array_distance(a.a_vec, b.b_vec) LIMIT 3
);

This enables "batch" index lookups by matching against a column of vectors instead of passing a single constant array value.

The optimization will apply for any constant value of k (e.g. what gets passed to inner LIMIT clause) up to DuckDB's STANDARD_VECTOR_SIZE (= 2048 by default).

@Maxxen Maxxen changed the title Optimize vss_join if the left hand side is a table with a HNSW index. Optimize lateral VSS joins using HNSW index Sep 26, 2024
@Maxxen Maxxen merged commit dd880d6 into duckdb:main Oct 7, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant