faiss-next-sys

Crates.iofaiss-next-sys
lib.rsfaiss-next-sys
version0.2.0
sourcesrc
created_at2024-01-23 13:28:56.36843
updated_at2024-02-02 15:28:16.745198
descriptionLight weighted rust wrapper of c api of facebookresearch/faiss library
homepagehttp://github.com/yexiangyu/faiss-next
repositoryhttps://github.com/yexiangyu/faiss-next
max_upload_size
id1110824
size392,607
(yexiangyu)

documentation

https://docs.rs/faiss-next

README

faiss-next-sys

faiss-next-sys wrap c_api of faiss into rust with bindgen.

Currently supported faiss version is v1.7.4

Build faiss from source

faiss-next-sys requires faiss compiled with FAISS_ENABLE_C_API=ON and BUILD_SHARED_LIBS=ON.

Some facebookresearch/faiss distributions, like of brew on mac, does not provide faiss_c library.

So, building faiss from source is necessary time to time.

facebookresearch/faiss provides installation document officially to guide how to build faiss from source.

But, on windows, building faiss will fail, because of msvc c++ compiler's implemention of C++17 syntax: issue.

So, a hecked v1.7.4 version is made: link to solve the issue.

If windows is not the target platform, just clone faiss and check v1.7.4 branch out, will just work fine.

Pick one of above, download, unzip, then start building:

MacOS

xcode and brew needed, install in advance.

# install cmake openblas and llvm
brew install cmake openblas llvm

# configure
cmake -B build -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++  -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF

# compile
cmake --build build --config Release

# install
cmake --install build --prefix=$HOME/faiss
cp build/c_api/libfaiss_c.dylib $HOME/faiss/lib/

Linux

gcc, cmake, intelmkl, cuda needed, install in advance.

# configure
cmake -B build -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_GPU=ON -DFAISS_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF

# compile
 cmake --build build --config Release

# install
 cmake --install build --prefix=$HOME/faiss
 cp build/c_api/libfaiss_c.so $HOME/faiss/lib/

Windows

Visual Studio 2022, cmake, intelmkl, cuda needed, install in advance.

# configure
cmake -B build -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_GPU=ON -DFAISS_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF

# compile
 cmake --build build --config Release

# install
cmake --install build --prefix=%USERPROFILE%\faiss
copy build\c_api\Release\faiss_c.dll %USERPROFILE%\faiss\bin
copy build\c_api\Release\faiss_c.lib %USERPROFILE%\faiss\lib\

Bindings

Bindings was generated by running the follow commands under faiss-next-sys folder

cargo build --features bindgen

or, generate bindings with gpu enabled

cargo build --features bindgen,gpu

Generated bindings looks like:

└── src
    ├── lib.rs
    ├── linux
    │   ├── bindings.rs      #linux cpu bindings
    │   └── bindings_gpu.rs  #linux gpu bindings
    ├── macos
    │   └── bindings.rs      #macos cpu bindings, gpu is not supported
    └── windows
        ├── bindings.rs	     #windows cpu bindings 
        └── bindings_gpu.rs  #windows gpu bindings
Commit count: 0

cargo fmt