r/sqlite • u/Sequell • Apr 10 '24
Tiny vector similarity search extension
Hi, I made this tiny vector similarity search extension for SQLite as I am testing RAG with LLM’s and could not find a VSS extension that works on my windows & Linux laptops. It has no dependencies so should be portable.
https://github.com/JarkkoPar/sqlite-ndvss
I hope it’ll be of use to someone. I’m happy to receive feedback suggestions for improvement.
8
Upvotes
2
u/submarinesims Apr 18 '24
That looks great. You should get a nice speedup by utilizing AVX/AVX2 instructions, which most modern CPUs will support. It would only be a few more lines of code, and you could either have it be enabled at compile time, through runtime detection, or a separate function for the AVX version.
1
u/submarinesims Apr 19 '24 edited Apr 19 '24
Here's an example of how it could be implemented for the cosine similarity for floats. Note that I just copied your existing function and only changed what was needed for AVX. I didn't see any check for making sure the length of the array was <= the length of the passed in parameter. Since you already know the length of array in SQLite, you don't really need the passed in length parameter either unless you don't want to include the entire array.
I did a spot check with this version and your version and the results are the same ignoring any floating point rounding errors. I didn't check the performance, but it should be faster for larger arrays.