From 4aed1850ed7cdeaad9c2391d4403915ba799a35c Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Thu, 18 Jul 2024 11:08:30 -0400 Subject: [PATCH 01/27] Move contributor info to separate file and add outline for readme --- CONTRIBUTING.md | 51 +++++++++++++++++++++++++++++++++++++++++ README.md | 50 +++++++++++++++++----------------------- pinecone_sdk/Cargo.toml | 9 +++++--- 3 files changed, 78 insertions(+), 32 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..60b2ea4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,51 @@ +# Contributing guide + +## Local development + +- [Internal Asana backlog](https://app.asana.com/0/1207449888227387/1207449824366220) + +### Prerequisites + +- Install [homebrew](https://brew.sh/) if you haven't already +- Install `brew install just`. just is a command line tool used to run commands defined inside the project `justfile`. You run commands by passing the command name, for example `just build-openapi`. + +### Clone the repository + +This repository relies on a git submodule to get access to our openapi spec. To clone the repository, use the command: + +``` +git clone --recurse-submodules git@github.com:pinecone-io/pinecone-rust-client.git +``` + +Or, if you have already cloned the repository, you can update the submodules with + +``` +git submodule update --init --recursive +``` + +### Generating code from OpenAPI and Proto specs + +The generated code is already checked into the repository, but it can be regenerated by following these steps. + +You will require access to the `apis` repository. +- Follow setup instructions for the `apis` repository + +OpenAPI + +- You need [Docker Desktop](https://www.docker.com/products/docker-desktop/) in order to generate code using openapi. Look at `codegen/build-oas.sh` to see how this is used. +- `just build-openapi` + - References the spec files from the `codegen/apis` submodule + - Outputs the generated code to `openapi` + +Protobuf +- `brew install protobuf` +- `cargo install protobuf-codegen` and add it to path: `PATH="$HOME/.cargo/bin:$PATH"` +- `just build-proto` + - References the spec files from the `codegen/apis` submodule + - Outputs the generated code to `protos` + +### Build and run + +Build and run the project: +- `cargo build` builds the project +- `cargo test` builds the project and runs tests diff --git a/README.md b/README.md index aeabd9a..2e0163d 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,35 @@ # Pinecone Rust SDK -- [Asana backlog](https://app.asana.com/0/1207449888227387/1207449824366220) +[license information] -# Prerequisites +## Documentation -- You need [Docker Desktop](https://www.docker.com/products/docker-desktop/) in order to generate code using openapi. Look at `codegen/build-oas.sh` to see how this is used. -- Install [homebrew](https://brew.sh/) if you haven't already -- Install `brew install just`. just is a command line tool used to run commands defined inside the project `justfile`. You run commands by passing the command name, for example `just build-openapi`. +[reference the documentation here] -Dependencies for generating code from OpenAPI and protobuf specifications: -- Follow setup instructions for the `apis` repository -- `brew install protobuf` -- `cargo install protobuf-codegen` and add it to path: `PATH="$HOME/.cargo/bin:$PATH"` +### Example code -# Clone the repository +[reference the sample app] -This repository relies on a git submodule to get access to our openapi spec. To clone the repository, use the command: +## Prerequisites -``` -git clone --recurse-submodules git@github.com:pinecone-io/pinecone-rust-client.git -``` +Rust version? -Or, if you have already cloned the repository, you can update the submodules with +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](https://app.pinecone.io). -``` -git submodule update --init --recursive -``` +## Installation -# Build and run +How to install - instruction for getting the package from crates.io -OpenAPI -- The generated code is comitted to the repository, but to regenerate run `just build-openapi` -- References the spec files from the `codegen/apis` submodule -- Outputs the generated code to `openapi` +## Usage -Protobuf -- Code is generated from protobuf during the project build process (`cargo build`) using the build script `build.rs` -- The generated code is outputted to `/target/debug/build/pinecone_sdk-{hash}/out` +Explanation about how environment variables are used -Build and run the project: -- `cargo build` builds the project -- `cargo test` builds the project and runs tests +Proxy config? + +## Indexes + +Sample code for using indexes + +## Collections + +Sample code for using colle diff --git a/pinecone_sdk/Cargo.toml b/pinecone_sdk/Cargo.toml index 9c2c892..69d5e29 100644 --- a/pinecone_sdk/Cargo.toml +++ b/pinecone_sdk/Cargo.toml @@ -2,11 +2,14 @@ name = "pinecone_sdk" version = "0.1.0" edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +description = "Pinecone Rust SDK" +repository = "https://github.com/pinecone-io/pinecone-rust-client" +rust-version = "1.78.0" +readme = "../README.md" +include = ["../protos"] [dependencies] -openapi = { path = "../openapi" } +openapi = { version = "0", path = "../openapi" } tokio = { version = "1", features = ["full"] } regex = "1.10.4" serde_json = "1.0.117" From fb188653d70d3ef05a579ab38d0a7ab869d0eeb8 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 11:15:04 -0400 Subject: [PATCH 02/27] added sample code for serverless index creation + headers --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e0163d..7e505ae 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,51 @@ Explanation about how environment variables are used Proxy config? -## Indexes +### Indexes + +## Create Index + +# Create serverless index +The following example creates a serverless in the `us-east-1` region of AWS. For more information on serverless and regional availability, see [Understanding indexes](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) +``` +use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; +use pinecone_sdk::utils::errors::PineconeError; +use std::time::Duration; + +let pinecone = PineconeClient::new('PINECONE_API_KEY', None, None, None).unwrap(); + +pinecone.create_serverless_index( + "index-name", // Name of the index + 10, // Dimension of the vectors + Metric::Cosine, // Distance metric + Cloud::Aws, // Cloud provider + "us-east-1", // Region + WaitPolicy::NoWait // Timeout +).await; +``` + +# Create pod index + +## List indexes + +## Describe index + +## Delete index + +## Describe index statistics + +## Upsert vectors + +## Query index + +## Delete vectors + +## Fetch vectors + +## Update vectors + +## List vectors + Sample code for using indexes From b26b60d8f774233f03600dfeb3e7d5fcac47d582 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 11:23:12 -0400 Subject: [PATCH 03/27] change headers --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e505ae..6022d90 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,11 @@ Explanation about how environment variables are used Proxy config? -### Indexes +# Indexes ## Create Index -# Create serverless index +### Create serverless index The following example creates a serverless in the `us-east-1` region of AWS. For more information on serverless and regional availability, see [Understanding indexes](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) ``` use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; @@ -49,7 +49,7 @@ pinecone.create_serverless_index( ).await; ``` -# Create pod index +### Create pod index ## List indexes From d86d3d8579c640346238ef3d8c2af74d752d510d Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 11:29:10 -0400 Subject: [PATCH 04/27] add syntax highlighting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6022d90..4c38226 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Proxy config? ### Create serverless index The following example creates a serverless in the `us-east-1` region of AWS. For more information on serverless and regional availability, see [Understanding indexes](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) -``` +```rust use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; use pinecone_sdk::utils::errors::PineconeError; use std::time::Duration; From e85cbec573ffe074da58f823ac922c5dc8b9c6c2 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 11:40:27 -0400 Subject: [PATCH 05/27] add examples for rest of control plane --- README.md | 55 ++++++++++++++++++++++++++-- pinecone_sdk/src/pinecone/control.rs | 6 +-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4c38226..9531325 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,11 @@ Proxy config? ## Create Index ### Create serverless index -The following example creates a serverless in the `us-east-1` region of AWS. For more information on serverless and regional availability, see [Understanding indexes](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) +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](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) ```rust use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; -use pinecone_sdk::utils::errors::PineconeError; -use std::time::Duration; -let pinecone = PineconeClient::new('PINECONE_API_KEY', None, None, None).unwrap(); +let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); pinecone.create_serverless_index( "index-name", // Name of the index @@ -50,12 +48,61 @@ pinecone.create_serverless_index( ``` ### Create pod index +The following example creates a pod index in the `us-east-1` region of AWS. This example does not create replicas, or shards, nor use metadata or a source collection. +```rust +use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy}}; + +let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); + +pinecone.create_pod_index( + "index-name", + 10, + Metric::Cosine, + "us-east-1", + 1, + None, + None, + None, + None, + WaitPolicy::NoWait +).await; +``` ## List indexes +```rust +use pinecone_sdk::pinecone::{ClientClient, control::IndexList}; + +let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); + +pinecone.list_indexes().await; +``` ## Describe index +```rust +use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; + +let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); + +pinecone.describe_index("index-name").await; +``` + +## Configure index +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +pinecone.configure_index("index-name", 6, "s1").await; +``` ## Delete index +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +pinecone.delete_index("index-name").await; +``` ## Describe index statistics diff --git a/pinecone_sdk/src/pinecone/control.rs b/pinecone_sdk/src/pinecone/control.rs index 5c13567..1fcb483 100644 --- a/pinecone_sdk/src/pinecone/control.rs +++ b/pinecone_sdk/src/pinecone/control.rs @@ -132,10 +132,10 @@ impl PineconeClient { /// /// // Create a pod index. /// let create_index_response: Result = pinecone.create_pod_index( - /// "index_name", // Name of the index + /// "index-name", // Name of the index /// 10, // Dimension of the index /// Metric::Cosine, // Distance metric - /// "us-east-1-aws", // Environment + /// "us-east-1", // Environment /// "p1.x1", // Pod type /// 1, // Number of pods /// Some(1), // Number of replicas @@ -336,7 +336,7 @@ impl PineconeClient { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); /// - /// let response = pinecone.configure_index("index-name", 6, "s1").await; + /// let response: Result = pinecone.configure_index("index-name", 6, "s1").await; /// # Ok(()) /// # } /// ``` From 5701196cc9114d4c4acb929464b94bba774142c4 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 11:52:38 -0400 Subject: [PATCH 06/27] fix build error --- README.md | 5 ++--- pinecone_sdk/src/pinecone/control.rs | 1 + pinecone_sdk/src/pinecone/data.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7989a9c..80fa672 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,6 @@ pinecone.delete_index("index-name").await; ## Describe index statistics ## Upsert vectors - ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::Vector; @@ -116,13 +115,13 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); -let vectors = vec![Vector { +let vectors = [Vector { id: "vector-id".to_string(), values: vec![1.0, 2.0, 3.0, 4.0], sparse_values: None, metadata: None, }]; -index.upsert(vectors, None).await.unwrap(); +index.upsert(&vectors, &"namespace".into()).await.unwrap(); ``` ## Query index diff --git a/pinecone_sdk/src/pinecone/control.rs b/pinecone_sdk/src/pinecone/control.rs index 92d200e..666ff7a 100644 --- a/pinecone_sdk/src/pinecone/control.rs +++ b/pinecone_sdk/src/pinecone/control.rs @@ -330,6 +330,7 @@ impl PineconeClient { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; + /// use pinecone_sdk::pinecone::control::IndexModel; /// use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] diff --git a/pinecone_sdk/src/pinecone/data.rs b/pinecone_sdk/src/pinecone/data.rs index aea08f6..af6c50f 100644 --- a/pinecone_sdk/src/pinecone/data.rs +++ b/pinecone_sdk/src/pinecone/data.rs @@ -79,7 +79,7 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::{Namespace, Vector}; + /// use pinecone_sdk::pinecone::data::Vector; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] From c25532f576f1e2126899c665afbc668406f0239e Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 14:08:24 -0400 Subject: [PATCH 07/27] add rest of data plane --- README.md | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80fa672..8c1c7a5 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,34 @@ pinecone.delete_index("index-name").await; ``` ## Describe index statistics +Without filter +```rust +use std::collections::BTreeMap; +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, Namespace}; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +index.describe_index_stats(None).await.unwrap(); +``` + +With filter +```rust +use std::collections::BTreeMap; +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, Namespace}; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +let mut fields = BTreeMap::new(); +fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); + +index.describe_index_stats(Some(Metadata { fields })).await.unwrap(); +``` ## Upsert vectors ```rust @@ -116,22 +144,129 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); let vectors = [Vector { - id: "vector-id".to_string(), + id: "id1".to_string(), values: vec![1.0, 2.0, 3.0, 4.0], sparse_values: None, metadata: None, +}, Vector { + id: "id2".to_string(), + values: vec1![2.0, 3.0, 4.0, 5.0], + sparse_values: None, + metadata: None, }]; index.upsert(&vectors, &"namespace".into()).await.unwrap(); ``` ## Query index +### Query by index +```rust +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::Namespace; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +// Connect to index host url +let mut index = pinecone.index("index-host").await.unwrap(); + +// Query the vector with id "vector-id" in the namespace "namespace" +index.query_by_id( + "vector-id".to_string(), + 10, + &Namespace::default(), + None, + None, + None +).await.unwrap(); +``` + +### Query by value +```rust +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +let vector = vec![1.0, 2.0, 3.0, 4.0]; + +index.query_by_value( + vector, + None, + 10, + &Namespace::default(), + None, + None, + None +).await.unwrap(); +``` ## Delete vectors +By ID: +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +let ids = ["vector-id"] +index.delete_by_id(&ids, &"namespace".into()).await.unwrap(); +``` + +By filter: +```rust +use std::collections::BTreeMap; +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::{Metadata, Value, Kind, Namespace}; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut fields = BTreeMap::new(); +fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); +index.delete_by_filter(Metadata { fields }, &"namespace".into()).await.unwrap(); +``` + +Delete all: +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +index.delete_all(&"namespace".into()).await.unwrap(); +``` ## Fetch vectors +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +index.fetch(vectors, &Default::default()).await.unwrap(); +``` ## Update vectors +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await.unwrap(); +``` ## List vectors +```rust +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::Namespace; + +let pinecone = PineconeClient::new("index-host").await.unwrap(); + +let mut index = pinecone.index("index-host").await.unwrap(); + +index.list(&"namespace".into(), None, None, None).await.unwrap(); +``` # Collections From 85b0d1232855b0f3c2919c30c5e44d9496b86022 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 16:18:14 -0400 Subject: [PATCH 08/27] added collections operations --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 8c1c7a5..a541227 100644 --- a/README.md +++ b/README.md @@ -270,3 +270,38 @@ index.list(&"namespace".into(), None, None, None).await.unwrap(); ``` # Collections +## Create collection +```rust +use pinecone_sdk::pinecone::{PineconeClient, control::CollectionModel}; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let create_collection_response = pinecone.create_collection("collection-name", "index-name").await; +``` + +## List collections +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let response = pinecone.list_collections().await; +``` + +## Describe collection +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let response = pinecone.describe_collection("collection-name").await; +``` + +## Delete collection +```rust +use pinecone_sdk::pinecone::PineconeClient; + +let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + +let response = pinecone.delete_collection("collection-name").await; +``` From 2ff98bac0a55b7ea17d2e24d5d5b307800fc745b Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 23 Jul 2024 16:25:01 -0400 Subject: [PATCH 09/27] added match statement to sample code --- README.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 128 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a541227..d48448f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); -pinecone.create_serverless_index( +let response = pinecone.create_serverless_index( "index-name", // Name of the index 10, // Dimension of the vectors Metric::Cosine, // Distance metric @@ -45,6 +45,11 @@ pinecone.create_serverless_index( "us-east-1", // Region WaitPolicy::NoWait // Timeout ).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ### Create pod index @@ -54,7 +59,7 @@ use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); -pinecone.create_pod_index( +let response = pinecone.create_pod_index( "index-name", 10, Metric::Cosine, @@ -66,6 +71,11 @@ pinecone.create_pod_index( None, WaitPolicy::NoWait ).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## List indexes @@ -74,7 +84,12 @@ use pinecone_sdk::pinecone::{ClientClient, control::IndexList}; let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); -pinecone.list_indexes().await; +let response = pinecone.list_indexes().await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Describe index @@ -83,7 +98,12 @@ use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); -pinecone.describe_index("index-name").await; +let response = pinecone.describe_index("index-name").await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Configure index @@ -92,7 +112,12 @@ use pinecone_sdk::pinecone::PineconeClient; let pinecone = PineconeClient::new(None, None, None, None).unwrap(); -pinecone.configure_index("index-name", 6, "s1").await; +let response = pinecone.configure_index("index-name", 6, "s1").await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Delete index @@ -101,7 +126,12 @@ use pinecone_sdk::pinecone::PineconeClient; let pinecone = PineconeClient::new(None, None, None, None).unwrap(); -pinecone.delete_index("index-name").await; +let response = pinecone.delete_index("index-name").await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Describe index statistics @@ -115,7 +145,12 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); -index.describe_index_stats(None).await.unwrap(); +let response = index.describe_index_stats(None).await.unwrap(); + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` With filter @@ -131,7 +166,12 @@ let mut index = pinecone.index("index-host").await.unwrap(); let mut fields = BTreeMap::new(); fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); -index.describe_index_stats(Some(Metadata { fields })).await.unwrap(); +let response = index.describe_index_stats(Some(Metadata { fields })).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Upsert vectors @@ -154,7 +194,13 @@ let vectors = [Vector { sparse_values: None, metadata: None, }]; -index.upsert(&vectors, &"namespace".into()).await.unwrap(); + +let response = index.upsert(&vectors, &"namespace".into()).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Query index @@ -169,14 +215,19 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); // Query the vector with id "vector-id" in the namespace "namespace" -index.query_by_id( +let response = index.query_by_id( "vector-id".to_string(), 10, &Namespace::default(), None, None, None -).await.unwrap(); +).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ### Query by value @@ -187,7 +238,7 @@ let mut index = pinecone.index("index-host").await.unwrap(); let vector = vec![1.0, 2.0, 3.0, 4.0]; -index.query_by_value( +let response = index.query_by_value( vector, None, 10, @@ -195,7 +246,12 @@ index.query_by_value( None, None, None -).await.unwrap(); +).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Delete vectors @@ -208,7 +264,13 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); let ids = ["vector-id"] -index.delete_by_id(&ids, &"namespace".into()).await.unwrap(); + +let response = index.delete_by_id(&ids, &"namespace".into()).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` By filter: @@ -221,7 +283,13 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut fields = BTreeMap::new(); fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); -index.delete_by_filter(Metadata { fields }, &"namespace".into()).await.unwrap(); + +let response = index.delete_by_filter(Metadata { fields }, &"namespace".into()).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` Delete all: @@ -232,7 +300,12 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); -index.delete_all(&"namespace".into()).await.unwrap(); +let response = index.delete_all(&"namespace".into()).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Fetch vectors @@ -243,7 +316,12 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); -index.fetch(vectors, &Default::default()).await.unwrap(); +let response = index.fetch(vectors, &Default::default()).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Update vectors @@ -254,7 +332,12 @@ let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); -index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await.unwrap(); +let response = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## List vectors @@ -266,7 +349,12 @@ let pinecone = PineconeClient::new("index-host").await.unwrap(); let mut index = pinecone.index("index-host").await.unwrap(); -index.list(&"namespace".into(), None, None, None).await.unwrap(); +let response = index.list(&"namespace".into(), None, None, None).await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` # Collections @@ -276,7 +364,12 @@ use pinecone_sdk::pinecone::{PineconeClient, control::CollectionModel}; let pinecone = PineconeClient::new(None, None, None, None).unwrap(); -let create_collection_response = pinecone.create_collection("collection-name", "index-name").await; +let response = pinecone.create_collection("collection-name", "index-name").await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## List collections @@ -286,6 +379,11 @@ use pinecone_sdk::pinecone::PineconeClient; let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let response = pinecone.list_collections().await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Describe collection @@ -295,6 +393,11 @@ use pinecone_sdk::pinecone::PineconeClient; let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let response = pinecone.describe_collection("collection-name").await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` ## Delete collection @@ -304,4 +407,9 @@ use pinecone_sdk::pinecone::PineconeClient; let pinecone = PineconeClient::new(None, None, None, None).unwrap(); let response = pinecone.delete_collection("collection-name").await; + +match response { + Ok(_) => println!("success"), + Err(_) => println!("error"), +}; ``` From 35e97f7ac93afb2f3f2d12d8a0ea3d7ca693b160 Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Wed, 24 Jul 2024 09:24:16 -0400 Subject: [PATCH 10/27] Update docstrings to use ? instead of unwrap --- README.md | 280 ++++++++----------------- pinecone_sdk/src/pinecone/control.rs | 48 ++--- pinecone_sdk/src/pinecone/data.rs | 80 +++---- pinecone_sdk/tests/integration_test.rs | 10 +- 4 files changed, 161 insertions(+), 257 deletions(-) diff --git a/README.md b/README.md index d48448f..8925bab 100644 --- a/README.md +++ b/README.md @@ -33,105 +33,76 @@ Proxy config? ### 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](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) ```rust -use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy}}; +use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; -let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); +let pinecone = PineconeClient::new('<>', None, None, None)?; -let response = pinecone.create_serverless_index( - "index-name", // Name of the index - 10, // Dimension of the vectors - Metric::Cosine, // Distance metric - Cloud::Aws, // Cloud provider - "us-east-1", // Region - WaitPolicy::NoWait // Timeout -).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: IndexModel = pinecone.create_serverless_index( + "index-name", // Name of the index + 10, // Dimension of the vectors + Metric::Cosine, // Distance metric + Cloud::Aws, // Cloud provider + "us-east-1", // Region + WaitPolicy::NoWait // Timeout +).await?; ``` ### Create pod index The following example creates a pod index in the `us-east-1` region of AWS. This example does not create replicas, or shards, nor use metadata or a source collection. ```rust -use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy}}; - -let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); - -let response = pinecone.create_pod_index( - "index-name", - 10, - Metric::Cosine, - "us-east-1", - 1, - None, - None, - None, - None, - WaitPolicy::NoWait -).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; + +let pinecone = PineconeClient::new('<>', None, None, None)?; + +let response: IndexModel = pinecone.create_pod_index( + "index-name", // index name + 10, // dimension + Metric::Cosine, // distance metric + "us-east-1", // region + "p1.x1", // pod type + 1, // number of pods + None, // number of replicas + None, // number of shards + None, // metadata + None, // source collection + WaitPolicy::NoWait // wait policy +).await?; ``` ## List indexes ```rust use pinecone_sdk::pinecone::{ClientClient, control::IndexList}; -let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); +let pinecone = PineconeClient::new('<>', None, None, None)?; -let response = pinecone.list_indexes().await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: IndexList = pinecone.list_indexes().await?; ``` ## Describe index ```rust use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; -let pinecone = PineconeClient::new('<>', None, None, None).unwrap(); - -let response = pinecone.describe_index("index-name").await; +let pinecone = PineconeClient::new('<>', None, None, None)?; -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: IndexModel = pinecone.describe_index("index-name").await?; ``` ## Configure index ```rust -use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let response = pinecone.configure_index("index-name", 6, "s1").await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; ``` ## Delete index ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let response = pinecone.delete_index("index-name").await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +pinecone.delete_index("index-name").await?; ``` ## Describe index statistics @@ -139,49 +110,39 @@ Without filter ```rust use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; -use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, Namespace}; +use pinecone_sdk::pinecone::data::DescribeIndexStatsResponse; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; -let response = index.describe_index_stats(None).await.unwrap(); - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: DescribeIndexStatsResponse = index.describe_index_stats(None).await?; ``` With filter ```rust use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; -use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, Namespace}; +use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, DescribeIndexStatsResponse}; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; let mut fields = BTreeMap::new(); fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); -let response = index.describe_index_stats(Some(Metadata { fields })).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: DescribeIndexStatsResponse = index.describe_index_stats(Some(Metadata { fields })).await?; ``` ## Upsert vectors ```rust use pinecone_sdk::pinecone::PineconeClient; -use pinecone_sdk::pinecone::data::Vector; +use pinecone_sdk::pinecone::data::{Vector, UpsertResponse}; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; let vectors = [Vector { id: "id1".to_string(), @@ -195,50 +156,43 @@ let vectors = [Vector { metadata: None, }]; -let response = index.upsert(&vectors, &"namespace".into()).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: UpsertResponse = index.upsert(&vectors, &"namespace".into()).await?; ``` ## Query index ### Query by index ```rust use pinecone_sdk::pinecone::PineconeClient; -use pinecone_sdk::pinecone::data::Namespace; +use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; // Connect to index host url -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; // Query the vector with id "vector-id" in the namespace "namespace" -let response = index.query_by_id( +let response: QueryResponse = index.query_by_id( "vector-id".to_string(), 10, &Namespace::default(), None, None, None -).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +).await?; ``` ### Query by value ```rust -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; + +let pinecone = PineconeClient::new(None, None, None, None)?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; let vector = vec![1.0, 2.0, 3.0, 4.0]; -let response = index.query_by_value( +let response: QueryResponse = index.query_by_value( vector, None, 10, @@ -246,12 +200,7 @@ let response = index.query_by_value( None, None, None -).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +).await?; ``` ## Delete vectors @@ -259,18 +208,13 @@ By ID: ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; let ids = ["vector-id"] -let response = index.delete_by_id(&ids, &"namespace".into()).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +index.delete_by_id(&ids, &"namespace".into()).await?; ``` By filter: @@ -279,137 +223,97 @@ use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Metadata, Value, Kind, Namespace}; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; let mut fields = BTreeMap::new(); fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); -let response = index.delete_by_filter(Metadata { fields }, &"namespace".into()).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +index.delete_by_filter(Metadata { fields }, &"namespace".into()).await?; ``` Delete all: ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); - -let mut index = pinecone.index("index-host").await.unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let response = index.delete_all(&"namespace".into()).await; +let mut index = pinecone.index("index-host").await?; -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +index.delete_all(&"namespace".into()).await?; ``` ## Fetch vectors ```rust use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::FetchResponse; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; -let response = index.fetch(vectors, &Default::default()).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: FetchResponse = index.fetch(vectors, &Default::default()).await?; ``` ## Update vectors ```rust use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::data::UpdateResponse; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); - -let mut index = pinecone.index("index-host").await.unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let response = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await; +let mut index = pinecone.index("index-host").await?; -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: UpdateResponse = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await?; ``` ## List vectors ```rust use pinecone_sdk::pinecone::PineconeClient; -use pinecone_sdk::pinecone::data::Namespace; +use pinecone_sdk::pinecone::data::{Namespace, ListResponse}; -let pinecone = PineconeClient::new("index-host").await.unwrap(); +let pinecone = PineconeClient::new("index-host").await?; -let mut index = pinecone.index("index-host").await.unwrap(); +let mut index = pinecone.index("index-host").await?; -let response = index.list(&"namespace".into(), None, None, None).await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: ListResponse = index.list(&"namespace".into(), None, None, None).await?; ``` # Collections ## Create collection ```rust -use pinecone_sdk::pinecone::{PineconeClient, control::CollectionModel}; - -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::control::CollectionModel; -let response = pinecone.create_collection("collection-name", "index-name").await; +let pinecone = PineconeClient::new(None, None, None, None)?; -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; ``` ## List collections ```rust use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::control::CollectionList; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); - -let response = pinecone.list_collections().await; +let pinecone = PineconeClient::new(None, None, None, None)?; -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: CollectionList = pinecone.list_collections().await?; ``` ## Describe collection ```rust use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::control::CollectionModel; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); +let pinecone = PineconeClient::new(None, None, None, None)?; -let response = pinecone.describe_collection("collection-name").await; - -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +let response: CollectionModel = pinecone.describe_collection("collection-name").await?; ``` ## Delete collection ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None).unwrap(); - -let response = pinecone.delete_collection("collection-name").await; +let pinecone = PineconeClient::new(None, None, None, None)?; -match response { - Ok(_) => println!("success"), - Err(_) => println!("error"), -}; +pinecone.delete_collection("collection-name").await?; ``` diff --git a/pinecone_sdk/src/pinecone/control.rs b/pinecone_sdk/src/pinecone/control.rs index 666ff7a..75e5519 100644 --- a/pinecone_sdk/src/pinecone/control.rs +++ b/pinecone_sdk/src/pinecone/control.rs @@ -50,17 +50,17 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Create an index. - /// let create_index_response: Result = pinecone.create_serverless_index( + /// let response: IndexModel = pinecone.create_serverless_index( /// "index-name", // Name of the index /// 10, // Dimension of the vectors /// Metric::Cosine, // Distance metric /// Cloud::Aws, // Cloud provider /// "us-east-1", // Region /// WaitPolicy::NoWait // Timeout - /// ).await; + /// ).await?; /// /// # Ok(()) /// # } @@ -128,10 +128,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError> { - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Create a pod index. - /// let create_index_response: Result = pinecone.create_pod_index( + /// let create_index_response: IndexModel = pinecone.create_pod_index( /// "index-name", // Name of the index /// 10, // Dimension of the index /// Metric::Cosine, // Distance metric @@ -147,7 +147,7 @@ impl PineconeClient { /// Some("example-collection"), // Source collection /// WaitPolicy::WaitFor(Duration::from_secs(10)), // Timeout /// ) - /// .await; + /// .await?; /// # Ok(()) /// # } /// ``` @@ -266,10 +266,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Describe an index in the project. - /// let describe_index_response: Result = pinecone.describe_index("index-name").await; + /// let describe_index_response: IndexModel = pinecone.describe_index("index-name").await?; /// # Ok(()) /// # } /// ``` @@ -297,10 +297,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // List all indexes in the project. - /// let index_list_response: Result = pinecone.list_indexes().await; + /// let index_list_response: IndexList = pinecone.list_indexes().await?; /// # Ok(()) /// # } /// ``` @@ -335,10 +335,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Configure an index in the project. - /// let response: Result = pinecone.configure_index("index-name", 6, "s1").await; + /// let response: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; /// # Ok(()) /// # } /// ``` @@ -382,10 +382,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Delete an index in the project. - /// let delete_index_response: Result<(), PineconeError> = pinecone.delete_index("index-name").await; + /// pinecone.delete_index("index-name").await?; /// # Ok(()) /// # } /// ``` @@ -414,10 +414,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Describe an index in the project. - /// let create_collection_response: Result = pinecone.create_collection("collection-name", "index-name").await; + /// let create_collection_response: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; /// # Ok(()) /// # } /// ``` @@ -452,15 +452,15 @@ impl PineconeClient { /// /// ### Example /// ```no_run - /// use pinecone_sdk::pinecone::PineconeClient; + /// use pinecone_sdk::pinecone::{PineconeClient, control::CollectionModel}; /// use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Describe a collection in the project. - /// let response = pinecone.describe_collection("collection-name").await; + /// let response: CollectionModel = pinecone.describe_collection("collection-name").await?; /// # Ok(()) /// # } /// ``` @@ -481,15 +481,15 @@ impl PineconeClient { /// /// ### Example /// ```no_run - /// use pinecone_sdk::pinecone::PineconeClient; + /// use pinecone_sdk::pinecone::{PineconeClient, control::CollectionList}; /// use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // List all collections in the project. - /// let collection_list = pinecone.list_collections().await.unwrap(); + /// let collection_list: CollectionList = pinecone.list_collections().await?; /// # Ok(()) /// # } /// ``` @@ -517,10 +517,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Delete a collection in the project. - /// let response = pinecone.delete_collection("collection-name").await; + /// pinecone.delete_collection("collection-name").await?; /// # Ok(()) /// # } /// ``` diff --git a/pinecone_sdk/src/pinecone/data.rs b/pinecone_sdk/src/pinecone/data.rs index af6c50f..eac953b 100644 --- a/pinecone_sdk/src/pinecone/data.rs +++ b/pinecone_sdk/src/pinecone/data.rs @@ -79,15 +79,15 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::Vector; + /// use pinecone_sdk::pinecone::data::{Vector, UpsertResponse}; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// let vectors = [Vector { /// id: "vector-id".to_string(), @@ -97,7 +97,7 @@ impl Index { /// }]; /// /// // Upsert vectors into the namespace "namespace" in the index - /// let response = index.upsert(&vectors, &"namespace".into()).await.unwrap(); + /// let response: UpsertResponse = index.upsert(&vectors, &"namespace".into()).await?; /// # Ok(()) /// # } /// ``` @@ -135,18 +135,18 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::Namespace; + /// use pinecone_sdk::pinecone::data::ListResponse; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// // List all vectors in the namespace "namespace" - /// let response = index.list(&"namespace".into(), None, None, None).await.unwrap(); + /// let response: ListResponse = index.list(&"namespace".into(), None, None, None).await?; /// # Ok(()) /// # } /// ``` @@ -186,22 +186,22 @@ impl Index { /// ```no_run /// use std::collections::BTreeMap; /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, Namespace}; + /// use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, DescribeIndexStatsResponse}; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// // 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(); + /// let response: DescribeIndexStatsResponse = index.describe_index_stats(Some(Metadata { fields })).await?; /// # Ok(()) /// # } /// ``` @@ -249,18 +249,18 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::{Namespace, SparseValues, Metadata}; + /// use pinecone_sdk::pinecone::data::{Namespace, SparseValues, Metadata, UpdateResponse}; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// // Update the vector with id "vector-id" in the namespace "namespace" - /// let response = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await.unwrap(); + /// let response: UpdateResponse = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await?; /// # Ok(()) /// # } /// ``` @@ -306,18 +306,18 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::Namespace; + /// use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// - /// // 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(); + /// // Query the vector with id "vector-id" in the default namespace + /// let response: QueryResponse = index.query_by_id("vector-id".to_string(), 10, &Namespace::default(), None, None, None).await?; /// # Ok(()) /// # } /// ``` @@ -362,20 +362,20 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::Namespace; + /// use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// 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 = index.query_by_value(vector, None, 10, &Namespace::default(), None, None, None).await.unwrap(); + /// let response: QueryResponse = index.query_by_value(vector, None, 10, &Namespace::default(), None, None, None).await?; /// # Ok(()) /// # } /// ``` @@ -421,15 +421,15 @@ impl Index { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// 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 = index.delete_by_id(&ids, &"namespace".into()).await.unwrap(); + /// index.delete_by_id(&ids, &"namespace".into()).await?; /// # Ok(()) /// # } /// ``` @@ -465,13 +465,13 @@ impl Index { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// // Delete all vectors from the namespace "namespace" - /// let response = index.delete_all(&"namespace".into()).await.unwrap(); + /// index.delete_all(&"namespace".into()).await?; /// # Ok(()) /// # } /// ``` @@ -504,17 +504,17 @@ impl Index { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// // 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(); + /// index.delete_by_filter(Metadata { fields }, &"namespace".into()).await?; /// # Ok(()) /// # } /// ``` @@ -557,20 +557,20 @@ impl Index { /// ```no_run /// use std::collections::BTreeMap; /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::{Metadata, Value, Kind}; + /// use pinecone_sdk::pinecone::data::{Metadata, Value, Kind, FetchResponse}; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url - /// let mut index = pinecone.index("index-host").await.unwrap(); + /// let mut index = pinecone.index("index-host").await?; /// /// 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(); + /// let response: FetchResponse = index.fetch(vectors, &Default::default()).await?; /// Ok(()) /// } /// ``` @@ -636,10 +636,10 @@ impl PineconeClient { /// /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ - /// let pinecone = PineconeClient::new(None, None, None, None).unwrap(); + /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Connect to index host url "index-host" - /// let index = pinecone.index("index-host").await.unwrap(); + /// let index = pinecone.index("index-host").await?; /// # Ok(()) /// # } /// ``` diff --git a/pinecone_sdk/tests/integration_test.rs b/pinecone_sdk/tests/integration_test.rs index add5a9c..1a124fd 100644 --- a/pinecone_sdk/tests/integration_test.rs +++ b/pinecone_sdk/tests/integration_test.rs @@ -982,10 +982,7 @@ async fn test_fetch_vectors() -> Result<(), PineconeError> { std::thread::sleep(std::time::Duration::from_secs(5)); let fetch_response = index - .fetch( - &["1".to_string(), "2".to_string()], - namespace, - ) + .fetch(&["1".to_string(), "2".to_string()], namespace) .await .expect("Failed to fetch vectors"); @@ -1034,7 +1031,10 @@ async fn test_fetch_no_match() -> Result<(), PineconeError> { .expect("Failed to target index"); let fetch_response = index - .fetch(&["invalid-id1".to_string(), "invalid-id2".to_string()], &Default::default()) + .fetch( + &["invalid-id1".to_string(), "invalid-id2".to_string()], + &Default::default(), + ) .await .expect("Failed to fetch vectors"); From 38a1931296bc43d8a7cba9bb27501e1d0a5632c5 Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Wed, 24 Jul 2024 09:37:09 -0400 Subject: [PATCH 11/27] Make response variable names consistent --- README.md | 44 +++++++++++++--------------- pinecone_sdk/src/pinecone/control.rs | 14 ++++----- pinecone_sdk/src/pinecone/data.rs | 13 +------- 3 files changed, 29 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 8925bab..cda865c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Pinecone Rust SDK -[license information] - ## Documentation [reference the documentation here] @@ -37,7 +35,7 @@ use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy let pinecone = PineconeClient::new('<>', None, None, None)?; -let response: IndexModel = pinecone.create_serverless_index( +let index_description: IndexModel = pinecone.create_serverless_index( "index-name", // Name of the index 10, // Dimension of the vectors Metric::Cosine, // Distance metric @@ -48,24 +46,24 @@ let response: IndexModel = pinecone.create_serverless_index( ``` ### Create pod index -The following example creates a pod index in the `us-east-1` region of AWS. This example does not create replicas, or shards, nor use metadata or a source collection. +The following example creates a pod index in the `us-east-1` region of AWS. ```rust use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; let pinecone = PineconeClient::new('<>', None, None, None)?; -let response: IndexModel = pinecone.create_pod_index( - "index-name", // index name - 10, // dimension - Metric::Cosine, // distance metric - "us-east-1", // region - "p1.x1", // pod type - 1, // number of pods - None, // number of replicas - None, // number of shards - None, // metadata - None, // source collection - WaitPolicy::NoWait // wait policy +let index_description: IndexModel = pinecone.create_pod_index( + "index-name", // Index name + 10, // Dimension + Metric::Cosine, // Distance metric + "us-east-1", // Region + "p1.x1", // Pod type + 1, // Number of pods + None, // Number of replicas + None, // Number of shards + None, // Metadata to index + None, // Source collection + WaitPolicy::NoWait // Wait policy ).await?; ``` @@ -75,7 +73,7 @@ use pinecone_sdk::pinecone::{ClientClient, control::IndexList}; let pinecone = PineconeClient::new('<>', None, None, None)?; -let response: IndexList = pinecone.list_indexes().await?; +let index_list: IndexList = pinecone.list_indexes().await?; ``` ## Describe index @@ -84,7 +82,7 @@ use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; let pinecone = PineconeClient::new('<>', None, None, None)?; -let response: IndexModel = pinecone.describe_index("index-name").await?; +let index_description: IndexModel = pinecone.describe_index("index-name").await?; ``` ## Configure index @@ -93,7 +91,7 @@ use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; let pinecone = PineconeClient::new(None, None, None, None)?; -let response: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; +let index_description: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; ``` ## Delete index @@ -167,7 +165,7 @@ use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; let pinecone = PineconeClient::new(None, None, None, None)?; -// Connect to index host url +// Connect to index at host "index-host" let mut index = pinecone.index("index-host").await?; // Query the vector with id "vector-id" in the namespace "namespace" @@ -286,7 +284,7 @@ use pinecone_sdk::pinecone::control::CollectionModel; let pinecone = PineconeClient::new(None, None, None, None)?; -let response: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; +let collection: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; ``` ## List collections @@ -296,7 +294,7 @@ use pinecone_sdk::pinecone::control::CollectionList; let pinecone = PineconeClient::new(None, None, None, None)?; -let response: CollectionList = pinecone.list_collections().await?; +let collection_list: CollectionList = pinecone.list_collections().await?; ``` ## Describe collection @@ -306,7 +304,7 @@ use pinecone_sdk::pinecone::control::CollectionModel; let pinecone = PineconeClient::new(None, None, None, None)?; -let response: CollectionModel = pinecone.describe_collection("collection-name").await?; +let collection: CollectionModel = pinecone.describe_collection("collection-name").await?; ``` ## Delete collection diff --git a/pinecone_sdk/src/pinecone/control.rs b/pinecone_sdk/src/pinecone/control.rs index 75e5519..10615ab 100644 --- a/pinecone_sdk/src/pinecone/control.rs +++ b/pinecone_sdk/src/pinecone/control.rs @@ -53,7 +53,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Create an index. - /// let response: IndexModel = pinecone.create_serverless_index( + /// let index_description: IndexModel = pinecone.create_serverless_index( /// "index-name", // Name of the index /// 10, // Dimension of the vectors /// Metric::Cosine, // Distance metric @@ -131,7 +131,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Create a pod index. - /// let create_index_response: IndexModel = pinecone.create_pod_index( + /// let index_description: IndexModel = pinecone.create_pod_index( /// "index-name", // Name of the index /// 10, // Dimension of the index /// Metric::Cosine, // Distance metric @@ -269,7 +269,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Describe an index in the project. - /// let describe_index_response: IndexModel = pinecone.describe_index("index-name").await?; + /// let index_description: IndexModel = pinecone.describe_index("index-name").await?; /// # Ok(()) /// # } /// ``` @@ -300,7 +300,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // List all indexes in the project. - /// let index_list_response: IndexList = pinecone.list_indexes().await?; + /// let index_list: IndexList = pinecone.list_indexes().await?; /// # Ok(()) /// # } /// ``` @@ -338,7 +338,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Configure an index in the project. - /// let response: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; + /// let updated_index: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; /// # Ok(()) /// # } /// ``` @@ -417,7 +417,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Describe an index in the project. - /// let create_collection_response: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; + /// let collection: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; /// # Ok(()) /// # } /// ``` @@ -460,7 +460,7 @@ impl PineconeClient { /// let pinecone = PineconeClient::new(None, None, None, None)?; /// /// // Describe a collection in the project. - /// let response: CollectionModel = pinecone.describe_collection("collection-name").await?; + /// let collection: CollectionModel = pinecone.describe_collection("collection-name").await?; /// # Ok(()) /// # } /// ``` diff --git a/pinecone_sdk/src/pinecone/data.rs b/pinecone_sdk/src/pinecone/data.rs index eac953b..427e517 100644 --- a/pinecone_sdk/src/pinecone/data.rs +++ b/pinecone_sdk/src/pinecone/data.rs @@ -86,7 +86,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// let vectors = [Vector { @@ -142,7 +141,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// // List all vectors in the namespace "namespace" @@ -193,7 +191,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// // Construct a metadata filter @@ -256,7 +253,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// // Update the vector with id "vector-id" in the namespace "namespace" @@ -313,7 +309,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// // Query the vector with id "vector-id" in the default namespace @@ -369,7 +364,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// let vector = vec![1.0, 2.0, 3.0, 4.0]; @@ -423,7 +417,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// let ids = ["vector-id"]; @@ -467,7 +460,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// // Delete all vectors from the namespace "namespace" @@ -506,7 +498,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// // Construct a metadata filter @@ -564,7 +555,6 @@ impl Index { /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; /// - /// // Connect to index host url /// let mut index = pinecone.index("index-host").await?; /// /// let vectors = &["1".to_string(), "2".to_string()]; @@ -637,8 +627,7 @@ impl PineconeClient { /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; - /// - /// // Connect to index host url "index-host" + /// "index-host" /// let index = pinecone.index("index-host").await?; /// # Ok(()) /// # } From f6b843f456c3cf032d7c73add216752022f71cf9 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:10:51 -0400 Subject: [PATCH 12/27] add some descriptions --- README.md | 81 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index cda865c..a7ae4e2 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ Proxy config? ### 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](https://docs.pinecone.io/guides/indexes/understanding-indexes#serverless-indexes) ```rust -use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::control::{Metric, Cloud, WaitPolicy, IndexModel}; let pinecone = PineconeClient::new('<>', None, None, None)?; @@ -48,7 +49,8 @@ let index_description: IndexModel = pinecone.create_serverless_index( ### Create pod index The following example creates a pod index in the `us-east-1` region of AWS. ```rust -use pinecone_sdk::pinecone::{PineconeClient, control::{Metric, Cloud, WaitPolicy, IndexModel}}; +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::control::{Metric, Cloud, WaitPolicy, IndexModel}; let pinecone = PineconeClient::new('<>', None, None, None)?; @@ -67,7 +69,33 @@ 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. +```rust +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::pinecone::control::{Metric, Cloud, WaitPolicy, IndexModel}; + +let pinecone = PineconeClient::new('<>', None, None, None)?; + +let index_description: IndexModel = pinecone.create_pod_index( + "index-name", // Index name + 10, // Dimension + Metric::Cosine, // Distance metric + "us-east-1", // Region + "p1.x1", // Pod type + 1, // Number of pods + Some(1), // Number of replicas + Some(1), // Number of shards + Some( // Metadata fields to index + &vec!["genre", + "title", + "imdb_rating"]), + Some("collection"), // Source collection + WaitPolicy::NoWait // Wait policy +).await?; +``` + ## List indexes +The following example lists all indexes in your project. ```rust use pinecone_sdk::pinecone::{ClientClient, control::IndexList}; @@ -77,6 +105,7 @@ let index_list: IndexList = pinecone.list_indexes().await?; ``` ## Describe index +The following example returns information about the index `index-name`. ```rust use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; @@ -86,31 +115,34 @@ let index_description: IndexModel = pinecone.describe_index("index-name").await? ``` ## Configure index +The following example changes the index `index-name` to have 6 replicas and pod type `s1`. ```rust use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let index_description: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; ``` ## Delete index +The following example deletes the index `index-name`. ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; pinecone.delete_index("index-name").await?; ``` ## Describe index statistics +The following example returns statistics about the index with host `index-host`. Without filter ```rust use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::DescribeIndexStatsResponse; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -123,7 +155,7 @@ use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Value, Kind, Metadata, DescribeIndexStatsResponse}; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -134,11 +166,12 @@ let response: DescribeIndexStatsResponse = index.describe_index_stats(Some(Metad ``` ## Upsert vectors +The following example upserts two vectors into the index with host `index-host`. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Vector, UpsertResponse}; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -157,13 +190,14 @@ let vectors = [Vector { let response: UpsertResponse = index.upsert(&vectors, &"namespace".into()).await?; ``` -## Query index +## Query vectors ### 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. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; // Connect to index at host "index-host" let mut index = pinecone.index("index-host").await?; @@ -180,11 +214,12 @@ let response: QueryResponse = index.query_by_id( ``` ### 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. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Namespace, QueryResponse}; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -202,11 +237,11 @@ let response: QueryResponse = index.query_by_value( ``` ## Delete vectors -By ID: +### Delete by ID: ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -215,13 +250,13 @@ let ids = ["vector-id"] index.delete_by_id(&ids, &"namespace".into()).await?; ``` -By filter: +### Delete by filter: ```rust use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Metadata, Value, Kind, Namespace}; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut fields = BTreeMap::new(); fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); @@ -229,11 +264,11 @@ fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value". index.delete_by_filter(Metadata { fields }, &"namespace".into()).await?; ``` -Delete all: +### Delete all: ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -245,7 +280,7 @@ index.delete_all(&"namespace".into()).await?; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::FetchResponse; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -257,7 +292,7 @@ let response: FetchResponse = index.fetch(vectors, &Default::default()).await?; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::UpdateResponse; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -269,7 +304,7 @@ let response: UpdateResponse = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0 use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Namespace, ListResponse}; -let pinecone = PineconeClient::new("index-host").await?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; @@ -282,7 +317,7 @@ let response: ListResponse = index.list(&"namespace".into(), None, None, None).a use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::control::CollectionModel; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let collection: CollectionModel = pinecone.create_collection("collection-name", "index-name").await?; ``` @@ -292,7 +327,7 @@ let collection: CollectionModel = pinecone.create_collection("collection-name", use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::control::CollectionList; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let collection_list: CollectionList = pinecone.list_collections().await?; ``` @@ -302,7 +337,7 @@ let collection_list: CollectionList = pinecone.list_collections().await?; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::control::CollectionModel; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; let collection: CollectionModel = pinecone.describe_collection("collection-name").await?; ``` @@ -311,7 +346,7 @@ let collection: CollectionModel = pinecone.describe_collection("collection-name" ```rust use pinecone_sdk::pinecone::PineconeClient; -let pinecone = PineconeClient::new(None, None, None, None)?; +let pinecone = PineconeClient::new('<>', None, None, None)?; pinecone.delete_collection("collection-name").await?; ``` From a2eec1a488ba72fccf6de9819d9ca5b998397c70 Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Wed, 24 Jul 2024 10:11:17 -0400 Subject: [PATCH 13/27] Update commit reference for submodule --- codegen/apis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/apis b/codegen/apis index d1c2230..4de4456 160000 --- a/codegen/apis +++ b/codegen/apis @@ -1 +1 @@ -Subproject commit d1c223060d97cf253acfba5004667d4b89bcc382 +Subproject commit 4de44568f98556d29e8044c8146b572d2396cb05 From 45b49a6ebbf9c4040410e2b88413fec3d296feab Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:20:29 -0400 Subject: [PATCH 14/27] add rest of data plane descriptions --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a7ae4e2..ac7f903 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ let response: UpsertResponse = index.upsert(&vectors, &"namespace".into()).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. ```rust @@ -237,7 +238,9 @@ let response: QueryResponse = index.query_by_value( ``` ## Delete vectors -### Delete by ID: +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`. ```rust use pinecone_sdk::pinecone::PineconeClient; @@ -251,6 +254,7 @@ index.delete_by_id(&ids, &"namespace".into()).await?; ``` ### Delete by filter: +The following example deletes vectors that satisfy the filter in the namespace `namespace`. ```rust use std::collections::BTreeMap; use pinecone_sdk::pinecone::PineconeClient; @@ -265,6 +269,7 @@ index.delete_by_filter(Metadata { fields }, &"namespace".into()).await?; ``` ### Delete all: +The following example deletes all vectors in the namespace `namespace`. ```rust use pinecone_sdk::pinecone::PineconeClient; @@ -276,6 +281,7 @@ index.delete_all(&"namespace".into()).await?; ``` ## Fetch vectors +The following example fetches the vectors with IDs `1` and `2` from the default namespace. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::FetchResponse; @@ -284,10 +290,13 @@ let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; +let vectors = &["1".to_string(), "2".to_string()]; + let response: FetchResponse = index.fetch(vectors, &Default::default()).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]`. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::UpdateResponse; @@ -300,6 +309,7 @@ let response: UpdateResponse = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0 ``` ## List vectors +The following example lists vectors in the namespace `namespace`. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::data::{Namespace, ListResponse}; From 4540a02a9fdc082ac1e34f481fbc43dbebeaeebd Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:21:32 -0400 Subject: [PATCH 15/27] pull changes --- codegen/apis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/apis b/codegen/apis index 4de4456..d1c2230 160000 --- a/codegen/apis +++ b/codegen/apis @@ -1 +1 @@ -Subproject commit 4de44568f98556d29e8044c8146b572d2396cb05 +Subproject commit d1c223060d97cf253acfba5004667d4b89bcc382 From 1fc262ebaa58c89095a19177a16ef32c0d75ac36 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:29:40 -0400 Subject: [PATCH 16/27] fix compile issue --- pinecone_sdk/src/pinecone/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pinecone_sdk/src/pinecone/data.rs b/pinecone_sdk/src/pinecone/data.rs index 427e517..41cbf17 100644 --- a/pinecone_sdk/src/pinecone/data.rs +++ b/pinecone_sdk/src/pinecone/data.rs @@ -627,7 +627,7 @@ impl PineconeClient { /// # #[tokio::main] /// # async fn main() -> Result<(), PineconeError>{ /// let pinecone = PineconeClient::new(None, None, None, None)?; - /// "index-host" + /// /// let index = pinecone.index("index-host").await?; /// # Ok(()) /// # } From 7b2418041a50299682926bef8f86654ba76593b5 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:34:36 -0400 Subject: [PATCH 17/27] descriptions for collection operations --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ac7f903..1790d94 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ let response: ListResponse = index.list(&"namespace".into(), None, None, None).a # Collections ## Create collection +The following example creates a collection `collection-name` in the index `index-name`. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::control::CollectionModel; @@ -333,6 +334,7 @@ let collection: CollectionModel = pinecone.create_collection("collection-name", ``` ## List collections +The following example lists all collections in a project. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::control::CollectionList; @@ -343,6 +345,7 @@ let collection_list: CollectionList = pinecone.list_collections().await?; ``` ## Describe collection +The following example describes the collection `collection-name`. ```rust use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::pinecone::control::CollectionModel; @@ -353,6 +356,7 @@ let collection: CollectionModel = pinecone.describe_collection("collection-name" ``` ## Delete collection +The following example deletes the collection `collection-name`. ```rust use pinecone_sdk::pinecone::PineconeClient; From 9d70f53728c299ec24db99376b9688e30da982f3 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:43:03 -0400 Subject: [PATCH 18/27] reformatted some docstrings --- README.md | 3 ++- pinecone_sdk/src/pinecone/data.rs | 37 +++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1790d94..90dacaf 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,8 @@ let pinecone = PineconeClient::new('<>', None, None, None)?; let mut index = pinecone.index("index-host").await?; let mut fields = BTreeMap::new(); -fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); +let kind = Some(Kind::StringValue("value".to_string())); +fields.insert("field".to_string(), Value { kind }); let response: DescribeIndexStatsResponse = index.describe_index_stats(Some(Metadata { fields })).await?; ``` diff --git a/pinecone_sdk/src/pinecone/data.rs b/pinecone_sdk/src/pinecone/data.rs index 41cbf17..087ca48 100644 --- a/pinecone_sdk/src/pinecone/data.rs +++ b/pinecone_sdk/src/pinecone/data.rs @@ -195,7 +195,8 @@ impl Index { /// /// // Construct a metadata filter /// let mut fields = BTreeMap::new(); - /// fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string())) }); + /// let kind = Some(Kind::StringValue("value".to_string())); + /// fields.insert("field".to_string(), Value { kind }); /// /// // Describe the index statistics /// let response: DescribeIndexStatsResponse = index.describe_index_stats(Some(Metadata { fields })).await?; @@ -246,7 +247,7 @@ impl Index { /// ### Example /// ```no_run /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::{Namespace, SparseValues, Metadata, UpdateResponse}; + /// use pinecone_sdk::pinecone::data::UpdateResponse; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] @@ -256,7 +257,13 @@ impl Index { /// let mut index = pinecone.index("index-host").await?; /// /// // Update the vector with id "vector-id" in the namespace "namespace" - /// let response: UpdateResponse = index.update("vector-id", vec![1.0, 2.0, 3.0, 4.0], None, None, &"namespace".into()).await?; + /// let response: UpdateResponse = index.update( + /// "vector-id", + /// vec![1.0, 2.0, 3.0, 4.0], + /// None, + /// None, + /// &"namespace".into() + /// ).await?; /// # Ok(()) /// # } /// ``` @@ -312,7 +319,14 @@ impl Index { /// let mut index = pinecone.index("index-host").await?; /// /// // Query the vector with id "vector-id" in the default namespace - /// let response: QueryResponse = index.query_by_id("vector-id".to_string(), 10, &Namespace::default(), None, None, None).await?; + /// let response: QueryResponse = index.query_by_id( + /// "vector-id".to_string(), + /// 10, + /// &Namespace::default(), + /// None, + /// None, + /// None + /// ).await?; /// # Ok(()) /// # } /// ``` @@ -369,7 +383,15 @@ impl Index { /// let vector = vec![1.0, 2.0, 3.0, 4.0]; /// /// // Query the vector in the default namespace - /// let response: QueryResponse = index.query_by_value(vector, None, 10, &Namespace::default(), None, None, None).await?; + /// let response: QueryResponse = index.query_by_value( + /// vector, + /// None, + /// 10, + /// &Namespace::default(), + /// None, + /// None, + /// None + /// ).await?; /// # Ok(()) /// # } /// ``` @@ -502,7 +524,8 @@ impl Index { /// /// // Construct a metadata filter /// let mut fields = BTreeMap::new(); - /// fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string())) }); + /// 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 /// index.delete_by_filter(Metadata { fields }, &"namespace".into()).await?; @@ -548,7 +571,7 @@ impl Index { /// ```no_run /// use std::collections::BTreeMap; /// use pinecone_sdk::pinecone::PineconeClient; - /// use pinecone_sdk::pinecone::data::{Metadata, Value, Kind, FetchResponse}; + /// use pinecone_sdk::pinecone::data::FetchResponse; /// # use pinecone_sdk::utils::errors::PineconeError; /// /// # #[tokio::main] From 61f976959ffa92d4752bb144673969e1869de9fc Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 10:43:39 -0400 Subject: [PATCH 19/27] split metadata builder into two lines --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 90dacaf..565a464 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,8 @@ use pinecone_sdk::pinecone::data::{Metadata, Value, Kind, Namespace}; let pinecone = PineconeClient::new('<>', None, None, None)?; let mut fields = BTreeMap::new(); -fields.insert("field".to_string(), Value { kind: Some(Kind::StringValue("value".to_string()))}); +let kind = Some(Kind::StringValue("value".to_string())); +fields.insert("field".to_string(), Value { kind }); index.delete_by_filter(Metadata { fields }, &"namespace".into()).await?; ``` From d60fd2075243045b83ee2f21d270fca95740d90c Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 11:59:29 -0400 Subject: [PATCH 20/27] add link to contribution guide --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 565a464..5bb3fb2 100644 --- a/README.md +++ b/README.md @@ -366,3 +366,6 @@ let pinecone = PineconeClient::new('<>', None, None, None)?; pinecone.delete_collection("collection-name").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](https://github.com/pinecone-io/pinecone-rust-client/blob/emily/update-readme/CONTRIBUTING.md) \ No newline at end of file From 629e29321f2154cda30291dcf06312ccaa2b7dd6 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Wed, 24 Jul 2024 16:42:21 -0400 Subject: [PATCH 21/27] add usage instructions --- README.md | 6 +++--- codegen/apis | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5bb3fb2..b517746 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ How to install - instruction for getting the package from crates.io ## Usage -Explanation about how environment variables are used - -Proxy config? +The `PineconeClient` class is the main point of entry into the Rust SDK. To instantiate it, call `Pinecone::new(...)`, which takes in an API key, control plane host, additional headers, and a source tag. All are optional arguments, however not all are truly optional: +- The API key must be passed in either as an argument or as an environment variable called `PINECONE_API_KEY`. If not passed in as an argument, the client will attempt to read in an environment variable value. +- The control plane host, if not passed in as an argument, will attempt to read in an environment variable called `PINECONE_CONTROLLER_HOST`. If it is not an environment variable, it will default to `https://api.pinecone.io`. # Indexes diff --git a/codegen/apis b/codegen/apis index d1c2230..4de4456 160000 --- a/codegen/apis +++ b/codegen/apis @@ -1 +1 @@ -Subproject commit d1c223060d97cf253acfba5004667d4b89bcc382 +Subproject commit 4de44568f98556d29e8044c8146b572d2396cb05 From 88c39017258e01e90a2155ebf33b68e80a5c19f1 Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Mon, 29 Jul 2024 10:58:02 -0400 Subject: [PATCH 22/27] Add link to apis repo readme --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 60b2ea4..db82d0d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,7 +28,7 @@ git submodule update --init --recursive The generated code is already checked into the repository, but it can be regenerated by following these steps. You will require access to the `apis` repository. -- Follow setup instructions for the `apis` repository +- Follow setup instructions for the `apis` repository: [apis setup](https://github.com/pinecone-io/apis) OpenAPI From 7e1e58dae150d0eeb63800c6249cfdecd08c3665 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Mon, 29 Jul 2024 16:43:44 -0400 Subject: [PATCH 23/27] updated configure index docs --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b517746..9095932 100644 --- a/README.md +++ b/README.md @@ -115,13 +115,24 @@ let index_description: IndexModel = pinecone.describe_index("index-name").await? ``` ## Configure index -The following example changes the index `index-name` to have 6 replicas and pod type `s1`. +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`. +```rust +use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; + +let pinecone = PineconeClient::new('<>', None, None, None)?; + +let index_description: IndexModel = pinecone.configure_index("index-name", Some(DeletionProtection::Disabled), None, None).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. ```rust use pinecone_sdk::pinecone::{PineconeClient, control::IndexModel}; let pinecone = PineconeClient::new('<>', None, None, None)?; -let index_description: IndexModel = pinecone.configure_index("index-name", 6, "s1").await?; +let index_description: IndexModel = pinecone.configure_index("index-name", None, Some(6), Some("s1")).await?; ``` ## Delete index From 6c526db9f67a2faf1b7a14c49b76a304d3b8d13c Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Tue, 30 Jul 2024 11:53:11 -0400 Subject: [PATCH 24/27] Update CONTRIBUTING for updated justfile --- CONTRIBUTING.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db82d0d..a65bafb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,16 +33,24 @@ You will require access to the `apis` repository. OpenAPI - You need [Docker Desktop](https://www.docker.com/products/docker-desktop/) in order to generate code using openapi. Look at `codegen/build-oas.sh` to see how this is used. + - Make sure Docker is running. - `just build-openapi` - References the spec files from the `codegen/apis` submodule - - Outputs the generated code to `openapi` + - Outputs the generated code to `src/openapi` Protobuf - `brew install protobuf` - `cargo install protobuf-codegen` and add it to path: `PATH="$HOME/.cargo/bin:$PATH"` - `just build-proto` - References the spec files from the `codegen/apis` submodule - - Outputs the generated code to `protos` + - Outputs the generated code to `src/protos` + +Alternatively, you can run `just build-client` to regenerate both OpenAPI and Protobuf code. + +What the build process looks like in all cases: +- Build the `apis` submodule to produce consolidated .yaml files in `codegen/apis/_build` +- Create a `version.rs` file containing API version info based on the defined value in the justfile +- Run build scripts for OpenAPI and/or Protobuf, propagating the API version ### Build and run From e3472788fcfadccc0a6fb96ee0436b7510cde9e5 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Tue, 30 Jul 2024 11:56:16 -0400 Subject: [PATCH 25/27] try to fix test case --- Cargo.lock | 72 +++++++++++++++++++++++++++++++ Cargo.toml | 1 + tests/integration_test_control.rs | 3 ++ 3 files changed, 76 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4905286..9218c41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -628,6 +628,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -635,6 +650,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -643,6 +659,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -706,9 +733,13 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -1455,6 +1486,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "serial_test", "snafu", "temp-env", "tokio", @@ -1864,6 +1896,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scc" +version = "2.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ccfb12511cdb770157ace92d7dda771e498445b78f9886e8cdbc5140a4eced" +dependencies = [ + "sdd", +] + [[package]] name = "schannel" version = "0.1.23" @@ -1879,6 +1920,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sdd" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177258b64c0faaa9ffd3c65cd3262c2bc7e2588dbbd9c1641d0346145c1bbda8" + [[package]] name = "security-framework" version = "2.11.1" @@ -1955,6 +2002,31 @@ dependencies = [ "serde", ] +[[package]] +name = "serial_test" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b4b487fe2acf240a021cf57c6b2b4903b1e78ca0ecd862a71b71d2a51fed77d" +dependencies = [ + "futures", + "log", + "once_cell", + "parking_lot", + "scc", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.71", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" diff --git a/Cargo.toml b/Cargo.toml index f393587..c1816f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ serde = { version = "^1.0", features = ["derive"] } url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } +serial_test = "3.1.1" [dev-dependencies] temp-env = "0.3.6" diff --git a/tests/integration_test_control.rs b/tests/integration_test_control.rs index c591c48..245a6f5 100644 --- a/tests/integration_test_control.rs +++ b/tests/integration_test_control.rs @@ -9,6 +9,7 @@ use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::utils::errors::PineconeError; use std::collections::HashMap; use std::time::Duration; +use serial_test::serial; mod common; @@ -255,6 +256,7 @@ async fn test_delete_index_err() -> Result<(), PineconeError> { } #[tokio::test] +#[serial] async fn test_configure_index() -> Result<(), PineconeError> { let pinecone = PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); @@ -398,6 +400,7 @@ async fn test_configure_invalid_index_err() -> Result<(), PineconeError> { } #[tokio::test] +#[serial] async fn test_create_delete_collection() -> Result<(), PineconeError> { let pinecone = PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); From 22aa9f317ceabd13b946c148c4473f832a160645 Mon Sep 17 00:00:00 2001 From: Emily Yu Date: Tue, 30 Jul 2024 15:35:06 -0400 Subject: [PATCH 26/27] Update version specificity and detail on apis submodule --- CONTRIBUTING.md | 6 ++---- Cargo.toml | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a65bafb..f588db0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,8 +2,6 @@ ## Local development -- [Internal Asana backlog](https://app.asana.com/0/1207449888227387/1207449824366220) - ### Prerequisites - Install [homebrew](https://brew.sh/) if you haven't already @@ -25,9 +23,9 @@ git submodule update --init --recursive ### Generating code from OpenAPI and Proto specs -The generated code is already checked into the repository, but it can be regenerated by following these steps. +The generated code is already checked into the repository and normally should not need to be modified. -You will require access to the `apis` repository. +To regenerate OpenAPI or Protobuf code, you will require access to the private `apis` repository. - Follow setup instructions for the `apis` repository: [apis setup](https://github.com/pinecone-io/apis) OpenAPI diff --git a/Cargo.toml b/Cargo.toml index c1816f8..71d75c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,15 +12,15 @@ license = "Apache-2.0" [dependencies] tokio = { version = "1", features = ["full"] } -regex = "1.10.4" -serde_json = "1.0.117" -snafu = "0.8.3" -rand = "0.8.5" -tonic = { version = "0.11.0", features = ["tls", "transport", "tls-roots"] } -prost = "0.12.6" -prost-types = "0.12.6" -# reqwest = "0.12.5" -once_cell = "1.19.0" +regex = "1.10" +serde_json = "1.0" +snafu = "0.8" +rand = "0.8" +tonic = { version = "0.11", features = ["tls", "transport", "tls-roots"] } +prost = "0.12" +prost-types = "0.12" +# reqwest = "0.12" +once_cell = "1.19" # openapi serde = { version = "^1.0", features = ["derive"] } @@ -28,11 +28,11 @@ serde = { version = "^1.0", features = ["derive"] } url = "^2.5" uuid = { version = "^1.8", features = ["serde", "v4"] } reqwest = { version = "^0.12", features = ["json", "multipart"] } -serial_test = "3.1.1" [dev-dependencies] -temp-env = "0.3.6" +temp-env = "0.3" httpmock = "0.7.0-rc.1" +serial_test = "3.1" [build-dependencies] -tonic-build = "0.11.0" +tonic-build = "0.11" From 74702864542bed684ce4f7d3b95c86a4790552a8 Mon Sep 17 00:00:00 2001 From: Erica Wang Date: Thu, 1 Aug 2024 10:41:09 -0400 Subject: [PATCH 27/27] try to fix failing data test --- tests/integration_test_data.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration_test_data.rs b/tests/integration_test_data.rs index 334c926..598c34f 100644 --- a/tests/integration_test_data.rs +++ b/tests/integration_test_data.rs @@ -547,6 +547,7 @@ async fn test_fetch_vectors() -> Result<(), PineconeError> { .expect("Failed to fetch vectors"); assert_eq!(fetch_response.namespace, namespace.name); + assert_eq!(fetch_response.vectors.len(), 2); let vectors = fetch_response.vectors; assert_eq!( *vectors.get("1").unwrap(),