#vector #llm #dag #ann #hnsw

vsag

Rust binding for VSAG, a vector indexing library used for similarity search

2 releases

0.1.1 Nov 12, 2024
0.1.0 Nov 11, 2024

#381 in Machine learning

Download history 248/week @ 2024-11-11 16/week @ 2024-11-18 89/week @ 2024-12-02 80/week @ 2024-12-09

195 downloads per month

Apache-2.0

2MB
39K SLoC

C++ 35K SLoC // 0.1% comments Python 3K SLoC // 0.2% comments Rust 395 SLoC // 0.1% comments Shell 98 SLoC // 0.2% comments BASH 10 SLoC

VSAG Rust Binding

Crates.io docs.rs License CI

A Rust binding for the VSAG.

Usage

cargo add vsag

Then try the example:

use vsag_sys::VsagIndex;

let index_type = "hnsw";
let con_params = r#"{
    "dtype": "float32",
    "metric_type": "l2",
    "dim": 128,
    "hnsw": {
        "max_degree": 16,
        "ef_construction": 100
    }
}"#;
let search_params = r#"{
    "hnsw": {
    "ef_search": 100
    }
}"#;

let index = VsagIndex::new(index_type, con_params).unwrap();

let ids: Vec<i64> = (0..num_vectors as i64).collect();
let vectors = (0..num_vectors)
    .map(|_| {
        (0..dim)
            .map(|_| rand::random::<f32>())
            .collect::<Vec<f32>>()
    })
    .collect::<Vec<_>>();
let vectors_for_index: Vec<f32> = vectors.iter().flat_map(|v| v.iter().copied()).collect();

let failed_ids = index
    .build(num_vectors, dim, &ids, &vectors_for_index)
    .unwrap();
assert_eq!(failed_ids.len(), 0);

let query_vector: Vec<f32> = (0..dim).map(|_| rand::random()).collect();
let k = 10;
let output = index.knn_search(&query_vector, k, search_params).unwrap();
assert_eq!(output.ids.len(), k.min(num_vectors));
assert_eq!(output.distances.len(), k.min(num_vectors));

No runtime deps