-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
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.
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 { .. })
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.
Looks good to me, but as this is a subjective change I think we should get multiple opinions
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.
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. 🎉
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.
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 thePineconeClient
struct. If the caller wants the oldnew(None, ...)
behavior, they can just callPineconeClient::default()
instead. - Implement
pub fn client() -> Result<PineconeClient, Error>
onPineconeClientConfig
to generate a client from the config. - Implement the
TryFrom
trait forPineconeClient
that calls theclient()
function - Remove
fn PineconeClient::new
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.
Nice improvement!
additional_headers: Option<HashMap<String, String>>, | ||
source_tag: Option<&str>, | ||
) -> Result<Self, PineconeError> { | ||
pub fn client(self) -> Result<PineconeClient, PineconeError> { |
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.
can we change to &self
or does the call need to own/consume the config?
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.
I think the call needs to consume the config, or it would need to clone all the fields
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.
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`. |
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.
nit: Might be worth mentioning that configuration values will be read from the environment in this case.
Problem
Currently,
PineconeClient::new()
takes in four optional arguments, which are often not provided. CallingPineconeClient::new(None, None, None, None)
isn't the best user experience.Solution
I created a
PineconeClientConfig
struct, which takes in all arguments thatPineconeClient::new()
would take in, and then pass in just this one struct into awith_config
function. This struct also implementsDefault
, so the user can set the parameters they want, and use..Default::default()
to fill in the rest. Thenew
function now doesn't take in any parameters and will callwith_config
with all parameters set toNone
.Type of Change
Test Plan
Test cases should pass.