Skip to content

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 16 commits into from
Jul 31, 2024

Conversation

ericapywang
Copy link
Contributor

@ericapywang ericapywang commented Jul 30, 2024

Problem

Currently, the SDK uses the generated types, however some of these are difficult to use from the user perspective (poorly defined, multiple versions defined, etc).

Solution

We implement a custom EmbeddingsListUsage, EmbeddingsList, IndexList, IndexModel, and Metric type in a models directory. We also export all openapi types to the same directory so that the imports will all be consistent.

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
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

Test cases should pass.

/// use pinecone_sdk::utils::errors::PineconeError;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), PineconeError>{
/// let pinecone = PineconeClient::new(None, None, None, None).unwrap();
///
/// // List all indexes in the project.
/// let index_list_response: Result<IndexList, PineconeError> = pinecone.list_indexes().await;
/// let index_list_response = pinecone.list_indexes().await;
Copy link
Contributor

Choose a reason for hiding this comment

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

I included the type here previously to be clear about what is being returned, is there a reason for removing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought we previously said not to include it in docstrings examples and only to include it in the README example, but I may be remembering wrong and I'm okay adding it back

@ericapywang ericapywang requested a review from haruska July 30, 2024 21:06
Copy link
Contributor

@ssmith-pc ssmith-pc left a comment

Choose a reason for hiding this comment

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

Really nice

Comment on lines 10 to 11
/// The embeddings generated by the model.
pub data: Vec<Vec<f32>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should still have types to represent the Embedding, since in the future we will introduce other responses alongside values like a sparse embedding that will have a different type than Vec<f32>

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess when we cross that bridge we may find ourselves wanting to re-type these fields as Optional, but let's keep it simple for now.

@ericapywang ericapywang requested a review from ssmith-pc July 31, 2024 15:02
Copy link
Contributor

@ssmith-pc ssmith-pc left a comment

Choose a reason for hiding this comment

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

This looks good to me, but would like to have input from @austin-denoble and @haruska

Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

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

Very nice, looks good to me. I really appreciate the organization here. 🚢

CollectionList, CollectionModel, ConfigureIndexRequest, ConfigureIndexRequestSpec,
ConfigureIndexRequestSpecPod, CreateCollectionRequest, DeletionProtection,
EmbedRequestParameters, IndexModelSpec, IndexModelStatus, IndexSpec, PodSpec,
PodSpecMetadataConfig, ServerlessSpec,
Copy link
Contributor

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.

Copy link
Contributor

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 through pinecone::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.

Copy link

@haruska haruska left a comment

Choose a reason for hiding this comment

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

Good improvement. I'd look into getting rid of the openapi::* re-export if possible to limit the surface area of the models module.

@ericapywang ericapywang marked this pull request as ready for review July 31, 2024 17:46
@ericapywang ericapywang merged commit e511603 into main Jul 31, 2024
1 check passed
@ericapywang ericapywang deleted the emily/custom-types branch July 31, 2024 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants