Pinecone Rust SDK
⚠️ Warning: This SDK is still in an alpha state. While it is mostly built out and functional, it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback, but be aware that updates may introduce breaking changes.
Documentation
The documentation can be found here.
Prerequisites
Rust version: tested with Rust version 1.78.0
Before you can use the Pinecone SDK, you must sign up for an account and find your API key in the Pinecone console dashboard at https://app.pinecone.io.
Installation
Run cargo add pinecone-sdk to add the crate as a dependency, or add the line pinecone-sdk = "0.1.2" to your Cargo.toml file under [dependencies]. More on the crate can be found here.
Usage
The PineconeClient class is the main point of entry into the Rust SDK. Parameters may either be directly passed in as Options, or read through environment variables as follows. More detail:
- The API key must be passed in either as an argument or as an environment variable called
PINECONE_API_KEY. If passed in asNone, the client will attempt to read in an environment variable value. - The control plane host, if passed in as
None, will attempt to read in an environment variable calledPINECONE_CONTROLLER_HOST. If it is not an environment variable, it will default tohttps://api.pinecone.io.
There are a couple of ways to instantiate the client, detailed below:
PineconeClientConfig
Initialize a PineconeClientConfig struct with parameters, and call config using the struct.
use ;
let config = PineconeClientConfig ;
let pinecone: PineconeClient = config.client.expect;
Default client
Use the default_client() function, which is the equivalent of constructing a PineconeClientConfig struct with all fields set to None. The API key and control plane host (optional) will be read from environment variables.
let pinecone: PineconeClient = default_client.expect;
Indexes
Create Index
Create serverless index
The following example creates a serverless index in the us-east-1 region of AWS. For more information on serverless and regional availability, see Understanding indexes
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_description: IndexModel = pinecone.create_serverless_index.await?;
Create pod index
The following example creates a pod index in the us-east-1 region of AWS.
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_description: IndexModel = pinecone.create_pod_index.await?;
Pod indexes support several optional configuration fields. The following example constructs a pod index with some specification for these fields.
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_description: IndexModel = pinecone.create_pod_index.await?;
List indexes
The following example lists all indexes in your project.
use PineconeClientConfig;
use IndexList;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_list: IndexList = pinecone.list_indexes.await?;
Describe index
The following example returns information about the index index-name.
use PineconeClientConfig;
use IndexModel;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_description: IndexModel = pinecone.describe_index.await?;
Configure index
Configuring an index takes in three optional parameters -- a DeletionProtection enum, the number of replicas, and the pod type. The deletion protection can be updated for any index type, while the number of replicas and the pod type can only be updated for pod indexes.
The following example disables deletion protection for the index index-name.
use PineconeClientConfig;
use IndexModel;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_description: IndexModel = pinecone.configure_index.await?;
The following example changes the index index-name to have 6 replicas and pod type s1. The deletion protection type will not be changed in this case.
use PineconeClientConfig;
use IndexModel;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let index_description: IndexModel = pinecone.configure_index.await?;
Delete index
The following example deletes the index index-name.
use PineconeClientConfig;
let config = PineconeClientConfig ;
let pinecone = config.client?;
pinecone.delete_index.await?;
Describe index statistics
The following example returns statistics about the index with host index-host.
Without filter
use BTreeMap;
use PineconeClientConfig;
use DescribeIndexStatsResponse;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let response: DescribeIndexStatsResponse = index.describe_index_stats.await?;
With filter
use BTreeMap;
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let mut fields = new;
let kind = Some;
fields.insert;
let response: DescribeIndexStatsResponse = index.describe_index_stats.await?;
Upsert vectors
The following example upserts two vectors into the index with host index-host.
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let vectors = ;
let response: UpsertResponse = index.upsert.await?;
Query vectors
There are two supported ways of querying an index.
Query by index
The following example queries the index with host index-host for the vector with ID vector-id, and returns the top 10 matches.
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
// Connect to index at host "index-host"
let mut index = pinecone.index.await?;
// Query the vector with id "vector-id" in the namespace "namespace"
let response: QueryResponse = index.query_by_id.await?;
Query by value
The following example queries the index with host index-host for the vector with values [1.0, 2.0, 3.0, 4.0], and returns the top 10 matches.
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let vector = vec!;
let response: QueryResponse = index.query_by_value.await?;
Delete vectors
There are three supported ways of deleting vectors.
Delete by ID
The following example deletes the vector with ID vector-id in the namespace namespace.
use PineconeClientConfig;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let ids =
index.delete_by_id.await?;
Delete by filter:
The following example deletes vectors that satisfy the filter in the namespace namespace.
use BTreeMap;
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut fields = new;
let kind = Some;
fields.insert;
index.delete_by_filter.await?;
Delete all:
The following example deletes all vectors in the namespace namespace.
use PineconeClientConfig;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
index.delete_all.await?;
Fetch vectors
The following example fetches the vectors with IDs 1 and 2 from the default namespace.
use PineconeClientConfig;
use FetchResponse;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let vectors = &;
let response: FetchResponse = index.fetch.await?;
Update vectors
The following example updates the vector with ID vector-id in the namespace namespace to have values [1.0, 2.0, 3.0, 4.0].
use PineconeClientConfig;
use UpdateResponse;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let response: UpdateResponse = index.update.await?;
List vectors
The following example lists vectors in the namespace namespace.
use PineconeClientConfig;
use ;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let mut index = pinecone.index.await?;
let response: ListResponse = index.list.await?;
Collections
Create collection
The following example creates a collection collection-name in the index index-name.
use PineconeClientConfig;
use CollectionModel;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let collection: CollectionModel = pinecone.create_collection.await?;
List collections
The following example lists all collections in a project.
use PineconeClientConfig;
use CollectionList;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let collection_list: CollectionList = pinecone.list_collections.await?;
Describe collection
The following example describes the collection collection-name.
use PineconeClientConfig;
use CollectionModel;
let config = PineconeClientConfig ;
let pinecone = config.client?;
let collection: CollectionModel = pinecone.describe_collection.await?;
Delete collection
The following example deletes the collection collection-name.
use PineconeClientConfig;
let config = PineconeClientConfig ;
let pinecone = config.client?;
pinecone.delete_collection.await?;
Contributing
If you'd like to make a contribution, or get setup locally to develop the Pinecone Rust client, please see our contributing guide