-
Notifications
You must be signed in to change notification settings - Fork 1
Implement custom types for inference and control plane #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f95fe00
Write custom types for inference
emily-emily 25a4f72
Merge branch 'main' into emily/custom-types
ericapywang 90bdab7
add custom metric type
ericapywang 906b660
add custom metric type
ericapywang 3a0be27
add custom types for IndexModel and all affected types
ericapywang 1077be7
add index_model file
ericapywang d5a83f8
added some documentation
ericapywang 860a51e
remove new function and boxed types
ericapywang d239e08
fix formatting
ericapywang 1d46743
export all control plane types
ericapywang 6d73fa6
changed imports for custom types
ericapywang a12ad32
fix docstrings
ericapywang 9ba593e
fix variable naming, use default tag for metric
ericapywang b46fc90
Add embedding struct and remove clone
emily-emily 21c3d87
add derivations for structs
ericapywang 43ebd66
Move openapi re-exports to models/mod.rs
emily-emily File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::openapi::models::Embedding as OpenApiEmbedding; | ||
|
||
/// Embedding | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub struct Embedding { | ||
/// Embedding values | ||
values: Vec<f32>, | ||
} | ||
|
||
impl From<OpenApiEmbedding> for Embedding { | ||
fn from(openapi_model: OpenApiEmbedding) -> Self { | ||
Embedding { | ||
values: openapi_model | ||
.values | ||
.unwrap_or_default() | ||
.into_iter() | ||
.map(|x| x as f32) | ||
.collect(), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use super::{Embedding, EmbeddingsListUsage}; | ||
use crate::openapi::models::EmbeddingsList as OpenApiEmbeddingsList; | ||
|
||
/// EmbeddingsList : Embeddings generated for the input | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub struct EmbeddingsList { | ||
/// The model used to generate the embeddings. | ||
pub model: String, | ||
/// The embeddings generated by the model. | ||
pub data: Vec<Embedding>, | ||
/// The total number of tokens processed. | ||
pub usage: EmbeddingsListUsage, | ||
} | ||
|
||
impl From<OpenApiEmbeddingsList> for EmbeddingsList { | ||
fn from(openapi_model: OpenApiEmbeddingsList) -> Self { | ||
EmbeddingsList { | ||
model: openapi_model.model.unwrap_or_default(), | ||
data: openapi_model | ||
.data | ||
.unwrap_or_default() | ||
.into_iter() | ||
.map(|x| x.into()) | ||
.collect(), | ||
usage: (*openapi_model.usage.unwrap_or_default()).into(), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::openapi::models::EmbeddingsListUsage as OpenApiEmbeddingsListUsage; | ||
|
||
/// EmbeddingsListUsage : Usage statistics for model inference including any instruction prefixes | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub struct EmbeddingsListUsage { | ||
/// The total number of tokens processed. | ||
pub total_tokens: i32, | ||
} | ||
|
||
impl From<OpenApiEmbeddingsListUsage> for EmbeddingsListUsage { | ||
fn from(openapi_model: OpenApiEmbeddingsListUsage) -> Self { | ||
EmbeddingsListUsage { | ||
total_tokens: openapi_model.total_tokens.unwrap_or(0), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::IndexModel; | ||
use crate::openapi::models::IndexList as OpenApiIndexList; | ||
|
||
/// IndexList : The list of indexes that exist in the project. | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub struct IndexList { | ||
/// The list of indexes | ||
pub indexes: Option<Vec<IndexModel>>, | ||
} | ||
|
||
impl From<OpenApiIndexList> for IndexList { | ||
fn from(index_list: OpenApiIndexList) -> Self { | ||
IndexList { | ||
indexes: index_list | ||
.indexes | ||
.map(|index| index.into_iter().map(|index| index.into()).collect()), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use super::{DeletionProtection, IndexModelSpec, IndexModelStatus, Metric}; | ||
use crate::openapi::models::index_model::IndexModel as OpenApiIndexModel; | ||
|
||
/// IndexModel : The IndexModel describes the configuration and status of a Pinecone index. | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub struct IndexModel { | ||
/// Index name | ||
pub name: String, | ||
/// Index dimension | ||
pub dimension: i32, | ||
/// Index metric | ||
pub metric: Metric, | ||
/// Index host | ||
pub host: String, | ||
/// Index deletion protection configuration | ||
pub deletion_protection: Option<DeletionProtection>, | ||
/// Index specs | ||
pub spec: IndexModelSpec, | ||
/// Index model specs | ||
pub status: IndexModelStatus, | ||
} | ||
|
||
impl From<OpenApiIndexModel> for IndexModel { | ||
fn from(openapi_index_model: OpenApiIndexModel) -> Self { | ||
IndexModel { | ||
name: openapi_index_model.name, | ||
dimension: openapi_index_model.dimension, | ||
metric: openapi_index_model.metric.into(), | ||
host: openapi_index_model.host, | ||
deletion_protection: openapi_index_model.deletion_protection, | ||
spec: *openapi_index_model.spec, | ||
status: *openapi_index_model.status, | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::openapi::models::create_index_request::Metric as RequestMetric; | ||
use crate::openapi::models::index_model::Metric as ResponseMetric; | ||
|
||
/// The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'. | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub enum Metric { | ||
/// Cosine similarity | ||
#[default] | ||
Cosine, | ||
/// Euclidean distance similarity | ||
Euclidean, | ||
/// Dot product similarity | ||
Dotproduct, | ||
} | ||
|
||
impl From<RequestMetric> for Metric { | ||
fn from(openapi_model: RequestMetric) -> Self { | ||
match openapi_model { | ||
RequestMetric::Cosine => Metric::Cosine, | ||
RequestMetric::Euclidean => Metric::Euclidean, | ||
RequestMetric::Dotproduct => Metric::Dotproduct, | ||
} | ||
} | ||
} | ||
|
||
impl From<ResponseMetric> for Metric { | ||
fn from(openapi_model: ResponseMetric) -> Self { | ||
match openapi_model { | ||
ResponseMetric::Cosine => Metric::Cosine, | ||
ResponseMetric::Euclidean => Metric::Euclidean, | ||
ResponseMetric::Dotproduct => Metric::Dotproduct, | ||
} | ||
} | ||
} | ||
|
||
impl From<Metric> for RequestMetric { | ||
fn from(model: Metric) -> Self { | ||
match model { | ||
Metric::Cosine => RequestMetric::Cosine, | ||
Metric::Euclidean => RequestMetric::Euclidean, | ||
Metric::Dotproduct => RequestMetric::Dotproduct, | ||
} | ||
} | ||
} | ||
|
||
impl From<Metric> for ResponseMetric { | ||
fn from(model: Metric) -> Self { | ||
match model { | ||
Metric::Cosine => ResponseMetric::Cosine, | ||
Metric::Euclidean => ResponseMetric::Euclidean, | ||
Metric::Dotproduct => ResponseMetric::Dotproduct, | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
mod embeddings_list; | ||
pub use self::embeddings_list::EmbeddingsList; | ||
|
||
mod embeddings_list_usage; | ||
pub use self::embeddings_list_usage::EmbeddingsListUsage; | ||
|
||
mod metric; | ||
pub use self::metric::Metric; | ||
|
||
mod index_model; | ||
pub use self::index_model::IndexModel; | ||
|
||
mod index_list; | ||
pub use self::index_list::IndexList; | ||
|
||
mod wait_policy; | ||
pub use self::wait_policy::WaitPolicy; | ||
|
||
mod embedding; | ||
pub use self::embedding::Embedding; | ||
|
||
mod openapi; | ||
pub use self::openapi::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub use crate::openapi::models::serverless_spec::Cloud; | ||
pub use crate::openapi::models::{ | ||
CollectionList, CollectionModel, ConfigureIndexRequest, ConfigureIndexRequestSpec, | ||
ConfigureIndexRequestSpecPod, CreateCollectionRequest, DeletionProtection, | ||
EmbedRequestParameters, IndexModelSpec, IndexModelStatus, IndexSpec, PodSpec, | ||
PodSpecMetadataConfig, ServerlessSpec, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::time::Duration; | ||
|
||
/// Defines the wait policy for index creation. | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum WaitPolicy { | ||
/// Wait for the index to become ready, up to the specified duration. | ||
WaitFor(Duration), | ||
|
||
/// Do not wait for the index to become ready -- return immediately. | ||
NoWait, | ||
} | ||
|
||
impl Default for WaitPolicy { | ||
fn default() -> Self { | ||
WaitPolicy::WaitFor(Duration::from_secs(300)) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Rust, does this essentially re-export these models from the
models
module for easier organization?We do something similar in TypeScript with mixing generated types and custom types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, outside the sdk you'd be able to import these openapi types through
pinecone::models
instead of the openapi folder. The openapi types are still accessible throughpinecone::openapi::<type>
though because we need to be able to access them from the sibling module, but I can see if there's a way to change that in a follow-up to this PR.