pub struct Index { /* private fields */ }
Expand description
A client for interacting with a Pinecone index.
Implementations§
Source§impl Index
impl Index
Sourcepub async fn upsert(
&mut self,
vectors: &[Vector],
namespace: &Namespace,
) -> Result<UpsertResponse, PineconeError>
pub async fn upsert( &mut self, vectors: &[Vector], namespace: &Namespace, ) -> Result<UpsertResponse, PineconeError>
The upsert operation writes vectors into a namespace. If a new value is upserted for an existing vector id, it will overwrite the previous value.
§Arguments
vectors: &[Vector]
- A list of vectors to upsert.namespace: &Namespace
- The namespace to upsert vectors into. Default is “”.
§Return
Result<UpsertResponse, PineconeError>
§Example
use pinecone_sdk::models::{Namespace, UpsertResponse, Vector};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
let vectors = [Vector {
id: "vector-id".to_string(),
values: vec![1.0, 2.0, 3.0, 4.0],
sparse_values: None,
metadata: None,
}];
// Upsert vectors into the namespace "namespace" in the index
let response: Result<UpsertResponse, PineconeError> = index.upsert(&vectors, &"namespace".into()).await;
Sourcepub async fn list(
&mut self,
namespace: &Namespace,
prefix: Option<&str>,
limit: Option<u32>,
pagination_token: Option<&str>,
) -> Result<ListResponse, PineconeError>
pub async fn list( &mut self, namespace: &Namespace, prefix: Option<&str>, limit: Option<u32>, pagination_token: Option<&str>, ) -> Result<ListResponse, PineconeError>
The list operation lists the IDs of vectors in a single namespace of a serverless index. An optional prefix can be passed to limit the results to IDs with a common prefix.
§Arguments
namespace: &Namespace
- The namespace to list vectors from. Default is “”.prefix: Option<&str>
- The vector IDs to list, will list all vectors with IDs that have a matching prefix. Default is empty string.limit: Option<u32>
- The maximum number of vector ids to return. If unspecified, the default limit is 100.pagination_token: Option<&str>
- The token for paginating through results.
§Return
Result<ListResponse, PineconeError>
§Example
use pinecone_sdk::models::{Namespace, ListResponse};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
// List all vectors in the namespace "namespace"
let response: Result<ListResponse, PineconeError> = index.list(&"namespace".into(), None, None, None).await;
Sourcepub async fn describe_index_stats(
&mut self,
filter: Option<Metadata>,
) -> Result<DescribeIndexStatsResponse, PineconeError>
pub async fn describe_index_stats( &mut self, filter: Option<Metadata>, ) -> Result<DescribeIndexStatsResponse, PineconeError>
The describe_index_stats operation returns statistics about the index.
§Arguments
filter: Option<Metadata>
- An optional filter to specify which vectors to return statistics for. None means no filter will be applied. Note that the filter is only supported by pod indexes.
§Return
Result<DescribeIndexStatsResponse, PineconeError>
§Example
use std::collections::BTreeMap;
use pinecone_sdk::models::{DescribeIndexStatsResponse, Value, Kind, Metadata, Namespace};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
// Construct a metadata filter
let mut fields = BTreeMap::new();
let kind = Some(Kind::StringValue("value".to_string()));
fields.insert("field".to_string(), Value { kind });
// Describe the index statistics
let response: Result<DescribeIndexStatsResponse, PineconeError> = index.describe_index_stats(Some(Metadata { fields })).await;
Sourcepub async fn update(
&mut self,
id: &str,
values: Vec<f32>,
sparse_values: Option<SparseValues>,
metadata: Option<Metadata>,
namespace: &Namespace,
) -> Result<UpdateResponse, PineconeError>
pub async fn update( &mut self, id: &str, values: Vec<f32>, sparse_values: Option<SparseValues>, metadata: Option<Metadata>, namespace: &Namespace, ) -> Result<UpdateResponse, PineconeError>
The update operation updates a vector in a namespace. If a value is included, it will overwrite the previous value.
If a metadata
filter is included, the values of the fields specified in it will be added or overwrite the previous values.
§Arguments
id: &str
- The vector’s unique ID.values: Vec<f32>
- The vector data.sparse_values: Option<SparseValues>
- The sparse vector data.metadata: Option<MetadataFilter>
- The metadata to set for the vector.namespace: &Namespace
- The namespace containing the vector to update. Default is “”.
§Return
Result<UpsertResponse, PineconeError>
§Example
use pinecone_sdk::models::{Namespace, SparseValues, Metadata, UpdateResponse};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
// Update the vector with id "vector-id" in the namespace "namespace"
let response: Result<UpdateResponse, PineconeError> = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await;
Sourcepub async fn query_by_id(
&mut self,
id: &str,
top_k: u32,
namespace: &Namespace,
filter: Option<Metadata>,
include_values: Option<bool>,
include_metadata: Option<bool>,
) -> Result<QueryResponse, PineconeError>
pub async fn query_by_id( &mut self, id: &str, top_k: u32, namespace: &Namespace, filter: Option<Metadata>, include_values: Option<bool>, include_metadata: Option<bool>, ) -> Result<QueryResponse, PineconeError>
The query operation searches a namespace using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.
§Arguments
id: &str
- The id of the query vector.top_k: u32
- The number of results to return.namespace: &Namespace
- The namespace to query. Default is “”.filter: Option<Metadata>
- The filter to apply to limit your search by vector metadata.include_values: Option<bool>
- Indicates whether to include the values of the vectors in the response. Default is false.include_metadata: Option<bool>
- Indicates whether to include the metadata of the vectors in the response. Default is false.
§Return
Result<QueryResponse, PineconeError>
§Example
use pinecone_sdk::models::{Namespace, QueryResponse};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
// Query the vector with id "vector-id" in the namespace "namespace"
let response: Result<QueryResponse, PineconeError> = index.query_by_id("vector-id", 10, &Namespace::default(), None, None, None).await;
Sourcepub async fn query_by_value(
&mut self,
vector: Vec<f32>,
sparse_vector: Option<SparseValues>,
top_k: u32,
namespace: &Namespace,
filter: Option<Metadata>,
include_values: Option<bool>,
include_metadata: Option<bool>,
) -> Result<QueryResponse, PineconeError>
pub async fn query_by_value( &mut self, vector: Vec<f32>, sparse_vector: Option<SparseValues>, top_k: u32, namespace: &Namespace, filter: Option<Metadata>, include_values: Option<bool>, include_metadata: Option<bool>, ) -> Result<QueryResponse, PineconeError>
The query operation searches a namespace using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.
§Arguments
vector: Vec<f32>
- The query vector.sparse_vector: Option<SparseValues>
- Vector sparse data.top_k: u32
- The number of results to return.namespace: &Namespace
- The namespace to query. Default is “”.filter: Option<Metadata>
- The filter to apply to limit your search by vector metadata.include_values: Option<bool>
- Indicates whether to include the values of the vectors in the response. Default is false.include_metadata: Option<bool>
- Indicates whether to include the metadata of the vectors in the response. Default is false.
§Return
Result<QueryResponse, PineconeError>
§Example
use pinecone_sdk::models::{Namespace, QueryResponse};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
let vector = vec![1.0, 2.0, 3.0, 4.0];
// Query the vector in the default namespace
let response: Result<QueryResponse, PineconeError> = index.query_by_value(vector, None, 10, &Namespace::default(), None, None, None).await;
Sourcepub async fn delete_by_id(
&mut self,
ids: &[&str],
namespace: &Namespace,
) -> Result<(), PineconeError>
pub async fn delete_by_id( &mut self, ids: &[&str], namespace: &Namespace, ) -> Result<(), PineconeError>
The delete_by_id operation deletes vectors by ID from a namespace.
§Arguments
ids: &[&str]
- List of IDs of vectors to be deleted.namespace: &Namespace
- The namespace to delete vectors from. Default is “”.
§Return
Result<(), PineconeError>
§Example
use pinecone_sdk::models::Namespace;
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
let ids = ["vector-id"];
// Delete vectors from the namespace "namespace" that have the ids in the list
let response: Result<(), PineconeError> = index.delete_by_id(&ids, &"namespace".into()).await;
Sourcepub async fn delete_all(
&mut self,
namespace: &Namespace,
) -> Result<(), PineconeError>
pub async fn delete_all( &mut self, namespace: &Namespace, ) -> Result<(), PineconeError>
The delete_all operation deletes all vectors from a namespace.
§Arguments
namespace: &Namespace
- The namespace to delete vectors from. Default is “”.
§Return
Result<(), PineconeError>
§Example
use pinecone_sdk::models::Namespace;
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
// Delete all vectors from the namespace "namespace"
let response: Result<(), PineconeError> = index.delete_all(&"namespace".into()).await;
Sourcepub async fn delete_by_filter(
&mut self,
filter: Metadata,
namespace: &Namespace,
) -> Result<(), PineconeError>
pub async fn delete_by_filter( &mut self, filter: Metadata, namespace: &Namespace, ) -> Result<(), PineconeError>
The delete_by_filter operation deletes the vectors from a namespace that satisfy the filter.
§Arguments
filter: Metadata
- The filter to specify which vectors to delete.namespace: &Namespace
- The namespace to delete vectors from. Default is “”.
§Return
Result<(), PineconeError>
§Example
use std::collections::BTreeMap;
use pinecone_sdk::models::{Metadata, Value, Kind, Namespace};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
// Construct a metadata filter
let mut fields = BTreeMap::new();
let kind = Some(Kind::StringValue("value".to_string()));
fields.insert("field".to_string(), Value { kind });
// Delete vectors from the namespace "namespace" that satisfy the filter
let response: Result<(), PineconeError> = index.delete_by_filter(Metadata { fields }, &"namespace".into()).await;
Sourcepub async fn fetch(
&mut self,
ids: &[&str],
namespace: &Namespace,
) -> Result<FetchResponse, PineconeError>
pub async fn fetch( &mut self, ids: &[&str], namespace: &Namespace, ) -> Result<FetchResponse, PineconeError>
The fetch operation retrieves vectors by ID from a namespace.
§Arguments
ids: &[&str]
- The ids of vectors to fetch.namespace: &Namespace
- The namespace to fetch vectors from. Default is “”.
§Return
Result<FetchResponse, PineconeError>
§Example
use std::collections::BTreeMap;
use pinecone_sdk::models::{FetchResponse, Metadata, Value, Kind};
let pinecone = pinecone_sdk::pinecone::default_client()?;
let mut index = pinecone.index("index-host").await?;
let vectors = &["1", "2"];
// Fetch vectors from the default namespace that have the ids in the list
let response: Result<FetchResponse, PineconeError> = index.fetch(vectors, &Default::default()).await;
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Index
impl !RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl !UnwindSafe for Index
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request