Open thewh1teagle opened 10 months ago
I managed to load the extension into sqlite3
cli
when compiled using make loadable-release
. Also I had to add cyglapack-0.dll
to the same folder.
I successfuly loaded the extensions in Python
as well. but unfortunately when executing
db.execute("""
CREATE VIRTUAL TABLE IF NOT EXISTS vss_post USING vss0(embeddings(3));
""")
it crash the program without any error.
Thanks for the detailed report and updates! You're the first person to report being able to compile sqlite-vss
, so I'm very interested in getting this to work.
A few questions:
vector0.dll
, does select vector_version()
return a string?vss0.dll
, does select vss_version()
return a string?select vss_distance_l1('[0.1, 0.1]', '[0.2, 0.2]')
and see if that works?See it in action:
C:\Users\User\Documents\projects\vss\sqlite-vss\vendor\sqlite\.libs>sqlite3.exe
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open random.db
sqlite> .load vector0.dll
sqlite> select vector_version();
v0.1.2
sqlite> .load vss0.dll
sqlite> select vector_version();
v0.1.2
sqlite> select vss_distance_l1('[0.1, 0.1]', '[0.2, 0.2]');
0.200000002980232
sqlite>
When running the same from Python
, the program crash here without error in
select vss_distance_l1('[0.1, 0.1]', '[0.2, 0.2]');
Does it throw an OperationalError
, or just completely crash? Is there a segmentation fault, or any other messaging that gets logged out?
No error, it just exit from python
with status 1
The fact that it only happens when executing functions that use Faiss's vector computations (ie fails on vss_distance_l1
and not vss_version
) makes me thing that it's a dynamically library error. I'm guess that windows holds off on resolving + executing the cygblas-0.dll
/ cyggomp-1.dll
/ cyglapack-0.dll
libraries until they're actually needed. It also might explain the spectacular no-error message failures - if it's a deep underlying dll error, then Python may not have a chance to catch it.
That's my guess at least - my knowledge with Windows is very limited. I'd say double check that those dll's exist and work correctly (probably with ldd ? ). I'd be curious to see if there's a sample Faiss C++ project you could compile + execute on your Windows machine, to see if it's a Faiss compilation error or a sqlite-vss
specific error.
I used the same faiss
submodule
in your repo
. Just installed the necessary tools and libraries in cygwin
setup and followed your instructions to build the library
I added strace
output when running the python
script
Also, when I run the script using Python
version of cygwin64
it works:
I tried faiss sample faiss
c++
project and it compiled and run without errors:
So to summarize, on your windows machine using cygwin64:
sqlite-vss
with the cygwin64 version of Python works as expectedsqlite-vss
with regular Python does now work and crashessqlite-vss
from the sqlite3 CLI does not work and still crashesIs that right?
Everything correct, except for the last one -
using sqlite-vss
from sqlite3 CLI
works, both from cygwin
environemnt or just from cmd
Cool - so is there anything actionable you'd like from this issue then? My guess is that since sqlite-vss
was built with cygwin64, it requires cygwin64 applications to load the extension.
I'll probably try compiling sqlite-vss with cygwin64 on a github actions runner, but its been very difficult in the past
Currenly I want to figure out why do I get segfault
when running from Python
/ Nodejs
that is not part of cygwin
I'm not sure how to debug it.
It will not be usable if we can't use it with regular Python
which is not of cygwin
I managed to compile faiss
on Windows in msys2
environment.
msys2
works pretty well, I think it's suitable for doing it pretty easily in Github actions as well.
https://github.com/facebookresearch/faiss/issues/3067
Hello, I try to use VSS in combination with SQLite on Windows.I like the approach making VSS part of the query search. Did you make any progress with the Windows install? I'm struggling now with settings in the Makefile and the CMakelist.txt.
Thanks in advance, Léon
Here's a way that worked for me, based on @thewh1teagle 's approach. I haven't tested it in-depth, but the sqlite3 cli can load the extensions and select vss_distance_l1('[0.1, 0.1]', '[0.2, 0.2]')
works.
# see https://github.com/facebookresearch/faiss/issues/3067#issuecomment-1873007384
pacman --needed -S $MINGW_PACKAGE_PREFIX-{toolchain,cmake,make,swig,autotools,lapack} git
git clone https://github.com/asg017/sqlite-vss.git && cd sqlite-vss
# see https://github.com/asg017/sqlite-vss/blob/main/docs.md
./vendor/get_sqlite.sh
cd vendor/sqlite
./configure && make
cd ../../
4. Apply the following patch to `vendor/faiss`:
```diff
diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt
index 16eb9e9c..940ba03f 100644
--- a/faiss/CMakeLists.txt
+++ b/faiss/CMakeLists.txt
@@ -214,8 +214,8 @@ add_library(faiss_avx2 ${FAISS_SRC})
if(NOT FAISS_OPT_LEVEL STREQUAL "avx2")
set_target_properties(faiss_avx2 PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
-if(NOT WIN32)
- target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mpopcnt>)
+if(NOT MSVC)
+ target_compile_options(faiss_avx2 PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mf16c -mpopcnt -fpermissive>)
else()
# MSVC enables FMA with /arch:AVX2; no separate flags for F16C, POPCNT
# Ref. FMA (under /arch:AVX2): https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
diff --git a/faiss/impl/platform_macros.h b/faiss/impl/platform_macros.h
index 9cec8260..44293e3e 100644
--- a/faiss/impl/platform_macros.h
+++ b/faiss/impl/platform_macros.h
@@ -83,6 +83,17 @@ inline int __builtin_clzll(uint64_t x) {
#endif
#else
+
+/*******************************************************
+ * Windows MinGW
+ *******************************************************/
+#ifdef _WIN32
+
+#define posix_memalign(p, a, s) \
+ (((*(p)) = _aligned_malloc((s), (a))), *(p) ? 0 : errno)
+#endif
+
+
/*******************************************************
* Linux and OSX
*******************************************************/
diff --git a/faiss/invlists/InvertedListsIOHook.cpp b/faiss/invlists/InvertedListsIOHook.cpp
index 0081c4f9..2c3a6006 100644
--- a/faiss/invlists/InvertedListsIOHook.cpp
+++ b/faiss/invlists/InvertedListsIOHook.cpp
@@ -13,9 +13,9 @@
#include <faiss/invlists/BlockInvertedLists.h>
-#ifndef _MSC_VER
+#ifndef _WIN32
#include <faiss/invlists/OnDiskInvertedLists.h>
-#endif // !_MSC_VER
+#endif // !_WIN32
namespace faiss {
@@ -33,7 +33,7 @@ namespace {
/// std::vector that deletes its contents
struct IOHookTable : std::vector<InvertedListsIOHook*> {
IOHookTable() {
-#ifndef _MSC_VER
+#ifndef _WIN32
push_back(new OnDiskInvertedListsIOHook());
#endif
push_back(new BlockInvertedListsIOHook());
cmake -B build-release . -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build build-release -- -j<number of cores here>
# copy dlls for use outside of MSYS2
cp /ucrt64/bin/{libgcc_s_seh-1.dll,libwinpthread-1.dll,libblas.dll,libgomp-1.dll,liblapack.dll,libgfortran-5.dll,libquadmath-0.dll,libstdc++-6.dll} ./build-release/
build-release
on deployment.Hi, @ma-chengyuan could you please share the dll file? I would like to use the windows version of sqlite-vss, but the make process seems too complicated. If you can share it, I would like to try it to see if it works in my environment.
@ma-chengyuan hi, I follow your instruction. The dlls only work with sqlite tool only. The built-in version sqlite3 (installed using .msi file on Windows) or node sqlite3 cannot load that dll as extension.
Here is the message error: The specified module could not be found
Hi I built
sqlite-vss
onWindows 11 x64
usingcygwin64
I followed the instructions in #building-sqlite-vss-yourselfAnd as shown, I got
vector0.dll
andvss0.dll
Then I placed the
dll
files in the same folder ofsqlite-vss/vendor/sqlite/.libs
which has the compiledsqlite.exe
and tried to load the extension intosqlite
Looks like it loads successfully
vector0.dll
but it fails to loadvss0.dll
ldd output
```ts C:\Users\User\Documents\projects\vss\sqlite-vss\vendor\sqlite\.libs>ldd vector0.dll ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x7ffd2ad10000) KERNEL32.DLL => /cygdrive/c/Windows/System32/KERNEL32.DLL (0x7ffd2a160000) KERNELBASE.dll => /cygdrive/c/Windows/System32/KERNELBASE.dll (0x7ffd283c0000) msvcrt.dll => /cygdrive/c/Windows/System32/msvcrt.dll (0x7ffd2a0b0000) cygwin1.dll => /usr/bin/cygwin1.dll (0x7ffceece0000) cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x3fec80000) cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3ff870000) advapi32.dll => /cygdrive/c/Windows/System32/advapi32.dll (0x7ffd2ab00000) sechost.dll => /cygdrive/c/Windows/System32/sechost.dll (0x7ffd293e0000) RPCRT4.dll => /cygdrive/c/Windows/System32/RPCRT4.dll (0x7ffd29920000) CRYPTBASE.DLL => /cygdrive/c/Windows/SYSTEM32/CRYPTBASE.DLL (0x7ffd27860000) bcryptPrimitives.dll => /cygdrive/c/Windows/System32/bcryptPrimitives.dll (0x7ffd288c0000) C:\Users\User\Documents\projects\vss\sqlite-vss\vendor\sqlite\.libs>ldd vss0.dll ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x7ffd2ad10000) KERNEL32.DLL => /cygdrive/c/Windows/System32/KERNEL32.DLL (0x7ffd2a160000) KERNELBASE.dll => /cygdrive/c/Windows/System32/KERNELBASE.dll (0x7ffd283c0000) msvcrt.dll => /cygdrive/c/Windows/System32/msvcrt.dll (0x7ffd2a0b0000) cygwin1.dll => /usr/bin/cygwin1.dll (0x7ffceece0000) cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x3fec80000) cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3ff870000) cygblas-0.dll => /cygdrive/c/Users/User/Documents/projects/vss/sqlite-vss/vendor/sqlite/.libs/cygblas-0.dll (0x3fe3d0000) cyggomp-1.dll => /usr/bin/cyggomp-1.dll (0x3fe310000) cyglapack-0.dll => /cygdrive/c/Users/User/Documents/projects/vss/sqlite-vss/vendor/sqlite/.libs/cyglapack-0.dll (0x3f8160000) cyggfortran-5.dll => /usr/bin/cyggfortran-5.dll (0x3f8890000) cygquadmath-0.dll => /usr/bin/cygquadmath-0.dll (0x3fc150000) advapi32.dll => /cygdrive/c/Windows/System32/advapi32.dll (0x7ffd2ab00000) sechost.dll => /cygdrive/c/Windows/System32/sechost.dll (0x7ffd293e0000) RPCRT4.dll => /cygdrive/c/Windows/System32/RPCRT4.dll (0x7ffd29920000) CRYPTBASE.DLL => /cygdrive/c/Windows/SYSTEM32/CRYPTBASE.DLL (0x7ffd27860000) bcryptPrimitives.dll => /cygdrive/c/Windows/System32/bcryptPrimitives.dll (0x7ffd288c0000) ```