turbopuffer-client

Crates.ioturbopuffer-client
lib.rsturbopuffer-client
version0.0.4
sourcesrc
created_at2024-04-02 22:18:35.760824
updated_at2024-10-16 23:47:39.334582
descriptionClient for the turbopuffer vector database
homepagehttps://github.com/ragkit/turbopuffer-client
repositoryhttps://github.com/ragkit/turbopuffer-client
max_upload_size
id1194488
size83,971
Kyle Davis (kyldvs)

documentation

https://docs.rs/turbopuffer-client/latest/turbopuffer-client/

README

turbopuffer-client

crates.io badge ci badge license badge

Overview

This is a Rust Client for interacting with the turbopuffer vector database.

Note: Right now, this library doesn't validate the JSON body, it simply passes what you construct to turbopuffer. For a full list of options see https://turbopuffer.com/docs.

Usage

Install via Cargo.toml:

[dependencies]
turbopuffer-client = "0.0.3"

Create a client using your API key from turbopuffer.com:

let client = turbopuffer_client::Client::new(&api_key);

All operations are scoped to a namespace:

let ns = client.namespace("test");

Initialize the namespace with some vectors using serde_json::json!() to build the body, and ns.upsert to send the request:

let body = json!({
  "ids": [1, 2, 3, 4],
  "vectors": [[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4]],
  "attributes": {
    "my-string": ["one", null, "three", "four"],
    "my-uint": [12, null, 84, 39],
    "my-string-array": [["a", "b"], ["b", "d"], [], ["c"]]
  }
});

let res = ns.upsert(&body).await.unwrap();

// This is the response type.
assert!(matches!(
  res,
  UpsertResponse {
    status: response::Status::Ok
  }
));

Query the namespace similarly, but using ns.query:

let query = json!({
  "vector": [0.105, 0.1],
  "distance_metric": "euclidean_squared",
  "top_k": 1,
  "include_vectors": true,
  "include_attributes": ["my-string"],
});

let res = ns.query(&query).await.unwrap();

// Then you have access to the ResponseVectors:
let first = res.vectors.first().unwrap();
assert!(matches!(first.id, response::Id::Int(1)));

Finally, you can delete a namespace using ns.delete:

let res = ns.delete().await.unwrap();

// This is the response type.
assert!(matches!(
  res,
  DeleteResponse {
    status: response::Status::Ok
  }
));

Contributing

We warmly welcome any contributions, for more info see: CONTRIBUTING.md

License

MIT

Commit count: 7

cargo fmt