Lightweight, simple, single instance, local in-memory vector database written in Rust.
Currently supports the following indexing strategies:
- IVFFlat (k-means for partitioning)
- Locality-sensitive hashing (LSH) heavily inspired by fennel.ai's blog post.
Like any sensible package, the API aims to be dead simple.
- Import, obviously:
use vers::indexes::base::{Index, Vector};
use vers::indexes::ivfflat::IVFFlatIndex;
- Build an index:
let mut index = IVFFlatIndex::build_index(
num_clusters,
num_attempts,
max_iterations,
&vectors
);
- Add an embedding vector into the index:
index.add(Vector(*emb), emb_unique_id);
- Persist the index to disk:
let _ = index.save_index("wiki.index");
- Load the index from disk:
let index = match IVFFlatIndex::load_index("wiki.index") {
Ok(index) => index,
Err(e) => panic!("Failed to load index! {}", e),
};
- And of course, actually search the index:
let results = index.search_approximate(
embs.get("king"), // query vector
10 // top_k
); // kings, queen, monarch, ...
That said, the API is unstable and subject to change. In particular, I really dislike having to pass in the unique vector ID into search_approximate
.
- Python bindings
- Performance improvements (building IVFFlat index is slow, vectorization)
- Benchmarks (comparisons with popular ANN search indexes, e.g. faiss, and exhaustive searches)
Contributions are welcomed.