Commit ff4f525
authored
Improve error message when using positional arguments with query() (#292)
## Problem
In v3.0, the order of arguments to `query()` was changed to reflect that
`top_k` is required and should therefore come first in the list of
parameters. This is unfortunate, since it means any usage relying on
`vector` being the first positional parameter will see a cryptic error
about passing two values of `top_k`.
## Solution
Disable positional arguments for this function. This allows us to throw
an error message with clearer instructions to the user.
## Type of Change
- [x] None of the above: Error UX
## Test Plan
Added unit test.
```
>>> from pinecone import Pinecone
>>> pc = Pinecone(api_key='XXX')
>>> index = pc.Index('foo')
>>> index.query([0.1, 0.2], top_k=10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jhamon/workspace/pinecone-python-client/pinecone/utils/error_handling.py", line 10, in inner_func
return func(*args, **kwargs)
File "/Users/jhamon/workspace/pinecone-python-client/pinecone/data/index.py", line 373, in query
raise ValueError("""The argument order for `query()` has changed; please use keyword arguments instead of positional arguments.
ValueError: The argument order for `query()` has changed; please use keyword arguments instead of positional arguments. Example: index.query(vector=[0.1, 0.2, 0.3], top_k=10, namespace='my_namespace')
>>> index.query(vector=[0.1, 0.2], top_k=10)
{"results":[],"matches":[],"namespace":"","usage":{"readUnits":0}}
```1 parent e770c5a commit ff4f525
2 files changed
+10
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| 318 | + | |
318 | 319 | | |
319 | 320 | | |
320 | 321 | | |
| |||
366 | 367 | | |
367 | 368 | | |
368 | 369 | | |
369 | | - | |
| 370 | + | |
| 371 | + | |
370 | 372 | | |
371 | 373 | | |
372 | 374 | | |
373 | 375 | | |
| 376 | + | |
| 377 | + | |
374 | 378 | | |
375 | 379 | | |
376 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
377 | 382 | | |
378 | 383 | | |
379 | 384 | | |
| |||
0 commit comments