Skip to content

Supports docs-api SLI-checkers on 2025-04 in pinecone-db #66

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: 2025-04
Choose a base branch
from
56 changes: 23 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ exclude = ["tests/*"]
tokio = { version = "1", features = ["full"] }
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"] }
serde_with = { version = "3.12", features = ["base64"] }
# serde_json = "^1.0"
strum = { version = "0.27", features = ["derive"] }
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
reqwest = { version = "^0.12", features = ["json", "multipart"] }
thiserror = "1.0.63"
anyhow = "1.0.86"
Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
//!
//! ```no_run
//! use pinecone_sdk::pinecone;
//! use pinecone_sdk::models::{Cloud, DeletionProtection, IndexModel, Metric, WaitPolicy};
//! use pinecone_sdk::models::{Cloud, DeletionProtection, IndexModel, Metric, VectorType, WaitPolicy};
//! use pinecone_sdk::utils::errors::PineconeError;
//! # async fn create_index_and_collection() -> Result<(), PineconeError> {
//! # async fn create_index() -> Result<(), PineconeError> {
//! let client: pinecone::PineconeClient =
//! pinecone::default_client().expect("Failed to create PineconeClient");
//!
Expand All @@ -63,17 +63,15 @@
//! "us-east-1",
//! DeletionProtection::Disabled,
//! WaitPolicy::NoWait,
//! VectorType::Dense,
//! None,
//! )
//! .await?;
//!
//! let collection = client.create_collection("my-collection-name", "my-previous-index-name").await?;
//!
//! let index_description = client.describe_index("index-name").await?;
//! let collection_description = client.describe_collection("my-collection-name").await?;
//! let indexes = client.list_indexes().await?;
//!
//! println!("Index description: {:?}", index_description);
//! println!("Collection description: {:?}", collection_description);
//! println!("Index list: {:?}", indexes);
//!
//! # Ok(())
Expand Down
58 changes: 58 additions & 0 deletions src/models/cloud.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};

/// The public cloud where you would like your index hosted.
#[derive(
Debug, Default, Clone, Copy, PartialEq, Eq, Display, EnumString, Serialize, Deserialize,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum Cloud {
/// GCP
#[default]
Gcp,
/// AWS
Aws,
/// Azure
Azure,
}

impl From<crate::openapi::models::serverless_spec::Cloud> for Cloud {
fn from(cloud: crate::openapi::models::serverless_spec::Cloud) -> Self {
match cloud {
crate::openapi::models::serverless_spec::Cloud::Gcp => Cloud::Gcp,
crate::openapi::models::serverless_spec::Cloud::Aws => Cloud::Aws,
crate::openapi::models::serverless_spec::Cloud::Azure => Cloud::Azure,
}
}
}

impl From<Cloud> for crate::openapi::models::serverless_spec::Cloud {
fn from(cloud: Cloud) -> Self {
match cloud {
Cloud::Gcp => crate::openapi::models::serverless_spec::Cloud::Gcp,
Cloud::Aws => crate::openapi::models::serverless_spec::Cloud::Aws,
Cloud::Azure => crate::openapi::models::serverless_spec::Cloud::Azure,
}
}
}

impl From<crate::openapi::models::create_index_for_model_request::Cloud> for Cloud {
fn from(cloud: crate::openapi::models::create_index_for_model_request::Cloud) -> Self {
match cloud {
crate::openapi::models::create_index_for_model_request::Cloud::Gcp => Cloud::Gcp,
crate::openapi::models::create_index_for_model_request::Cloud::Aws => Cloud::Aws,
crate::openapi::models::create_index_for_model_request::Cloud::Azure => Cloud::Azure,
}
}
}

impl From<Cloud> for crate::openapi::models::create_index_for_model_request::Cloud {
fn from(cloud: Cloud) -> Self {
match cloud {
Cloud::Gcp => crate::openapi::models::create_index_for_model_request::Cloud::Gcp,
Cloud::Aws => crate::openapi::models::create_index_for_model_request::Cloud::Aws,
Cloud::Azure => crate::openapi::models::create_index_for_model_request::Cloud::Azure,
}
}
}
89 changes: 88 additions & 1 deletion src/models/index_model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::{DeletionProtection, IndexModelSpec, IndexModelStatus, Metric};
use super::{DeletionProtection, IndexModelSpec, IndexModelStatus, Metric, VectorType};
use crate::openapi::models::index_model::IndexModel as OpenApiIndexModel;
use crate::openapi::models::{CreateIndexForModelRequestEmbed, ModelIndexEmbed};
use serde_with::serde_derive::Serialize;
use std::collections::HashMap;

/// IndexModel : The IndexModel describes the configuration and status of a Pinecone index.
#[derive(Clone, Default, Debug, PartialEq)]
Expand All @@ -18,6 +21,12 @@ pub struct IndexModel {
pub spec: IndexModelSpec,
/// Index model specs
pub status: IndexModelStatus,
/// Index tags
pub tags: Option<HashMap<String, String>>,
/// Index embedding configuration
pub embed: Option<ModelIndexEmbed>,
/// Index vector type
pub vector_type: VectorType,
}

impl From<OpenApiIndexModel> for IndexModel {
Expand All @@ -30,6 +39,84 @@ impl From<OpenApiIndexModel> for IndexModel {
deletion_protection: openapi_index_model.deletion_protection,
spec: *openapi_index_model.spec,
status: *openapi_index_model.status,
tags: openapi_index_model.tags,
embed: openapi_index_model.embed.map(|emb| *emb),
vector_type: openapi_index_model.vector_type,
}
}
}

/// A field mapping entry by type.
#[derive(Clone, Debug)]
pub enum FieldMapEntry {
/// The name of the text field from your document model that is embedded.
TextField(String),
}

/// A model parameter value of a specific type.
#[derive(Clone, Debug, Serialize)]
pub enum ModelParameterValue {
/// A string value type
StringVal(String),
/// An integer value type
IntVal(i32),
/// A floating point value type
FloatVal(f32),
/// A boolean value type.
BoolVal(bool),
}

/// Configuration options for the index with integrated embedding.
#[derive(Clone, Debug)]
pub struct CreateIndexForModelOptions {
/// The name of the embedding model to use for the index.
pub model: String,
/// Identifies the name of the field from your document model that will be embedded. (Only one
/// field is supported for now.)
pub field_map: Vec<FieldMapEntry>,
/// The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'. If not specified, the metric will be defaulted according to the model. Cannot be updated once set.
pub metric: Option<Metric>,
/// The desired vector dimension, if supported by the model.
pub dimension: Option<i32>,
/// The read parameters for the embedding model.
pub read_parameters: Option<HashMap<String, ModelParameterValue>>,
/// The write parameters for the embedding model.
pub write_parameters: Option<HashMap<String, ModelParameterValue>>,
}

impl From<CreateIndexForModelOptions> for CreateIndexForModelRequestEmbed {
fn from(options: CreateIndexForModelOptions) -> Self {
let field_map = options
.field_map
.into_iter()
.map(|entry| match entry {
FieldMapEntry::TextField(field_name) => {
("text", serde_json::Value::String(field_name))
}
})
.collect();

let read_parameters = options.read_parameters.map(|params| {
params
.into_iter()
.map(|(key, value)| (key, serde_json::to_value(value).unwrap()))
.collect()
});

let write_parameters = options.write_parameters.map(|params| {
params
.into_iter()
.map(|(key, value)| (key, serde_json::to_value(value).unwrap()))
.collect()
});

CreateIndexForModelRequestEmbed {
model: options.model,
field_map,
metric: options.metric.map(|m| m.into()),
read_parameters,
write_parameters,
dimension: options.dimension,
}
}
}
32 changes: 32 additions & 0 deletions src/models/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,35 @@ impl From<Metric> for ResponseMetric {
}
}
}

impl From<Metric> for crate::openapi::models::create_index_for_model_request_embed::Metric {
fn from(model: Metric) -> Self {
match model {
Metric::Cosine => {
crate::openapi::models::create_index_for_model_request_embed::Metric::Cosine
}
Metric::Euclidean => {
crate::openapi::models::create_index_for_model_request_embed::Metric::Euclidean
}
Metric::Dotproduct => {
crate::openapi::models::create_index_for_model_request_embed::Metric::Dotproduct
}
}
}
}

impl From<crate::openapi::models::create_index_for_model_request_embed::Metric> for Metric {
fn from(model: crate::openapi::models::create_index_for_model_request_embed::Metric) -> Self {
match model {
crate::openapi::models::create_index_for_model_request_embed::Metric::Cosine => {
Metric::Cosine
}
crate::openapi::models::create_index_for_model_request_embed::Metric::Euclidean => {
Metric::Euclidean
}
crate::openapi::models::create_index_for_model_request_embed::Metric::Dotproduct => {
Metric::Dotproduct
}
}
}
}
20 changes: 15 additions & 5 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ mod namespace;
pub use self::namespace::Namespace;

mod index_model;
pub use self::index_model::IndexModel;
pub use self::index_model::{
CreateIndexForModelOptions, FieldMapEntry, IndexModel, ModelParameterValue,
};

mod index_list;
pub use self::index_list::IndexList;
Expand All @@ -22,11 +24,19 @@ pub use self::wait_policy::WaitPolicy;
mod embedding;
pub use self::embedding::Embedding;

mod vector_type;
pub use self::vector_type::VectorType;

mod cloud;
pub use self::cloud::Cloud;

pub use crate::openapi::models::{
index_model_status::State, serverless_spec::Cloud, CollectionList, CollectionModel,
ConfigureIndexRequest, ConfigureIndexRequestSpec, ConfigureIndexRequestSpecPod,
CreateCollectionRequest, DeletionProtection, EmbedRequestParameters, IndexModelSpec,
IndexModelStatus, IndexSpec, PodSpec, PodSpecMetadataConfig, ServerlessSpec,
index_model_status::State, CollectionList, CollectionModel, ConfigureIndexRequest,
ConfigureIndexRequestSpec, ConfigureIndexRequestSpecPod, CreateCollectionRequest,
DeletionProtection, EmbedRequestParameters, IndexModelSpec, IndexModelStatus, IndexSpec,
PodSpec, PodSpecMetadataConfig, SearchRecordsRequest, SearchRecordsRequestQuery,
SearchRecordsRequestRerank, SearchRecordsResponse, ServerlessSpec, UpsertRecord,
UpsertResponse as UpsertRecordResponse,
};

pub use crate::protos::{
Expand Down
16 changes: 16 additions & 0 deletions src/models/vector_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};

/// Vector type, either dense or sparse.
#[derive(
Debug, Default, Clone, Copy, PartialEq, Eq, Display, EnumString, Serialize, Deserialize,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum VectorType {
/// Dense vector type
#[default]
Dense,
/// Sparse vector type
Sparse,
}
Loading