Skip to content

Update documentation #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pinecone_sdk/src/pinecone/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl PineconeClient {
/// * `timeout: WaitPolicy` - The wait policy for index creation. If the index becomes ready before the specified duration, the function will return early. If the index is not ready after the specified duration, the function will return an error.
///
/// ### Return
/// * Returns a `Result<IndexModel, PineconeError>` object.
/// * Result<IndexModel, PineconeError>`
///
/// ### Example
/// ```no_run
Expand Down Expand Up @@ -336,6 +336,7 @@ impl PineconeClient {
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Configure an index in the project.
/// let response = pinecone.configure_index("index-name", 6, "s1").await;
/// # Ok(())
/// # }
Expand Down Expand Up @@ -371,7 +372,7 @@ impl PineconeClient {
/// * name: &str - The name of the index to be deleted.
///
/// ### Return
/// * Returns a `Result<(), PineconeError>` object.
/// * `Result<(), PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -382,6 +383,7 @@ impl PineconeClient {
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Delete an index in the project.
/// let delete_index_response: Result<(), PineconeError> = pinecone.delete_index("index-name").await;
/// # Ok(())
/// # }
Expand Down Expand Up @@ -445,7 +447,7 @@ impl PineconeClient {
/// * name: &str - The name of the collection to describe.
///
/// ### Return
/// * Returns a `Result<(), PineconeError>` object.
/// * `Result<(), PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -456,6 +458,7 @@ impl PineconeClient {
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Describe a collection in the project.
/// let response = pinecone.describe_collection("collection-name").await;
/// # Ok(())
/// # }
Expand Down Expand Up @@ -504,7 +507,7 @@ impl PineconeClient {
/// * name: &str - The name of the collection to be deleted.
///
/// ### Return
/// * Returns a `Result<(), PineconeError>` object.
/// * `Result<(), PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -515,7 +518,8 @@ impl PineconeClient {
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// /// let response = pinecone.delete_collection("collection-name").await;
/// // Delete a collection in the project.
/// let response = pinecone.delete_collection("collection-name").await;
/// # Ok(())
/// # }
/// ```
Expand Down
74 changes: 51 additions & 23 deletions pinecone_sdk/src/pinecone/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use tonic::{Request, Status};

pub use pb::{
DescribeIndexStatsResponse, FetchResponse, ListResponse, QueryResponse, SparseValues, UpdateResponse,
UpsertResponse, Vector,
DescribeIndexStatsResponse, FetchResponse, ListResponse, QueryResponse, SparseValues,
UpdateResponse, UpsertResponse, Vector,
};
pub use prost_types::{value::Kind, Struct as Metadata, Value};

Expand Down Expand Up @@ -40,7 +40,7 @@
#[derive(Debug)]
pub struct Index {
/// The name of the index.
host: String,

Check warning on line 43 in pinecone_sdk/src/pinecone/data.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

field `host` is never read

Check warning on line 43 in pinecone_sdk/src/pinecone/data.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

field `host` is never read
connection: VectorServiceClient<InterceptedService<Channel, ApiKeyInterceptor>>,
}

Expand Down Expand Up @@ -70,10 +70,11 @@
/// If a new value is upserted for an existing vector id, it will overwrite the previous value.
///
/// ### Arguments
/// * `vectors: Vec<Vector>` - A list of vectors to upsert.
/// * `vectors: &[Vector]` - A list of vectors to upsert.
/// * `namespace: &Namespace` - The namespace to upsert vectors into. Default is "".
///
/// ### Return
/// * `Result<UpsertResponse, PineconeError>` - A response object.
/// * `Result<UpsertResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -85,6 +86,7 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// let vectors = [Vector {
Expand All @@ -93,6 +95,8 @@
/// sparse_values: None,
/// metadata: None,
/// }];
///
/// // Upsert vectors into the namespace "namespace" in the index
/// let response = index.upsert(&vectors, &"namespace".into()).await.unwrap();
/// # Ok(())
/// # }
Expand Down Expand Up @@ -120,13 +124,13 @@
/// 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` - Default is "".
/// * `namespace: &Namespace` - The namespace to list vectors from. Default is "".
/// * `prefix: Option<String>` - The maximum number of vectors to return. If unspecified, the server will use a default value.
/// * `limit: Option<u32>` - The maximum number of vector ids to return. If unspecified, the default limit is 100.
/// * `pagination_token: Option<String>` - The token for paginating through results.
///
/// ### Return
/// * `Result<ListResponse, PineconeError>` - A response object.
/// * `Result<ListResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -138,8 +142,10 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we word this better? "index-host" is the host url of the index rather than the name

/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// // List all vectors in the namespace "namespace"
/// let response = index.list(&"namespace".into(), None, None, None).await.unwrap();
/// # Ok(())
/// # }
Expand Down Expand Up @@ -171,10 +177,10 @@
/// 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. Note that the filter is only supported by pod indexes.
/// * `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
/// * Returns a `Result<DescribeIndexStatsResponse, PineconeError>` object.
/// * `Result<DescribeIndexStatsResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -187,11 +193,14 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// // Construct a metadata filter
/// let mut fields = BTreeMap::new();
/// fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string())) });
///
/// // Describe the index statistics
/// let response = index.describe_index_stats(Some(Metadata { fields })).await.unwrap();
/// # Ok(())
/// # }
Expand All @@ -212,6 +221,7 @@
Ok(response)
}

// Helper function to call query operation
async fn query(&mut self, request: pb::QueryRequest) -> Result<QueryResponse, PineconeError> {
let response = self
.connection
Expand All @@ -231,10 +241,10 @@
/// * `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 "".
/// * `namespace: &Namespace` - The namespace containing the vector to update. Default is "".
///
/// ### Return
/// * `Result<UpsertResponse, PineconeError>` - A response object.
/// * `Result<UpsertResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -246,8 +256,10 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// // Update the vector with id "vector-id" in the namespace "namespace"
/// let response = index.update("vector-id".to_string(), vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await.unwrap();
/// # Ok(())
/// # }
Expand Down Expand Up @@ -283,13 +295,13 @@
/// ### Arguments
/// * `id: String` - The id of the query vector.
/// * `top_k: u32` - The number of results to return.
/// * `namespace: Option<String>` - The namespace to query. If not specified, the default namespace is used.
/// * `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>` - A response object.
/// * `Result<QueryResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -301,8 +313,10 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// // Query the vector with id "vector-id" in the namespace "namespace"
/// let response = index.query_by_id("vector-id".to_string(), 10, &Namespace::default(), None, None, None).await.unwrap();
/// # Ok(())
/// # }
Expand All @@ -323,7 +337,7 @@
filter,
include_values: include_values.unwrap_or(false),
include_metadata: include_metadata.unwrap_or(false),
queries: vec![],

Check warning on line 340 in pinecone_sdk/src/pinecone/data.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

use of deprecated field `pinecone::data::pb::QueryRequest::queries`

Check warning on line 340 in pinecone_sdk/src/pinecone/data.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

use of deprecated field `pinecone::data::pb::QueryRequest::queries`
vector: vec![],
sparse_vector: None,
};
Expand All @@ -337,13 +351,13 @@
/// * `vector: Vec<f32>` - The query vector.
/// * `sparse_vector: Option<SparseValues>` - Vector sparse data.
/// * `top_k: u32` - The number of results to return.
/// * `namespace: Option<String>` - The namespace to query. If not specified, the default namespace is used.
/// * `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>` - A response object.
/// * `Result<QueryResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -355,10 +369,12 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// let vector = vec![1.0, 2.0, 3.0, 4.0];
///
/// // Query the vector in the default namespace
/// let response = index.query_by_value(vector, None, 10, &Namespace::default(), None, None, None).await.unwrap();
/// # Ok(())
/// # }
Expand All @@ -380,7 +396,7 @@
filter,
include_values: include_values.unwrap_or(false),
include_metadata: include_metadata.unwrap_or(false),
queries: vec![],

Check warning on line 399 in pinecone_sdk/src/pinecone/data.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

use of deprecated field `pinecone::data::pb::QueryRequest::queries`

Check warning on line 399 in pinecone_sdk/src/pinecone/data.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

use of deprecated field `pinecone::data::pb::QueryRequest::queries`
vector,
sparse_vector,
};
Expand All @@ -392,10 +408,10 @@
///
/// ### Arguments
/// * `ids: Vec<String>` - List of IDs of vectors to be deleted.
/// * `namespace: Namespace` - The namespace to delete vectors from. Default is "".
/// * `namespace: &Namespace` - The namespace to delete vectors from. Default is "".
///
/// ### Return
/// * Returns a `Result<(), PineconeError>` object.
/// * `Result<(), PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -407,9 +423,12 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// let ids = ["vector-id".to_string()];
///
/// // Delete vectors from the namespace "namespace" that have the ids in the list
/// let response = index.delete_by_id(&ids, &"namespace".into()).await.unwrap();
/// # Ok(())
/// # }
Expand All @@ -432,10 +451,10 @@
/// The delete_all operation deletes all vectors from a namespace.
///
/// ### Arguments
/// * `namespace: Namespace` - The namespace to delete vectors from. Default is "".
/// * `namespace: &Namespace` - The namespace to delete vectors from. Default is "".
///
/// ### Return
/// * Returns a `Result<(), PineconeError>` object.
/// * `Result<(), PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -447,8 +466,10 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// // Delete all vectors from the namespace "namespace"
/// let response = index.delete_all(&"namespace".into()).await.unwrap();
/// # Ok(())
/// # }
Expand All @@ -468,10 +489,10 @@
///
/// ### Arguments
/// * `filter: Metadata` - The filter to specify which vectors to delete.
/// * `namespace: Namespace` - The namespace to delete vectors from.
/// * `namespace: &Namespace` - The namespace to delete vectors from. Default is "".
///
/// ### Return
/// * Returns a `Result<(), PineconeError>` object.
/// * `Result<(), PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -484,11 +505,14 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// // Construct a metadata filter
/// let mut fields = BTreeMap::new();
/// fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string())) });
///
/// // Delete vectors from the namespace "namespace" that satisfy the filter
/// let response = index.delete_by_filter(Metadata { fields }, &"namespace".into()).await.unwrap();
/// # Ok(())
/// # }
Expand Down Expand Up @@ -523,10 +547,10 @@
///
/// ### Arguments
/// * `ids: &[String]` - The ids of vectors to fetch.
/// * `namespace: &Namespace` - The namespace to fetch vectors from.
/// * `namespace: &Namespace` - The namespace to fetch vectors from. Default is "".
///
/// ### Return
/// * Returns a `Result<FetchResponse, PineconeError>` object.
/// * `Result<FetchResponse, PineconeError>`
///
/// ### Example
/// ```no_run
Expand All @@ -539,10 +563,12 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let mut index = pinecone.index("index-host").await.unwrap();
///
/// let vectors = &["1".to_string(), "2".to_string()];
///
/// // Fetch vectors from the default namespace that have the ids in the list
/// let response = index.fetch(vectors, &Default::default()).await.unwrap();
/// Ok(())
/// }
Expand Down Expand Up @@ -599,7 +625,7 @@
/// * `host: &str` - The host of the index to target. If the host does not contain a scheme, it will default to `https://`. If the host does not contain a port, it will default to `443`.
///
/// ### Return
/// * `Result<Index, PineconeError>` - A Pinecone index object.
/// * `Result<Index, PineconeError>`
///
/// ### Example
///
Expand All @@ -611,6 +637,7 @@
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // Connect to the index "index-host"
/// let index = pinecone.index("index-host").await.unwrap();
/// # Ok(())
/// # }
Expand Down Expand Up @@ -638,6 +665,7 @@
Ok(index)
}

// Helper function to create a new index connection
async fn new_index_connection(
&self,
host: String,
Expand Down
Loading
Loading