Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize lateral VSS joins using HNSW index #29

Merged
merged 8 commits into from
Oct 7, 2024
Merged

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