Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pinecone/data/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def fetch(self, ids: List[str], namespace: Optional[str] = None, **kwargs) -> Fe
@validate_and_convert_errors
def query(
self,
*args,
top_k: int,
vector: Optional[List[float]] = None,
id: Optional[str] = None,
Expand Down Expand Up @@ -366,11 +367,14 @@ def query(
and namespace name.
"""

_check_type = kwargs.pop("_check_type", False)
if len(args) > 0:
raise 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')")

if vector is not None and id is not None:
raise ValueError("Cannot specify both `id` and `vector`")

_check_type = kwargs.pop("_check_type", False)

sparse_vector = self._parse_sparse_values_arg(sparse_vector)
args_dict = self._parse_non_empty_args(
[
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ def test_query_rejects_both_id_and_vector(self):
with pytest.raises(ValueError, match="Cannot specify both `id` and `vector`"):
self.index.query(top_k=10, id="vec1", vector=[1, 2, 3])

def test_query_with_positional_args(self, mocker):
with pytest.raises(ValueError) as e:
self.index.query([0.1, 0.2, 0.3], top_k=10)
assert "The argument order for `query()` has changed; please use keyword arguments instead of positional arguments" in str(e.value)

# endregion

# region: delete tests
Expand Down