From 2ccc8c17b53fb82d66d88878f8ce82131ebed8bc Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Tue, 1 Oct 2024 16:56:51 -0400 Subject: [PATCH] Add lint, build, and test commands to `justfile`, add fmt and clippy to CI workflow (#59) ## Problem @haruska had some good feedback around adding explicit `build`, `test`, and `lint` commands to the `justfile` in the repo. Currently there are only commands for dealing with code generation which is a little confusing. Additionally, we haven't run `cargo fmt` and `cargo clippy` on the codebase yet, and have nothing enforcing its use. ## Solution - Refactor`justfile`: move all code generation under `gen-*` commands, add `build`, `test`, `lint`, and `update` commands to the file. - Update `ci.yaml` workflow to support both fmt and clippy. Reject if running either leads to issues. - Code changes for fmt and clippy. **Note:** At the moment I've added `#![allow(clippy::enum_variant_names)]` and `#![allow(clippy::empty_docs)]` to the `src/openapi/mod.rs` file. There were some clippy issues in the generated code, and since we still need to refactor the entire generation flow in this repo, I just stuck the allow tags on top for now. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [X] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Make sure CI passes. --- .github/workflows/ci.yaml | 79 +++-- justfile | 33 ++- src/lib.rs | 4 +- src/openapi/apis/configuration.rs | 4 - src/openapi/apis/inference_api.rs | 25 +- src/openapi/apis/manage_indexes_api.rs | 227 ++++++++++---- src/openapi/apis/mod.rs | 16 +- src/openapi/mod.rs | 5 +- src/openapi/models/collection_list.rs | 5 +- src/openapi/models/collection_model.rs | 1 - src/openapi/models/configure_index_request.rs | 6 +- .../models/configure_index_request_spec.rs | 5 +- .../configure_index_request_spec_pod.rs | 1 - .../models/create_collection_request.rs | 8 +- src/openapi/models/create_index_request.rs | 16 +- src/openapi/models/deletion_protection.rs | 6 +- src/openapi/models/embed_request.rs | 1 - .../models/embed_request_inputs_inner.rs | 5 +- .../models/embed_request_parameters.rs | 1 - src/openapi/models/embedding.rs | 5 +- src/openapi/models/embeddings_list.rs | 1 - src/openapi/models/embeddings_list_usage.rs | 5 +- src/openapi/models/error_response.rs | 1 - src/openapi/models/error_response_error.rs | 3 +- src/openapi/models/index_list.rs | 5 +- src/openapi/models/index_model.rs | 17 +- src/openapi/models/index_model_spec.rs | 1 - src/openapi/models/index_model_status.rs | 8 +- src/openapi/models/index_spec.rs | 5 +- src/openapi/models/pod_spec.rs | 9 +- .../models/pod_spec_metadata_config.rs | 5 +- src/openapi/models/serverless_spec.rs | 8 +- src/pinecone/control.rs | 48 +-- src/pinecone/data.rs | 5 +- src/pinecone/inference.rs | 6 +- src/pinecone/mod.rs | 3 +- src/protos/mod.rs | 278 +++++++----------- src/utils/user_agent.rs | 9 +- tests/common.rs | 5 + 39 files changed, 466 insertions(+), 409 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 02caf57..f60f316 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,34 +1,55 @@ name: CI on: - pull_request: {} - push: - branches: - - main - workflow_dispatch: {} + pull_request: {} + push: + branches: + - main + workflow_dispatch: {} jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - rust: [stable] - steps: - - uses: actions/checkout@v4 - - uses: hecrj/setup-rust-action@v2 - with: - rust-version: ${{ matrix.rust }} - - name: Install protoc - uses: arduino/setup-protoc@v3 - - name: Build SDK - run: cargo build - - name: Build documentation - run: cargo doc --no-deps - - name: Run tests - env: - PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} - SERVERLESS_INDEX_NAME: ${{ secrets.SERVERLESS_INDEX_NAME }} - POD_INDEX_NAME: ${{ secrets.POD_INDEX_NAME }} - COLLECTION_NAME: ${{ secrets.COLLECTION_NAME }} - run: cargo test --verbose + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + rust: [stable] + steps: + - uses: actions/checkout@v4 + - uses: hecrj/setup-rust-action@v2 + with: + rust-version: ${{ matrix.rust }} + - name: Install protoc + uses: arduino/setup-protoc@v3 + - name: Build SDK + run: cargo build + - name: Build documentation + run: cargo doc --no-deps + - name: Run tests + env: + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + SERVERLESS_INDEX_NAME: ${{ secrets.SERVERLESS_INDEX_NAME }} + POD_INDEX_NAME: ${{ secrets.POD_INDEX_NAME }} + COLLECTION_NAME: ${{ secrets.COLLECTION_NAME }} + run: cargo test --verbose + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - name: Enforce formatting + run: cargo fmt --check + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - name: Run clippy + run: cargo clippy -- -D warnings diff --git a/justfile b/justfile index 93e7299..49de641 100644 --- a/justfile +++ b/justfile @@ -1,22 +1,39 @@ api_version := "2024-07" -# Generate version file -generate-version: - echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > src/version.rs +# Lint files and run tests with optional specific test cases +test *tests: lint + # Runs the specified tests, or all tests if none specified + cargo test {{tests}} --verbose + +# Update git submodules recursively +update: + git submodule update --init --recursive + +# Run linting tools (cargo fmt and clippy) +lint: + cargo fmt && cargo clippy -# Build the OpenAPI and Protobuf definitions in `codegen/apis` -build-apis: +# Run cargo build +build: + cargo build + +# Build the OpenAPI and Protobuf definitions in the `codegen/apis` submodule +gen-build-submodule-apis: cd codegen/apis && just build # Generate the control plane OpenAPI code based on the yaml files in `codegen/apis/_build` -build-openapi: build-apis generate-version +gen-openapi: gen-build-submodule-apis gen-version_file ./codegen/build-oas.sh {{api_version}} # Generate the data plane protobuf code based on the yaml files in `codegen/apis/_build` -build-proto: build-apis generate-version +gen-proto: gen-build-submodule-apis gen-version_file ./codegen/build-proto.sh {{api_version}} # Generate all OpenAPI and protobuf code -build-client: build-apis generate-version +gen-client: gen-build-submodule-apis gen-version_file ./codegen/build-oas.sh {{api_version}} ./codegen/build-proto.sh {{api_version}} + +# Generate version file +gen-version_file: + echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > src/version.rs \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2ee9f8f..1fa337e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ //! # Pinecone Rust SDK //! //! > ⚠️ **Warning:** This SDK is still in an alpha state. While it is mostly built out and functional, -//! it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback, -//! but be aware that updates may introduce breaking changes. +//! > it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback, +//! > but be aware that updates may introduce breaking changes. //! //! `pinecone-sdk` provides an interface for working with Pinecone services such as the Database and Inference APIs. //! See [docs.pinecone.io](https://docs.pinecone.io/) for more information. diff --git a/src/openapi/apis/configuration.rs b/src/openapi/apis/configuration.rs index 67256cb..ef6b88f 100644 --- a/src/openapi/apis/configuration.rs +++ b/src/openapi/apis/configuration.rs @@ -8,8 +8,6 @@ * Generated by: https://openapi-generator.tech */ - - #[derive(Debug, Clone)] pub struct Configuration { pub base_path: String, @@ -30,7 +28,6 @@ pub struct ApiKey { pub key: String, } - impl Configuration { pub fn new() -> Configuration { Configuration::default() @@ -47,7 +44,6 @@ impl Default for Configuration { oauth_access_token: None, bearer_access_token: None, api_key: None, - } } } diff --git a/src/openapi/apis/inference_api.rs b/src/openapi/apis/inference_api.rs index 1173b27..fef45c6 100644 --- a/src/openapi/apis/inference_api.rs +++ b/src/openapi/apis/inference_api.rs @@ -8,12 +8,10 @@ * Generated by: https://openapi-generator.tech */ - +use super::{configuration, Error}; +use crate::openapi::{apis::ResponseContent, models}; use reqwest; use serde::{Deserialize, Serialize}; -use crate::openapi::{apis::ResponseContent, models}; -use super::{Error, configuration}; - /// struct for typed errors of method [`embed`] #[derive(Debug, Clone, Serialize, Deserialize)] @@ -25,18 +23,22 @@ pub enum EmbedError { UnknownValue(serde_json::Value), } - /// Generate embeddings for input data -pub async fn embed(configuration: &configuration::Configuration, embed_request: Option) -> Result> { +pub async fn embed( + configuration: &configuration::Configuration, + embed_request: Option, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/embed", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -58,8 +60,11 @@ pub async fn embed(configuration: &configuration::Configuration, embed_request: serde_json::from_str(&local_var_content).map_err(Error::from) } else { let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } - diff --git a/src/openapi/apis/manage_indexes_api.rs b/src/openapi/apis/manage_indexes_api.rs index 1f7f7ec..2b0af4f 100644 --- a/src/openapi/apis/manage_indexes_api.rs +++ b/src/openapi/apis/manage_indexes_api.rs @@ -8,12 +8,10 @@ * Generated by: https://openapi-generator.tech */ - +use super::{configuration, Error}; +use crate::openapi::{apis::ResponseContent, models}; use reqwest; use serde::{Deserialize, Serialize}; -use crate::openapi::{apis::ResponseContent, models}; -use super::{Error, configuration}; - /// struct for typed errors of method [`configure_index`] #[derive(Debug, Clone, Serialize, Deserialize)] @@ -114,18 +112,27 @@ pub enum ListIndexesError { UnknownValue(serde_json::Value), } - /// This operation configures an existing index. For serverless indexes, you can configure only index deletion protection. For pod-based indexes, you can configure the pod size, number of replicas, and index deletion protection. It is not possible to change the pod type of a pod-based index. However, you can create a collection from a pod-based index and then [create a new pod-based index with a different pod type](http://docs.pinecone.io/guides/indexes/create-an-index#create-an-index-from-a-collection) from the collection. For guidance and examples, see [Configure an index](http://docs.pinecone.io/guides/indexes/configure-an-index). -pub async fn configure_index(configuration: &configuration::Configuration, index_name: &str, configure_index_request: models::ConfigureIndexRequest) -> Result> { +pub async fn configure_index( + configuration: &configuration::Configuration, + index_name: &str, + configure_index_request: models::ConfigureIndexRequest, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/indexes/{index_name}", local_var_configuration.base_path, index_name=crate::openapi::apis::urlencode(index_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str()); + let local_var_uri_str = format!( + "{}/indexes/{index_name}", + local_var_configuration.base_path, + index_name = crate::openapi::apis::urlencode(index_name) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -146,23 +153,33 @@ pub async fn configure_index(configuration: &configuration::Configuration, index if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } -/// This operation creates a Pinecone collection. Serverless indexes do not support collections. -pub async fn create_collection(configuration: &configuration::Configuration, create_collection_request: models::CreateCollectionRequest) -> Result> { +/// This operation creates a Pinecone collection. Serverless indexes do not support collections. +pub async fn create_collection( + configuration: &configuration::Configuration, + create_collection_request: models::CreateCollectionRequest, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/collections", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -183,23 +200,33 @@ pub async fn create_collection(configuration: &configuration::Configuration, cre if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } -/// This operation deploys a Pinecone index. This is where you specify the measure of similarity, the dimension of vectors to be stored in the index, which cloud provider you would like to deploy with, and more. For guidance and examples, see [Create an index](https://docs.pinecone.io/guides/indexes/create-an-index#create-a-serverless-index). -pub async fn create_index(configuration: &configuration::Configuration, create_index_request: models::CreateIndexRequest) -> Result> { +/// This operation deploys a Pinecone index. This is where you specify the measure of similarity, the dimension of vectors to be stored in the index, which cloud provider you would like to deploy with, and more. For guidance and examples, see [Create an index](https://docs.pinecone.io/guides/indexes/create-an-index#create-a-serverless-index). +pub async fn create_index( + configuration: &configuration::Configuration, + create_index_request: models::CreateIndexRequest, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/indexes", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -220,23 +247,37 @@ pub async fn create_index(configuration: &configuration::Configuration, create_i if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } -/// This operation deletes an existing collection. Serverless indexes do not support collections. -pub async fn delete_collection(configuration: &configuration::Configuration, collection_name: &str) -> Result<(), Error> { +/// This operation deletes an existing collection. Serverless indexes do not support collections. +pub async fn delete_collection( + configuration: &configuration::Configuration, + collection_name: &str, +) -> Result<(), Error> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/collections/{collection_name}", local_var_configuration.base_path, collection_name=crate::openapi::apis::urlencode(collection_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let local_var_uri_str = format!( + "{}/collections/{collection_name}", + local_var_configuration.base_path, + collection_name = crate::openapi::apis::urlencode(collection_name) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -256,23 +297,37 @@ pub async fn delete_collection(configuration: &configuration::Configuration, col if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } /// This operation deletes an existing index. -pub async fn delete_index(configuration: &configuration::Configuration, index_name: &str) -> Result<(), Error> { +pub async fn delete_index( + configuration: &configuration::Configuration, + index_name: &str, +) -> Result<(), Error> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/indexes/{index_name}", local_var_configuration.base_path, index_name=crate::openapi::apis::urlencode(index_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let local_var_uri_str = format!( + "{}/indexes/{index_name}", + local_var_configuration.base_path, + index_name = crate::openapi::apis::urlencode(index_name) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -292,23 +347,37 @@ pub async fn delete_index(configuration: &configuration::Configuration, index_na if !local_var_status.is_client_error() && !local_var_status.is_server_error() { Ok(()) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } -/// This operation gets a description of a collection. Serverless indexes do not support collections. -pub async fn describe_collection(configuration: &configuration::Configuration, collection_name: &str) -> Result> { +/// This operation gets a description of a collection. Serverless indexes do not support collections. +pub async fn describe_collection( + configuration: &configuration::Configuration, + collection_name: &str, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/collections/{collection_name}", local_var_configuration.base_path, collection_name=crate::openapi::apis::urlencode(collection_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let local_var_uri_str = format!( + "{}/collections/{collection_name}", + local_var_configuration.base_path, + collection_name = crate::openapi::apis::urlencode(collection_name) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -328,23 +397,37 @@ pub async fn describe_collection(configuration: &configuration::Configuration, c if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } /// Get a description of an index. -pub async fn describe_index(configuration: &configuration::Configuration, index_name: &str) -> Result> { +pub async fn describe_index( + configuration: &configuration::Configuration, + index_name: &str, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/indexes/{index_name}", local_var_configuration.base_path, index_name=crate::openapi::apis::urlencode(index_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let local_var_uri_str = format!( + "{}/indexes/{index_name}", + local_var_configuration.base_path, + index_name = crate::openapi::apis::urlencode(index_name) + ); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -364,23 +447,32 @@ pub async fn describe_index(configuration: &configuration::Configuration, index_ if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } -/// This operation returns a list of all collections in a project. Serverless indexes do not support collections. -pub async fn list_collections(configuration: &configuration::Configuration, ) -> Result> { +/// This operation returns a list of all collections in a project. Serverless indexes do not support collections. +pub async fn list_collections( + configuration: &configuration::Configuration, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/collections", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -400,23 +492,32 @@ pub async fn list_collections(configuration: &configuration::Configuration, ) -> if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } /// This operation returns a list of all indexes in a project. -pub async fn list_indexes(configuration: &configuration::Configuration, ) -> Result> { +pub async fn list_indexes( + configuration: &configuration::Configuration, +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; let local_var_uri_str = format!("{}/indexes", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let mut local_var_req_builder = + local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + local_var_req_builder = + local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } if let Some(ref local_var_apikey) = local_var_configuration.api_key { let local_var_key = local_var_apikey.key.clone(); @@ -436,9 +537,13 @@ pub async fn list_indexes(configuration: &configuration::Configuration, ) -> Res if !local_var_status.is_client_error() && !local_var_status.is_server_error() { serde_json::from_str(&local_var_content).map_err(Error::from) } else { - let local_var_entity: Option = serde_json::from_str(&local_var_content).ok(); - let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; + let local_var_entity: Option = + serde_json::from_str(&local_var_content).ok(); + let local_var_error = ResponseContent { + status: local_var_status, + content: local_var_content, + entity: local_var_entity, + }; Err(Error::ResponseError(local_var_error)) } } - diff --git a/src/openapi/apis/mod.rs b/src/openapi/apis/mod.rs index 6508d4a..a38c3c1 100644 --- a/src/openapi/apis/mod.rs +++ b/src/openapi/apis/mod.rs @@ -16,7 +16,7 @@ pub enum Error { ResponseError(ResponseContent), } -impl fmt::Display for Error { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (module, e) = match self { Error::Reqwest(e) => ("reqwest", e.to_string()), @@ -28,7 +28,7 @@ impl fmt::Display for Error { } } -impl error::Error for Error { +impl error::Error for Error { fn source(&self) -> Option<&(dyn error::Error + 'static)> { Some(match self { Error::Reqwest(e) => e, @@ -39,19 +39,19 @@ impl error::Error for Error { } } -impl From for Error { +impl From for Error { fn from(e: reqwest::Error) -> Self { Error::Reqwest(e) } } -impl From for Error { +impl From for Error { fn from(e: serde_json::Error) -> Self { Error::Serde(e) } } -impl From for Error { +impl From for Error { fn from(e: std::io::Error) -> Self { Error::Io(e) } @@ -78,8 +78,10 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String value, )); } - }, - serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), + } + serde_json::Value::String(s) => { + params.push((format!("{}[{}]", prefix, key), s.clone())) + } _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), } } diff --git a/src/openapi/mod.rs b/src/openapi/mod.rs index a1837b9..e438d1b 100644 --- a/src/openapi/mod.rs +++ b/src/openapi/mod.rs @@ -1,10 +1,11 @@ #![allow(unused_imports)] #![allow(clippy::too_many_arguments)] - +#![allow(clippy::enum_variant_names)] +#![allow(clippy::empty_docs)] +extern crate reqwest; extern crate serde; extern crate serde_json; extern crate url; -extern crate reqwest; pub mod apis; pub mod models; diff --git a/src/openapi/models/collection_list.rs b/src/openapi/models/collection_list.rs index 14b421c..29dcbd5 100644 --- a/src/openapi/models/collection_list.rs +++ b/src/openapi/models/collection_list.rs @@ -21,9 +21,6 @@ pub struct CollectionList { impl CollectionList { /// The list of collections that exist in the project. pub fn new() -> CollectionList { - CollectionList { - collections: None, - } + CollectionList { collections: None } } } - diff --git a/src/openapi/models/collection_model.rs b/src/openapi/models/collection_model.rs index 7043f6a..4f7f513 100644 --- a/src/openapi/models/collection_model.rs +++ b/src/openapi/models/collection_model.rs @@ -63,4 +63,3 @@ impl Default for Status { Self::Initializing } } - diff --git a/src/openapi/models/configure_index_request.rs b/src/openapi/models/configure_index_request.rs index 466ea57..e41acd4 100644 --- a/src/openapi/models/configure_index_request.rs +++ b/src/openapi/models/configure_index_request.rs @@ -16,7 +16,10 @@ use serde::{Deserialize, Serialize}; pub struct ConfigureIndexRequest { #[serde(rename = "spec", skip_serializing_if = "Option::is_none")] pub spec: Option>, - #[serde(rename = "deletion_protection", skip_serializing_if = "Option::is_none")] + #[serde( + rename = "deletion_protection", + skip_serializing_if = "Option::is_none" + )] pub deletion_protection: Option, } @@ -29,4 +32,3 @@ impl ConfigureIndexRequest { } } } - diff --git a/src/openapi/models/configure_index_request_spec.rs b/src/openapi/models/configure_index_request_spec.rs index 4566af6..fa1ed64 100644 --- a/src/openapi/models/configure_index_request_spec.rs +++ b/src/openapi/models/configure_index_request_spec.rs @@ -19,9 +19,6 @@ pub struct ConfigureIndexRequestSpec { impl ConfigureIndexRequestSpec { pub fn new(pod: models::ConfigureIndexRequestSpecPod) -> ConfigureIndexRequestSpec { - ConfigureIndexRequestSpec { - pod: Box::new(pod), - } + ConfigureIndexRequestSpec { pod: Box::new(pod) } } } - diff --git a/src/openapi/models/configure_index_request_spec_pod.rs b/src/openapi/models/configure_index_request_spec_pod.rs index e583b06..7fc4c48 100644 --- a/src/openapi/models/configure_index_request_spec_pod.rs +++ b/src/openapi/models/configure_index_request_spec_pod.rs @@ -29,4 +29,3 @@ impl ConfigureIndexRequestSpecPod { } } } - diff --git a/src/openapi/models/create_collection_request.rs b/src/openapi/models/create_collection_request.rs index cbc7b7a..6c848b3 100644 --- a/src/openapi/models/create_collection_request.rs +++ b/src/openapi/models/create_collection_request.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; /// CreateCollectionRequest : The configuration needed to create a Pinecone collection. #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] pub struct CreateCollectionRequest { - /// The name of the collection to be created. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'. + /// The name of the collection to be created. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'. #[serde(rename = "name")] pub name: String, /// The name of the index to be used as the source for the collection. @@ -25,10 +25,6 @@ pub struct CreateCollectionRequest { impl CreateCollectionRequest { /// The configuration needed to create a Pinecone collection. pub fn new(name: String, source: String) -> CreateCollectionRequest { - CreateCollectionRequest { - name, - source, - } + CreateCollectionRequest { name, source } } } - diff --git a/src/openapi/models/create_index_request.rs b/src/openapi/models/create_index_request.rs index e17fba5..0a4c786 100644 --- a/src/openapi/models/create_index_request.rs +++ b/src/openapi/models/create_index_request.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; /// CreateIndexRequest : The configuration needed to create a Pinecone index. #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] pub struct CreateIndexRequest { - /// The name of the index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'. + /// The name of the index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'. #[serde(rename = "name")] pub name: String, /// The dimensions of the vectors to be inserted in the index. @@ -23,7 +23,10 @@ pub struct CreateIndexRequest { /// The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'. #[serde(rename = "metric", skip_serializing_if = "Option::is_none")] pub metric: Option, - #[serde(rename = "deletion_protection", skip_serializing_if = "Option::is_none")] + #[serde( + rename = "deletion_protection", + skip_serializing_if = "Option::is_none" + )] pub deletion_protection: Option, #[serde(rename = "spec", deserialize_with = "Option::deserialize")] pub spec: Option>, @@ -31,13 +34,17 @@ pub struct CreateIndexRequest { impl CreateIndexRequest { /// The configuration needed to create a Pinecone index. - pub fn new(name: String, dimension: i32, spec: Option) -> CreateIndexRequest { + pub fn new( + name: String, + dimension: i32, + spec: Option, + ) -> CreateIndexRequest { CreateIndexRequest { name, dimension, metric: None, deletion_protection: None, - spec: if let Some(x) = spec {Some(Box::new(x))} else {None}, + spec: spec.map(Box::new), } } } @@ -57,4 +64,3 @@ impl Default for Metric { Self::Cosine } } - diff --git a/src/openapi/models/deletion_protection.rs b/src/openapi/models/deletion_protection.rs index 4bcdade..9686167 100644 --- a/src/openapi/models/deletion_protection.rs +++ b/src/openapi/models/deletion_protection.rs @@ -11,15 +11,14 @@ use crate::openapi::models; use serde::{Deserialize, Serialize}; -/// DeletionProtection : Whether [deletion protection](http://docs.pinecone.io/guides/indexes/prevent-index-deletion) is enabled/disabled for the index. -/// Whether [deletion protection](http://docs.pinecone.io/guides/indexes/prevent-index-deletion) is enabled/disabled for the index. +/// DeletionProtection : Whether [deletion protection](http://docs.pinecone.io/guides/indexes/prevent-index-deletion) is enabled/disabled for the index. +/// Whether [deletion protection](http://docs.pinecone.io/guides/indexes/prevent-index-deletion) is enabled/disabled for the index. #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum DeletionProtection { #[serde(rename = "disabled")] Disabled, #[serde(rename = "enabled")] Enabled, - } impl std::fmt::Display for DeletionProtection { @@ -36,4 +35,3 @@ impl Default for DeletionProtection { Self::Disabled } } - diff --git a/src/openapi/models/embed_request.rs b/src/openapi/models/embed_request.rs index a538ec3..81d3001 100644 --- a/src/openapi/models/embed_request.rs +++ b/src/openapi/models/embed_request.rs @@ -32,4 +32,3 @@ impl EmbedRequest { } } } - diff --git a/src/openapi/models/embed_request_inputs_inner.rs b/src/openapi/models/embed_request_inputs_inner.rs index 90920e1..2713a8a 100644 --- a/src/openapi/models/embed_request_inputs_inner.rs +++ b/src/openapi/models/embed_request_inputs_inner.rs @@ -19,9 +19,6 @@ pub struct EmbedRequestInputsInner { impl EmbedRequestInputsInner { pub fn new() -> EmbedRequestInputsInner { - EmbedRequestInputsInner { - text: None, - } + EmbedRequestInputsInner { text: None } } } - diff --git a/src/openapi/models/embed_request_parameters.rs b/src/openapi/models/embed_request_parameters.rs index 41d0a6e..06b5780 100644 --- a/src/openapi/models/embed_request_parameters.rs +++ b/src/openapi/models/embed_request_parameters.rs @@ -31,4 +31,3 @@ impl EmbedRequestParameters { } } } - diff --git a/src/openapi/models/embedding.rs b/src/openapi/models/embedding.rs index 470b252..abae85b 100644 --- a/src/openapi/models/embedding.rs +++ b/src/openapi/models/embedding.rs @@ -22,9 +22,6 @@ pub struct Embedding { impl Embedding { /// Embedding of a single input pub fn new() -> Embedding { - Embedding { - values: None, - } + Embedding { values: None } } } - diff --git a/src/openapi/models/embeddings_list.rs b/src/openapi/models/embeddings_list.rs index 3393cfb..bdb7643 100644 --- a/src/openapi/models/embeddings_list.rs +++ b/src/openapi/models/embeddings_list.rs @@ -32,4 +32,3 @@ impl EmbeddingsList { } } } - diff --git a/src/openapi/models/embeddings_list_usage.rs b/src/openapi/models/embeddings_list_usage.rs index 8bae72f..eed4f99 100644 --- a/src/openapi/models/embeddings_list_usage.rs +++ b/src/openapi/models/embeddings_list_usage.rs @@ -21,9 +21,6 @@ pub struct EmbeddingsListUsage { impl EmbeddingsListUsage { /// Usage statistics for model inference including any instruction prefixes pub fn new() -> EmbeddingsListUsage { - EmbeddingsListUsage { - total_tokens: None, - } + EmbeddingsListUsage { total_tokens: None } } } - diff --git a/src/openapi/models/error_response.rs b/src/openapi/models/error_response.rs index b235722..708d4d0 100644 --- a/src/openapi/models/error_response.rs +++ b/src/openapi/models/error_response.rs @@ -30,4 +30,3 @@ impl ErrorResponse { } } } - diff --git a/src/openapi/models/error_response_error.rs b/src/openapi/models/error_response_error.rs index 54e5b86..f339140 100644 --- a/src/openapi/models/error_response_error.rs +++ b/src/openapi/models/error_response_error.rs @@ -33,7 +33,7 @@ impl ErrorResponseError { } } } -/// +/// #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum Code { #[serde(rename = "OK")] @@ -81,4 +81,3 @@ impl Default for Code { Self::Ok } } - diff --git a/src/openapi/models/index_list.rs b/src/openapi/models/index_list.rs index 5e6ddd8..7555142 100644 --- a/src/openapi/models/index_list.rs +++ b/src/openapi/models/index_list.rs @@ -21,9 +21,6 @@ pub struct IndexList { impl IndexList { /// The list of indexes that exist in the project. pub fn new() -> IndexList { - IndexList { - indexes: None, - } + IndexList { indexes: None } } } - diff --git a/src/openapi/models/index_model.rs b/src/openapi/models/index_model.rs index f0bf11e..bee1b58 100644 --- a/src/openapi/models/index_model.rs +++ b/src/openapi/models/index_model.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; /// IndexModel : The IndexModel describes the configuration and status of a Pinecone index. #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] pub struct IndexModel { - /// The name of the index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'. + /// The name of the index. Resource name must be 1-45 characters long, start and end with an alphanumeric character, and consist only of lower case alphanumeric characters or '-'. #[serde(rename = "name")] pub name: String, /// The dimensions of the vectors to be inserted in the index. @@ -26,7 +26,10 @@ pub struct IndexModel { /// The URL address where the index is hosted. #[serde(rename = "host")] pub host: String, - #[serde(rename = "deletion_protection", skip_serializing_if = "Option::is_none")] + #[serde( + rename = "deletion_protection", + skip_serializing_if = "Option::is_none" + )] pub deletion_protection: Option, #[serde(rename = "spec")] pub spec: Box, @@ -36,7 +39,14 @@ pub struct IndexModel { impl IndexModel { /// The IndexModel describes the configuration and status of a Pinecone index. - pub fn new(name: String, dimension: i32, metric: Metric, host: String, spec: models::IndexModelSpec, status: models::IndexModelStatus) -> IndexModel { + pub fn new( + name: String, + dimension: i32, + metric: Metric, + host: String, + spec: models::IndexModelSpec, + status: models::IndexModelStatus, + ) -> IndexModel { IndexModel { name, dimension, @@ -64,4 +74,3 @@ impl Default for Metric { Self::Cosine } } - diff --git a/src/openapi/models/index_model_spec.rs b/src/openapi/models/index_model_spec.rs index a69b786..30dbc2b 100644 --- a/src/openapi/models/index_model_spec.rs +++ b/src/openapi/models/index_model_spec.rs @@ -27,4 +27,3 @@ impl IndexModelSpec { } } } - diff --git a/src/openapi/models/index_model_status.rs b/src/openapi/models/index_model_status.rs index 960c96c..cfbd242 100644 --- a/src/openapi/models/index_model_status.rs +++ b/src/openapi/models/index_model_status.rs @@ -21,13 +21,10 @@ pub struct IndexModelStatus { impl IndexModelStatus { pub fn new(ready: bool, state: State) -> IndexModelStatus { - IndexModelStatus { - ready, - state, - } + IndexModelStatus { ready, state } } } -/// +/// #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum State { #[serde(rename = "Initializing")] @@ -53,4 +50,3 @@ impl Default for State { Self::Initializing } } - diff --git a/src/openapi/models/index_spec.rs b/src/openapi/models/index_spec.rs index bd16296..5b69823 100644 --- a/src/openapi/models/index_spec.rs +++ b/src/openapi/models/index_spec.rs @@ -11,7 +11,7 @@ use crate::openapi::models; use serde::{Deserialize, Serialize}; -/// IndexSpec : The spec object defines how the index should be deployed. For serverless indexes, you define only the [cloud and region](http://docs.pinecone.io/guides/indexes/understanding-indexes#cloud-regions) where the index should be hosted. For pod-based indexes, you define the [environment](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-environments) where the index should be hosted, the [pod type and size](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-types) to use, and other index characteristics. +/// IndexSpec : The spec object defines how the index should be deployed. For serverless indexes, you define only the [cloud and region](http://docs.pinecone.io/guides/indexes/understanding-indexes#cloud-regions) where the index should be hosted. For pod-based indexes, you define the [environment](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-environments) where the index should be hosted, the [pod type and size](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-types) to use, and other index characteristics. #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] pub struct IndexSpec { #[serde(rename = "serverless", skip_serializing_if = "Option::is_none")] @@ -21,7 +21,7 @@ pub struct IndexSpec { } impl IndexSpec { - /// The spec object defines how the index should be deployed. For serverless indexes, you define only the [cloud and region](http://docs.pinecone.io/guides/indexes/understanding-indexes#cloud-regions) where the index should be hosted. For pod-based indexes, you define the [environment](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-environments) where the index should be hosted, the [pod type and size](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-types) to use, and other index characteristics. + /// The spec object defines how the index should be deployed. For serverless indexes, you define only the [cloud and region](http://docs.pinecone.io/guides/indexes/understanding-indexes#cloud-regions) where the index should be hosted. For pod-based indexes, you define the [environment](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-environments) where the index should be hosted, the [pod type and size](http://docs.pinecone.io/guides/indexes/understanding-indexes#pod-types) to use, and other index characteristics. pub fn new() -> IndexSpec { IndexSpec { serverless: None, @@ -29,4 +29,3 @@ impl IndexSpec { } } } - diff --git a/src/openapi/models/pod_spec.rs b/src/openapi/models/pod_spec.rs index c0a46d4..4e37c4f 100644 --- a/src/openapi/models/pod_spec.rs +++ b/src/openapi/models/pod_spec.rs @@ -38,7 +38,13 @@ pub struct PodSpec { impl PodSpec { /// Configuration needed to deploy a pod-based index. - pub fn new(environment: String, replicas: i32, shards: i32, pod_type: String, pods: i32) -> PodSpec { + pub fn new( + environment: String, + replicas: i32, + shards: i32, + pod_type: String, + pods: i32, + ) -> PodSpec { PodSpec { environment, replicas, @@ -50,4 +56,3 @@ impl PodSpec { } } } - diff --git a/src/openapi/models/pod_spec_metadata_config.rs b/src/openapi/models/pod_spec_metadata_config.rs index 76c6bac..7eb8974 100644 --- a/src/openapi/models/pod_spec_metadata_config.rs +++ b/src/openapi/models/pod_spec_metadata_config.rs @@ -22,9 +22,6 @@ pub struct PodSpecMetadataConfig { impl PodSpecMetadataConfig { /// Configuration for the behavior of Pinecone's internal metadata index. By default, all metadata is indexed; when `metadata_config` is present, only specified metadata fields are indexed. These configurations are only valid for use with pod-based indexes. pub fn new() -> PodSpecMetadataConfig { - PodSpecMetadataConfig { - indexed: None, - } + PodSpecMetadataConfig { indexed: None } } } - diff --git a/src/openapi/models/serverless_spec.rs b/src/openapi/models/serverless_spec.rs index 15ebd52..bf1e68f 100644 --- a/src/openapi/models/serverless_spec.rs +++ b/src/openapi/models/serverless_spec.rs @@ -17,7 +17,7 @@ pub struct ServerlessSpec { /// The public cloud where you would like your index hosted. #[serde(rename = "cloud")] pub cloud: Cloud, - /// The region where you would like your index to be created. + /// The region where you would like your index to be created. #[serde(rename = "region")] pub region: String, } @@ -25,10 +25,7 @@ pub struct ServerlessSpec { impl ServerlessSpec { /// Configuration needed to deploy a serverless index. pub fn new(cloud: Cloud, region: String) -> ServerlessSpec { - ServerlessSpec { - cloud, - region, - } + ServerlessSpec { cloud, region } } } /// The public cloud where you would like your index hosted. @@ -47,4 +44,3 @@ impl Default for Cloud { Self::Gcp } } - diff --git a/src/pinecone/control.rs b/src/pinecone/control.rs index 3cc5f43..6c43f79 100644 --- a/src/pinecone/control.rs +++ b/src/pinecone/control.rs @@ -50,6 +50,7 @@ impl PineconeClient { /// # Ok(()) /// # } /// ``` + #[allow(clippy::too_many_arguments)] pub async fn create_serverless_index( &self, name: &str, @@ -80,7 +81,7 @@ impl PineconeClient { // make openAPI call let res = manage_indexes_api::create_index(&self.openapi_config, create_index_request) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; // poll index status match self.handle_poll_index(name, timeout).await { @@ -106,7 +107,7 @@ impl PineconeClient { /// * `timeout: WaitPolicy` - The wait policy for index creation. If the index becomes ready before the specified duration, the function will return early. If the index is not ready after the specified duration, the function will return an error. /// /// ### Return - /// * Result` + /// * `Result` /// /// ### Example /// ```no_run @@ -140,6 +141,7 @@ impl PineconeClient { /// # Ok(()) /// # } /// ``` + #[allow(clippy::too_many_arguments)] pub async fn create_pod_index( &self, name: &str, @@ -184,7 +186,7 @@ impl PineconeClient { // make openAPI call let res = manage_indexes_api::create_index(&self.openapi_config, create_index_request) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; // poll index status match self.handle_poll_index(name, timeout).await { @@ -268,7 +270,7 @@ impl PineconeClient { // make openAPI call let res = manage_indexes_api::describe_index(&self.openapi_config, name) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res.into()) } @@ -299,7 +301,7 @@ impl PineconeClient { // make openAPI call let res = manage_indexes_api::list_indexes(&self.openapi_config) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res.into()) } @@ -310,10 +312,10 @@ impl PineconeClient { /// Deletion protection can be changed for both pod and serverless indexes, while pod types and number of replicas can only be changed for pod indexes. /// /// ### Arguments - /// * name: &str - The name of the index to be configured. - /// * deletion_protection: Option - Deletion protection for the index. - /// * replicas: Option - The desired number of replicas, lowest value is 0. This parameter should be `None` if the index is serverless. - /// * pod_type: Option<&str> - The new pod_type for the index. This parameter should be `None` if the index is serverless. + /// * `name: &str` - The name of the index to be configured. + /// * `deletion_protection: Option` - Deletion protection for the index. + /// * `replicas: Option` - The desired number of replicas, lowest value is 0. This parameter should be `None` if the index is serverless. + /// * `pod_type: Option<&str>` - The new pod_type for the index. This parameter should be `None` if the index is serverless. /// /// ### Return /// * `Result` @@ -344,7 +346,7 @@ impl PineconeClient { replicas: Option, pod_type: Option<&str>, ) -> Result { - if replicas == None && pod_type == None && deletion_protection == None { + if replicas.is_none() && pod_type.is_none() && deletion_protection.is_none() { return Err(PineconeError::InvalidConfigurationError { message: "At least one of deletion_protection, number of replicas, or pod type must be provided".to_string(), }); @@ -384,7 +386,7 @@ impl PineconeClient { configure_index_request, ) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res.into()) } @@ -392,7 +394,7 @@ impl PineconeClient { /// Deletes an index. /// /// ### Arguments - /// * name: &str - The name of the index to be deleted. + /// * `name: &str` - The name of the index to be deleted. /// /// ### Return /// * `Result<(), PineconeError>` @@ -412,11 +414,11 @@ impl PineconeClient { /// ``` pub async fn delete_index(&self, name: &str) -> Result<(), PineconeError> { // make openAPI call - let res = manage_indexes_api::delete_index(&self.openapi_config, name) + manage_indexes_api::delete_index(&self.openapi_config, name) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; - Ok(res) + Ok(()) } /// Creates a collection from an index. @@ -456,7 +458,7 @@ impl PineconeClient { let res = manage_indexes_api::create_collection(&self.openapi_config, create_collection_request) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res) } @@ -464,7 +466,7 @@ impl PineconeClient { /// Describe a collection. /// /// ### Arguments - /// * name: &str - The name of the collection to describe. + /// * `name: &str` - The name of the collection to describe. /// /// ### Return /// * `Result<(), PineconeError>` @@ -486,7 +488,7 @@ impl PineconeClient { pub async fn describe_collection(&self, name: &str) -> Result { let res = manage_indexes_api::describe_collection(&self.openapi_config, name) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res) } @@ -516,7 +518,7 @@ impl PineconeClient { // make openAPI call let res = manage_indexes_api::list_collections(&self.openapi_config) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res) } @@ -524,7 +526,7 @@ impl PineconeClient { /// Deletes a collection. /// /// ### Arguments - /// * name: &str - The name of the collection to be deleted. + /// * `name: &str` - The name of the collection to be deleted. /// /// ### Return /// * `Result<(), PineconeError>` @@ -544,11 +546,11 @@ impl PineconeClient { /// ``` pub async fn delete_collection(&self, name: &str) -> Result<(), PineconeError> { // make openAPI call - let res = manage_indexes_api::delete_collection(&self.openapi_config, name) + manage_indexes_api::delete_collection(&self.openapi_config, name) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; - Ok(res) + Ok(()) } } diff --git a/src/pinecone/data.rs b/src/pinecone/data.rs index 5dab576..ac283d3 100644 --- a/src/pinecone/data.rs +++ b/src/pinecone/data.rs @@ -33,6 +33,7 @@ impl Interceptor for ApiKeyInterceptor { /// A client for interacting with a Pinecone index. #[derive(Debug)] +#[allow(dead_code)] pub struct Index { /// The name of the index. host: String, @@ -298,6 +299,7 @@ impl Index { include_values: Option, include_metadata: Option, ) -> Result { + #[allow(deprecated)] let request = protos::QueryRequest { id: id.to_string(), top_k, @@ -345,6 +347,7 @@ impl Index { /// # Ok(()) /// # } /// ``` + #[allow(clippy::too_many_arguments)] pub async fn query_by_value( &mut self, vector: Vec, @@ -355,6 +358,7 @@ impl Index { include_values: Option, include_metadata: Option, ) -> Result { + #[allow(deprecated)] let request = protos::QueryRequest { id: "".to_string(), top_k, @@ -654,7 +658,6 @@ impl PineconeClient { #[cfg(test)] mod tests { - use super::*; use crate::pinecone::default_client; use httpmock::prelude::*; diff --git a/src/pinecone/inference.rs b/src/pinecone/inference.rs index a82f2b2..44a6692 100644 --- a/src/pinecone/inference.rs +++ b/src/pinecone/inference.rs @@ -32,11 +32,11 @@ impl PineconeClient { &self, model: &str, parameters: Option, - inputs: &Vec<&str>, + inputs: &[&str], ) -> Result { let request = EmbedRequest { model: model.to_string(), - parameters: parameters.map(|x| Box::new(x)), + parameters: parameters.map(Box::new), inputs: inputs .iter() .map(|&x| EmbedRequestInputsInner { @@ -47,7 +47,7 @@ impl PineconeClient { let res = inference_api::embed(&self.openapi_config, Some(request)) .await - .map_err(|e| PineconeError::from(e))?; + .map_err(PineconeError::from)?; Ok(res.into()) } diff --git a/src/pinecone/mod.rs b/src/pinecone/mod.rs index 66b61a9..c7d8086 100644 --- a/src/pinecone/mod.rs +++ b/src/pinecone/mod.rs @@ -85,7 +85,7 @@ impl PineconeClientConfig { let controller_host = &self.control_plane_host.clone().unwrap_or(env_controller); // get user agent - let user_agent = get_user_agent(self.source_tag.as_ref().map(|s| s.as_str())); + let user_agent = get_user_agent(self.source_tag.as_deref()); // get additional headers let mut additional_headers = @@ -151,6 +151,7 @@ impl PineconeClientConfig { /// The `PineconeClient` struct is the main entry point for interacting with Pinecone via this Rust SDK. #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct PineconeClient { /// Pinecone API key api_key: String, diff --git a/src/protos/mod.rs b/src/protos/mod.rs index 7aa02b7..1ea4ebf 100644 --- a/src/protos/mod.rs +++ b/src/protos/mod.rs @@ -313,10 +313,7 @@ pub struct DescribeIndexStatsResponse { /// summary of its contents. If a metadata filter expression is present, the /// summary will reflect only vectors matching that expression. #[prost(map = "string, message", tag = "1")] - pub namespaces: ::std::collections::HashMap< - ::prost::alloc::string::String, - NamespaceSummary, - >, + pub namespaces: ::std::collections::HashMap<::prost::alloc::string::String, NamespaceSummary>, /// The dimension of the indexed vectors. #[prost(uint32, tag = "2")] pub dimension: u32, @@ -334,8 +331,8 @@ pub struct DescribeIndexStatsResponse { /// Generated client implementations. pub mod vector_service_client { #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] - use tonic::codegen::*; use tonic::codegen::http::Uri; + use tonic::codegen::*; /// The `VectorService` interface is exposed by Pinecone's vector index services. /// This service could also be called a `gRPC` service or a `REST`-like api. #[derive(Debug, Clone)] @@ -381,9 +378,8 @@ pub mod vector_service_client { >::ResponseBody, >, >, - , - >>::Error: Into + Send + Sync, + >>::Error: + Into + Send + Sync, { VectorServiceClient::new(InterceptedService::new(inner, interceptor)) } @@ -427,19 +423,17 @@ pub mod vector_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/VectorService/Upsert"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("VectorService", "Upsert")); + req.extensions_mut() + .insert(GrpcMethod::new("VectorService", "Upsert")); self.inner.unary(req, path, codec).await } /// Delete vectors @@ -451,19 +445,17 @@ pub mod vector_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/VectorService/Delete"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("VectorService", "Delete")); + req.extensions_mut() + .insert(GrpcMethod::new("VectorService", "Delete")); self.inner.unary(req, path, codec).await } /// Fetch vectors @@ -475,19 +467,17 @@ pub mod vector_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/VectorService/Fetch"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("VectorService", "Fetch")); + req.extensions_mut() + .insert(GrpcMethod::new("VectorService", "Fetch")); self.inner.unary(req, path, codec).await } /// List vector IDs @@ -503,19 +493,17 @@ pub mod vector_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/VectorService/List"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("VectorService", "List")); + req.extensions_mut() + .insert(GrpcMethod::new("VectorService", "List")); self.inner.unary(req, path, codec).await } /// Query vectors @@ -527,19 +515,17 @@ pub mod vector_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/VectorService/Query"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("VectorService", "Query")); + req.extensions_mut() + .insert(GrpcMethod::new("VectorService", "Query")); self.inner.unary(req, path, codec).await } /// Update a vector @@ -551,19 +537,17 @@ pub mod vector_service_client { &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result, tonic::Status> { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static("/VectorService/Update"); let mut req = request.into_request(); - req.extensions_mut().insert(GrpcMethod::new("VectorService", "Update")); + req.extensions_mut() + .insert(GrpcMethod::new("VectorService", "Update")); self.inner.unary(req, path, codec).await } /// Get index stats @@ -576,23 +560,16 @@ pub mod vector_service_client { pub async fn describe_index_stats( &mut self, request: impl tonic::IntoRequest, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - > { - self.inner - .ready() - .await - .map_err(|e| { - tonic::Status::new( - tonic::Code::Unknown, - format!("Service was not ready: {}", e.into()), - ) - })?; + ) -> std::result::Result, tonic::Status> + { + self.inner.ready().await.map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static( - "/VectorService/DescribeIndexStats", - ); + let path = http::uri::PathAndQuery::from_static("/VectorService/DescribeIndexStats"); let mut req = request.into_request(); req.extensions_mut() .insert(GrpcMethod::new("VectorService", "DescribeIndexStats")); @@ -675,10 +652,7 @@ pub mod vector_service_server { async fn describe_index_stats( &self, request: tonic::Request, - ) -> std::result::Result< - tonic::Response, - tonic::Status, - >; + ) -> std::result::Result, tonic::Status>; } /// The `VectorService` interface is exposed by Pinecone's vector index services. /// This service could also be called a `gRPC` service or a `REST`-like api. @@ -705,10 +679,7 @@ pub mod vector_service_server { max_encoding_message_size: None, } } - pub fn with_interceptor( - inner: T, - interceptor: F, - ) -> InterceptedService + pub fn with_interceptor(inner: T, interceptor: F) -> InterceptedService where F: tonic::service::Interceptor, { @@ -764,23 +735,16 @@ pub mod vector_service_server { "/VectorService/Upsert" => { #[allow(non_camel_case_types)] struct UpsertSvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService - for UpsertSvc { + impl tonic::server::UnaryService for UpsertSvc { type Response = super::UpsertResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::upsert(&inner, request).await - }; + let fut = + async move { ::upsert(&inner, request).await }; Box::pin(fut) } } @@ -810,23 +774,16 @@ pub mod vector_service_server { "/VectorService/Delete" => { #[allow(non_camel_case_types)] struct DeleteSvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService - for DeleteSvc { + impl tonic::server::UnaryService for DeleteSvc { type Response = super::DeleteResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::delete(&inner, request).await - }; + let fut = + async move { ::delete(&inner, request).await }; Box::pin(fut) } } @@ -856,22 +813,16 @@ pub mod vector_service_server { "/VectorService/Fetch" => { #[allow(non_camel_case_types)] struct FetchSvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService for FetchSvc { + impl tonic::server::UnaryService for FetchSvc { type Response = super::FetchResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::fetch(&inner, request).await - }; + let fut = + async move { ::fetch(&inner, request).await }; Box::pin(fut) } } @@ -901,22 +852,16 @@ pub mod vector_service_server { "/VectorService/List" => { #[allow(non_camel_case_types)] struct ListSvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService for ListSvc { + impl tonic::server::UnaryService for ListSvc { type Response = super::ListResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::list(&inner, request).await - }; + let fut = + async move { ::list(&inner, request).await }; Box::pin(fut) } } @@ -946,22 +891,16 @@ pub mod vector_service_server { "/VectorService/Query" => { #[allow(non_camel_case_types)] struct QuerySvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService for QuerySvc { + impl tonic::server::UnaryService for QuerySvc { type Response = super::QueryResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::query(&inner, request).await - }; + let fut = + async move { ::query(&inner, request).await }; Box::pin(fut) } } @@ -991,23 +930,16 @@ pub mod vector_service_server { "/VectorService/Update" => { #[allow(non_camel_case_types)] struct UpdateSvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService - for UpdateSvc { + impl tonic::server::UnaryService for UpdateSvc { type Response = super::UpdateResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); - let fut = async move { - ::update(&inner, request).await - }; + let fut = + async move { ::update(&inner, request).await }; Box::pin(fut) } } @@ -1037,23 +969,19 @@ pub mod vector_service_server { "/VectorService/DescribeIndexStats" => { #[allow(non_camel_case_types)] struct DescribeIndexStatsSvc(pub Arc); - impl< - T: VectorService, - > tonic::server::UnaryService - for DescribeIndexStatsSvc { + impl + tonic::server::UnaryService + for DescribeIndexStatsSvc + { type Response = super::DescribeIndexStatsResponse; - type Future = BoxFuture< - tonic::Response, - tonic::Status, - >; + type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { - ::describe_index_stats(&inner, request) - .await + ::describe_index_stats(&inner, request).await }; Box::pin(fut) } @@ -1081,18 +1009,14 @@ pub mod vector_service_server { }; Box::pin(fut) } - _ => { - Box::pin(async move { - Ok( - http::Response::builder() - .status(200) - .header("grpc-status", "12") - .header("content-type", "application/grpc") - .body(empty_body()) - .unwrap(), - ) - }) - } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap()) + }), } } } diff --git a/src/utils/user_agent.rs b/src/utils/user_agent.rs index 10904d4..7cbfb6c 100644 --- a/src/utils/user_agent.rs +++ b/src/utils/user_agent.rs @@ -1,7 +1,7 @@ use regex::Regex; /// Normalizes the source tag. -fn build_source_tag(source_tag: &String) -> String { +fn build_source_tag(source_tag: &str) -> String { // 1. Lowercase // 2. Limit charset to [a-z0-9_ ] // 3. Trim left/right empty space @@ -22,12 +22,9 @@ fn build_source_tag(source_tag: &String) -> String { pub fn get_user_agent(source_tag: Option<&str>) -> String { let mut user_agent = format!("lang=rust; pinecone-rust-client={}", "0.1.0"); if let Some(st) = source_tag { - user_agent.push_str(&format!( - "; source_tag={}", - build_source_tag(&st.to_string()) - )); + user_agent.push_str(&format!("; source_tag={}", build_source_tag(st))); } - return user_agent; + user_agent } #[cfg(test)] diff --git a/tests/common.rs b/tests/common.rs index bd7566a..5128c8f 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -16,22 +16,26 @@ pub fn generate_random_string() -> String { } /// Generates a random index name +#[allow(dead_code)] pub fn generate_index_name() -> String { format!("test-index-{}", generate_random_string()) } /// Generates a random collection name +#[allow(dead_code)] pub fn generate_collection_name() -> String { format!("test-collection-{}", generate_random_string()) } /// Generates a random namespace name +#[allow(dead_code)] pub fn generate_namespace_name() -> Namespace { let name = format!("test-namespace-{}", generate_random_string()); name.into() } /// Generates a random vector of length `length` +#[allow(dead_code)] pub fn generate_vector(length: usize) -> Vec { let mut rng = rand::thread_rng(); (0..length).map(|_| rng.gen()).collect() @@ -48,6 +52,7 @@ pub fn get_pod_index() -> String { } /// Returns the name of the collection from the environment variable +#[allow(dead_code)] pub fn get_collection() -> String { std::env::var("COLLECTION_NAME").unwrap() }