Struct Index

Source
pub struct Index { /* private fields */ }
Expand description

A client for interacting with a Pinecone index.

Implementations§

Source§

impl Index

Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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§

Source§

impl Debug for Index

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,