Provides a subset of the faiss API to DuckDB
Installing and Loading
INSTALL faiss FROM community;
LOAD faiss;
Example
-- Generate semi-random input data and queries
-- Note that the dimensionality of our data will be 5
CREATE TABLE input AS SELECT i AS id, apply(generate_series(1, 5), j-> CAST(hash(i*1000+j) AS FLOAT)/18446744073709551615) AS data FROM generate_series(1, 1000) s(i);
CREATE TABLE queries AS SELECT i AS id, apply(generate_series(1, 5), j-> CAST(hash(i*1000+j+8047329823) AS FLOAT)/18446744073709551615) AS data FROM generate_series(1, 10) s(i);
-- Create the index and insert data into it
CALL FAISS_CREATE('name', 5, 'IDMap,HNSW32');
CALL FAISS_ADD((SELECT id, data FROM input), 'name');
-- Get 10 results with uneven id
SELECT id, UNNEST(FAISS_SEARCH_FILTER('name', 10, data, 'id%2==1', 'rowid', 'input')) FROM queries;
-- Get 10 results with even id
SELECT id, UNNEST(FAISS_SEARCH_FILTER('name', 10, data, 'id%2==0', 'rowid', 'input')) FROM queries;
-- Get 10 results
SELECT id, UNNEST(FAISS_SEARCH('name', 10, data)) FROM queries;
About faiss
The FAISS extension allows DuckDB users to store vector data in faiss, and query this data, making reliable vector search more accessible.
Added Functions
function_name | function_type | description | comment | example |
---|---|---|---|---|
__faiss_create_mask | table | |||
faiss_add | table | |||
faiss_create | table | |||
faiss_create_params | table | |||
faiss_destroy | table | |||
faiss_load | table | |||
faiss_manual_train | table | |||
faiss_save | table | |||
faiss_search | scalar | |||
faiss_search_filter | scalar | |||
faiss_search_filter_set | scalar |