Code Monkey home page Code Monkey logo

faiss-rs's Introduction

Faiss-rs

faiss at crates.io Continuous integration status Minimum Rust Version Stable dependency status

This project provides Rust bindings to Faiss, the state-of-the-art vector search and clustering library.

Installing as a dependency

Currently, this crate does not build Faiss automatically for you. The dynamic library needs to be installed manually to your system.

  1. Follow the instructions here to build Faiss using CMake, enabling the variables FAISS_ENABLE_C_API and BUILD_SHARED_LIBS. The crate is currently only compatible with version v1.7.2. Consider building Faiss from this fork, c_api_head branch, which will contain the latest bindings to the C interface. For example:
    cmake -B . -DFAISS_ENABLE_C_API=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
    This will result in the dynamic library faiss_c ("c_api/libfaiss_c.so" on Linux), which needs to be installed in a place where your system will pick up (in Linux, try somewhere in the LD_LIBRARY_PATH environment variable, such as "/usr/lib", or try adding a new path to this variable). For GPU support, don't forget to enable the option FAISS_ENABLE_GPU. Note: faiss_c might link dynamically to the native faiss library, which in that case you will need to install the main shared object (faiss/libfaiss.so) as well.
  2. You are now ready to include this crate as a dependency:
[dependencies]
"faiss" = "0.11.0"

If you have built Faiss with GPU support, you can include the "gpu" feature in the bindings:

[dependencies]
"faiss" = {version = "0.11.0", features = ["gpu"]}

Using

A basic example is seen below. Please check out the documentation for more.

use faiss::{Index, index_factory, MetricType};

let mut index = index_factory(64, "Flat", MetricType::L2)?;
index.add(&my_data)?;

let result = index.search(&my_query, 5)?;
for (i, (l, d)) in result.labels.iter()
    .zip(result.distances.iter())
    .enumerate()
{
    println!("#{}: {} (D={})", i + 1, *l, *d);
}

License and attribution notice

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

This work is not affiliated with Facebook AI Research or the main Faiss software.

faiss-rs's People

Contributors

ava57r avatar enet4 avatar gensmusic avatar mooreniemi avatar skyfan2002 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.