Crates.io | vsag |
lib.rs | vsag |
version | 0.1.1 |
source | src |
created_at | 2024-11-11 15:04:05.85269 |
updated_at | 2024-11-12 00:15:02.857926 |
description | Rust binding for VSAG, a vector indexing library used for similarity search. |
homepage | https://github.com/jiacai2050/vsag-rs |
repository | https://github.com/jiacai2050/vsag-rs |
max_upload_size | |
id | 1443837 |
size | 3,524,534 |
A Rust binding for the VSAG.
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));