4 releases

0.0.4 Oct 16, 2024
0.0.3 Apr 14, 2024
0.0.2 Apr 10, 2024
0.0.1 Apr 2, 2024

#2285 in Database interfaces

Download history 2/week @ 2024-09-22 13/week @ 2024-09-29 206/week @ 2024-10-13 14/week @ 2024-10-20 1/week @ 2024-10-27

186 downloads per month

MIT license

34KB
188 lines

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

Dependencies

~5–16MB
~205K SLoC