Skip to content

Commit bce979c

Browse files
Raise an exception in case of excess fields
In the case when user passed a misstyped column name (e.g. 'metadat'), a warning won't be sufficient as the result is unpredictable
1 parent 5520462 commit bce979c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pinecone/core/grpc/index_grpc.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44
import logging
55
import numbers
6-
import warnings
76
from abc import ABC, abstractmethod
87
from functools import wraps
98
from typing import NamedTuple, Optional, Dict, Iterable, Union, List, Tuple, Any
@@ -340,8 +339,8 @@ def _dict_to_grpc_vector(item):
340339

341340
excessive_keys = item_keys - (REQUIRED_VECTOR_FIELDS | OPTIONAL_VECTOR_FIELDS)
342341
if len(excessive_keys) > 0:
343-
warnings.warn(f"Found excessive keys in the vector dictionary: {list(excessive_keys)}. "
344-
f"These keys will be ignored. The allowed keys are: {list(REQUIRED_VECTOR_FIELDS | OPTIONAL_VECTOR_FIELDS)}")
342+
raise ValueError(f"Found excess keys in the vector dictionary: {list(excessive_keys)}. "
343+
f"The allowed keys are: {list(REQUIRED_VECTOR_FIELDS | OPTIONAL_VECTOR_FIELDS)}")
345344

346345
sparse_values = None
347346
if 'sparse_values' in item:
@@ -377,7 +376,7 @@ def _vector_transform(item):
377376
if len(item) > 3:
378377
raise ValueError(f"Found a tuple of length {len(item)} which is not supported. "
379378
f"Vectors can be represented as tuples either the form (id, values, metadata) or (id, values). "
380-
f"To pass sparse values please use either dicts or a GRPCVector objects as inputs.")
379+
f"To pass sparse values please use either dicts or GRPCVector objects as inputs.")
381380
id, values, metadata = fix_tuple_length(item, 3)
382381
return GRPCVector(id=id, values=values, metadata=dict_to_proto_struct(metadata) or {})
383382
elif isinstance(item, Mapping):

pinecone/index.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright (c) 2020-2021 Pinecone Systems Inc. All right reserved.
33
#
44
import numbers
5-
import warnings
65

76
from tqdm import tqdm
87
from collections.abc import Iterable, Mapping
@@ -174,8 +173,8 @@ def _dict_to_vector(item):
174173

175174
excessive_keys = item_keys - (REQUIRED_VECTOR_FIELDS | OPTIONAL_VECTOR_FIELDS)
176175
if len(excessive_keys) > 0:
177-
warnings.warn(f"Found excessive keys in the vector dictionary: {list(excessive_keys)}. "
178-
f"These keys will be ignored. The allowed keys are: {list(REQUIRED_VECTOR_FIELDS | OPTIONAL_VECTOR_FIELDS)}")
176+
raise ValueError(f"Found excess keys in the vector dictionary: {list(excessive_keys)}. "
177+
f"The allowed keys are: {list(REQUIRED_VECTOR_FIELDS | OPTIONAL_VECTOR_FIELDS)}")
179178

180179
sparse_values = None
181180
if 'sparse_values' in item:

0 commit comments

Comments
 (0)