[Feat] Helpful error when incorrectly instantiating Index client #418
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.
Problem
Sometimes users incorrectly instantiate the Index client like this:
Then they will later get an authentication exception when using it, since the
Index
class does not have the configuration values it needs when attempting to perform vector operations.Solution
Index
implementation to_Index
so that people will not accidentally interact with it.Index
that throws an informative message.Bonus:
index.py
file. I copied this approach from the grpc module. pdoc seems to still find and render the docs okay when doing this.Usage
The error message incorporates the args/kwargs the user was attempting to pass.
One positional arg
Multiple positional args
One keyword arg:
Multiple kwargs
Mixed args/kwargs
Type of Change
This change is a UX feature that could be considered breaking if someone was importing
Index
directly and going out of their way to set it up correctly. This was never documented usage, but somebody skilled at reading code could have figured out how to do this.