asg017 / sqlite-vss

A SQLite extension for efficient vector search, based on Faiss!
MIT License
1.59k stars 58 forks source link

`faiss::FaissException` when using `vss_search` with `better-sqlite3` on Node (WSL) #81

Closed larryhudson closed 11 months ago

larryhudson commented 11 months ago

Hi Alex, awesome job with these sqlite extensions. I'm trying to get up and running with sqlite-vss and better-sqlite3 on Node, in Ubuntu using WSL.

I have followed the installation instructions and have set up a simple test script here: https://github.com/larryhudson/testing-sqlite-vss/blob/main/index.js

I think I am storing the vectors and setting up the virtual table properly, but I am running into a faiss::FaissException error when I get to the vss_search stage:

terminate called after throwing an instance of 'faiss::FaissException'
  what():  Error in virtual void faiss::IndexFlat::search(faiss::idx_t, const float*, faiss::idx_t, float*, faiss::idx_t*, const faiss::SearchParameters*) const at /home/runner/work/sqlite-vss/sqlite-vss/vendor/faiss/faiss/IndexFlat.cpp:34: Error: 'k > 0' failed
Aborted

Could you please check out the test script and let me know if I am doing something wrong? Thanks again.

larryhudson commented 11 months ago

Just tried reproducing the error on macOS (M1) and I'm getting the same error, so I don't think it's a WSL error. Must be something wrong with how I'm setting up the tables or storing the vectors.

asg017 commented 11 months ago

In your script , it looks like the vss_quotes table is empty. The insertRowsStatement statement only inserts into quotes but not vss_quotes.

Could do something like this:

insert into vss_quotes(rowid, text_embedding)
  select id, text_embedding
  from quotes;

On line 86.

That error should be caught + handled on the sqlite-vss side regardless, will look into. Could you run sqlite_version() just to double check the sqlite version you're on?

larryhudson commented 11 months ago

Ah great, that has fixed it! I missed that instruction when I was going through the Observable article.

Thanks for the quick response :)

larryhudson commented 11 months ago

And it looks like I'm running SQLite version 3.39.5 on macOS, by the way.

asg017 commented 11 months ago

Glad to hear it got resolved!

One note, since you're on 3.39.5 (which contains a bug that was fixed in 3.41+, you'll have to use the vss_search(text_embedding, vss_search_params(?, 20)) syntax instead of vss_search(text_embedding, ?) limit 20. There's some info about this in the docs, which I should also clean up a little...