Crate arc_vector_rust
source ·Expand description
The ArcVector Vector Database client
This library uses GRPC to connect to the ArcVector server and allows you to access most if not all features. If you find a missing feature, please open an issue.
If you use this library, you’ll likely want to import the usual types and functions:
#[allow(unused_import)]
use arc_vector_rust::prelude::*;
To work with a ArcVector database, you’ll first need to connect by creating a
ArcVectorClient
:
let mut config = ArcVectorClientConfig::from_url(url);
config.api_key = std::env::var("ARC_VECTOR_API_KEY").ok();
ArcVectorClient::new(Some(config))
ArcVector works with Collections of Points. To add vector data, you first create a collection:
use arc_vector_rust::arc_vector::{VectorParams, VectorsConfig};
use arc_vector_rust::arc_vector::vectors_config::Config;
let response = arc_vector_client
.create_collection(&CreateCollection {
collection_name: "my_collection".into(),
vectors_config: Some(VectorsConfig {
config: Some(Config::Params(VectorParams {
size: 512,
distance: Distance::Cosine as i32,
..Default::default()
})),
}),
..Default::default()
})
.await?;
The most interesting parts are the collection_name
and the
vectors_config.size
(the length of vectors to store) and distance
(which is the Distance
measure to gauge
similarity for the nearest neighbors search).
Now we have a collection, we can insert (or rather upsert) points. Points have an id, one or more vectors and a payload. We can usually do that in bulk, but for this example, we’ll add a single point:
let point = PointStruct {
id: Some(PointId::from(42)), // unique u64 or String
vectors: Some(vec![0.0_f32; 512].into()),
payload: std::collections::HashMap::from([
("great".into(), Value::from(true)),
("level".into(), Value::from(9000)),
("text".into(), Value::from("Hi ArcVector!")),
("list".into(), Value::from(vec![1.234, 0.815])),
]),
};
let response = arc_vector_client
.upsert_points("my_collection", vec![point], None)
.await?;
Finally, we can retrieve points in various ways, the canonical one being a plain similarity search:
let response = arc_vector_client
.search_points(&SearchPoints {
collection_name: "my_collection".to_string(),
vector: vec![0.0_f32; 512],
limit: 4,
with_payload: Some(true.into()),
..Default::default()
})
.await?;
You can also add a filters: Some(filters)
field to the
SearchPoints
argument to filter the
result. See the Filter
documentation for
details.