3 releases

0.0.3 Apr 14, 2024
0.0.2 Apr 10, 2024
0.0.1 Apr 2, 2024

#1373 in Database interfaces

Download history 213/week @ 2024-04-01 276/week @ 2024-04-08 36/week @ 2024-04-15

151 downloads per month

MIT license

34KB
168 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

~4–15MB
~219K SLoC