bbqvec

Crates.iobbqvec
lib.rsbbqvec
version0.0.10
sourcesrc
created_at2024-09-23 17:44:29.020484
updated_at2024-09-26 19:43:13.901963
descriptionScalable, embeddable, vector storage for approximate K-nearest-neighbors (AKNN)
homepage
repositoryhttps://github.com/daxe-ai/bbqvec
max_upload_size
id1384326
size63,775
Barak Michener (barakmich)

documentation

README

BBQvec Logo

Status license GoDoc Crates.io Go CI Rust CI

BBQvec is an open-source, embedded vector database index for Go and Rust, providing approximate K-nearest-neighbors (aKNN).

Read more about the algorithm on our blog!

Getting Started

Go

package main

import (
  "fmt"

  bbq "github.com/daxe-ai/bbqvec"
)

func main() {
  // Declare store parameters
  dimensions := 200
  nBasis := 10

  // Initialize the store
  backend := bbq.NewMemoryBackend(dimensions)
  datastore, _ := bbq.NewVectorStore(backend, nBasis)

  // Create some test data, 100K random vectors
  vecs := bbq.NewRandVectorSet(100_000, dimensions, nil)
  datastore.AddVectorsWithOffset(0, vecs)
  /*
  Equivalent to:
  for i, v := range vecs {
  datastore.AddVector(bbq.ID(i), v)
  }
  */

  // Run a query
  targetVec := bbq.NewRandVector(dimensions, nil)
  results, _ := datastore.FindNearest(targetVec, 10, 1000, 1)

  // Inspect the results
  top := results.ToSlice()[0]
  vec, _ := backend.GetVector(top.ID)
  fmt.Println(top.ID, vec, top.Similarity)
}

Rust

use bbqvec::IndexIDIterator;

fn main() -> Result<()> {
  // Declare store parameters
  let dimensions = 200;
  let n_basis = 10;

  // Initialize the store
  let mem = bbqvec::MemoryBackend::new(dimensions, n_basis)?;
  let mut store = bbqvec::VectorStore::new(mem)?;

  // Create some test data, 100K random vectors
  let vecs = bbqvec::create_vector_set(dimensions, 100000);
  store.add_vector_iter(vecs.enumerate_ids())?;

  // Run a query
  let target = bbqvec::create_random_vector(dimensions);
  let results = store.find_nearest(&target, 10, 1000, 1)?;

  // Inspect the results
  for res in results.iter_results() {
    println!("{} {}", res.id, res.similarity)
  }
}

TODOs

We're still early; Go is the more tried-and-true and suits the beta use-case, but Rust is a good deal faster. We welcome contributions.

Go

  • More benchmarks
  • New Quantizations
    • Hamming Distance (single-bit vectors)
    • Novel quantizations

Rust

  • Finish disk backend to match Go (in progress, shortly)

  • New Quantizations

Acknowledgements

Thank you to MariaLetta for the free-gophers-pack and to rustacean.net for the CC0 logo characters.

Commit count: 50

cargo fmt