Skip to content

Create PineconeClientConfig struct #49

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 10 commits into from
Aug 5, 2024
Merged

Conversation

ericapywang
Copy link
Contributor

@ericapywang ericapywang commented Aug 1, 2024

Problem

Currently, PineconeClient::new() takes in four optional arguments, which are often not provided. Calling PineconeClient::new(None, None, None, None) isn't the best user experience.

Solution

I created a PineconeClientConfig struct, which takes in all arguments that PineconeClient::new() would take in, and then pass in just this one struct into a with_config function. This struct also implements Default, so the user can set the parameters they want, and use ..Default::default() to fill in the rest. The new function now doesn't take in any parameters and will call with_config with all parameters set to None.

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.

@ericapywang ericapywang requested review from emily-emily, haruska, austin-denoble and ssmith-pc and removed request for emily-emily August 1, 2024 15:44
@ericapywang ericapywang changed the title create PineconeClientConfig struct Create PineconeClientConfig struct Aug 1, 2024
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 still doesn't really spark joy for me:

PineconeClient::new(Default::default())

What about having a default no-param version:

PineconeClient::new()

and some form of overload:

PineconeClient::from_config(PineconeClientConfig { .. })
or
PineconeClient::with_config(PineconeClientConfig { .. })
or
PineconeClient::new_with_config(PineconeClientConfig { .. })

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.

Looks good to me, but as this is a subjective change I think we should get multiple opinions

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.

Really nice work, I like this approach a lot. It's very similar to what we've done in a number of other SDKs, and feels a lot cleaner to read and work with. 🎉

@ericapywang ericapywang marked this pull request as ready for review August 2, 2024 21:01
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.

This is indeed nicer than the new(None, None, ...) pattern before. It seems most similar to a Golang-style of an input struct to denote named parameters.

An alternative for consideration:

  • Implement the Default trait for the PineconeClient struct. If the caller wants the old new(None, ...) behavior, they can just call PineconeClient::default() instead.
  • Implement pub fn client() -> Result<PineconeClient, Error> on PineconeClientConfig to generate a client from the config.
  • Implement the TryFrom trait for PineconeClient that calls the client() function
  • Remove fn PineconeClient::new

@ericapywang ericapywang requested a review from haruska August 5, 2024 21:16
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.

Nice improvement!

additional_headers: Option<HashMap<String, String>>,
source_tag: Option<&str>,
) -> Result<Self, PineconeError> {
pub fn client(self) -> Result<PineconeClient, PineconeError> {
Copy link

Choose a reason for hiding this comment

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

can we change to &self or does the call need to own/consume the config?

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 think the call needs to consume the config, or it would need to clone all the fields

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.

LGTM, just one README nit. Great work!

README.md Outdated
```

### Default client
Use the `default_client()` function, which is the equivalent of constructing a `PineconeClientConfig` struct with all fields set to `None`.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Might be worth mentioning that configuration values will be read from the environment in this case.

@ericapywang ericapywang merged commit e80ce32 into main Aug 5, 2024
1 check passed
@ericapywang ericapywang deleted the erica/pinecone-client-params branch August 5, 2024 22:08
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.

4 participants