Skip to content
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

fix: fix integer index conversion #640

Merged
merged 1 commit into from
Jun 7, 2024
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
24 changes: 24 additions & 0 deletions qdrant_client/conversions/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ def convert_payload_schema_params(
if model.HasField("text_index_params"):
text_index_params = model.text_index_params
return cls.convert_text_index_params(text_index_params)
if model.HasField("integer_index_params"):
integer_index_params = model.integer_index_params
return cls.convert_integer_index_params(integer_index_params)

raise ValueError(f"invalid PayloadIndexParams model: {model}") # pragma: no cover

Expand Down Expand Up @@ -988,6 +991,16 @@ def convert_text_index_params(cls, model: grpc.TextIndexParams) -> rest.TextInde
lowercase=model.lowercase if model.HasField("lowercase") else None,
)

@classmethod
def convert_integer_index_params(
cls, model: grpc.IntegerIndexParams
) -> rest.IntegerIndexParams:
return rest.IntegerIndexParams(
type=rest.IntegerIndexType.INTEGER,
range=model.range,
lookup=model.lookup,
)

@classmethod
def convert_collection_params_diff(
cls, model: grpc.CollectionParamsDiff
Expand Down Expand Up @@ -1578,6 +1591,11 @@ def convert_payload_schema_params(
if isinstance(model, rest.TextIndexParams):
return grpc.PayloadIndexParams(text_index_params=cls.convert_text_index_params(model))

if isinstance(model, rest.IntegerIndexParams):
return grpc.PayloadIndexParams(
integer_index_params=cls.convert_integer_index_params(model)
)

raise ValueError(f"invalid PayloadSchemaParams model: {model}") # pragma: no cover

@classmethod
Expand Down Expand Up @@ -2402,6 +2420,12 @@ def convert_text_index_params(cls, model: rest.TextIndexParams) -> grpc.TextInde
max_token_len=model.max_token_len,
)

@classmethod
def convert_integer_index_params(
cls, model: rest.IntegerIndexParams
) -> grpc.IntegerIndexParams:
return grpc.IntegerIndexParams(lookup=model.lookup, range=model.range)

@classmethod
def convert_collection_params_diff(
cls, model: rest.CollectionParamsDiff
Expand Down
37 changes: 37 additions & 0 deletions tests/conversions/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@

text_index_params_4 = grpc.TextIndexParams(tokenizer=grpc.TokenizerType.Multilingual)

integer_index_params_0 = grpc.IntegerIndexParams(lookup=True, range=False)
integer_index_params_1 = grpc.IntegerIndexParams(lookup=False, range=True)
integer_index_params_2 = grpc.IntegerIndexParams(lookup=True, range=True)


payload_schema_text_prefix = grpc.PayloadSchemaInfo(
data_type=grpc.PayloadSchemaType.Text,
params=grpc.PayloadIndexParams(text_index_params=text_index_params_1),
Expand All @@ -362,6 +367,24 @@
points=0,
)

payload_schema_integer_lookup = grpc.PayloadSchemaInfo(
data_type=grpc.PayloadSchemaType.Integer,
params=grpc.PayloadIndexParams(integer_index_params=integer_index_params_0),
points=0,
)

payload_schema_integer_range = grpc.PayloadSchemaInfo(
data_type=grpc.PayloadSchemaType.Integer,
params=grpc.PayloadIndexParams(integer_index_params=integer_index_params_1),
points=0,
)

payload_schema_integer_lookup_and_range = grpc.PayloadSchemaInfo(
data_type=grpc.PayloadSchemaType.Integer,
params=grpc.PayloadIndexParams(integer_index_params=integer_index_params_2),
points=0,
)

collection_info_grey = grpc.CollectionInfo(
status=collection_status_grey,
optimizer_status=optimizer_status_error,
Expand Down Expand Up @@ -391,6 +414,9 @@
"text_field_multilingual": payload_schema_text_multilingual,
"bool_field": payload_schema_bool,
"datetime_field": payload_schema_datetime,
"integer_lookup": payload_schema_integer_lookup,
"integer_range": payload_schema_integer_range,
"integer_lookup_and_range": payload_schema_integer_lookup_and_range,
},
)

Expand All @@ -413,6 +439,9 @@
"text_field_multilingual": payload_schema_text_multilingual,
"bool_field": payload_schema_bool,
"datetime_field": payload_schema_datetime,
"integer_lookup": payload_schema_integer_lookup,
"integer_range": payload_schema_integer_range,
"integer_lookup_and_range": payload_schema_integer_lookup_and_range,
},
)

Expand All @@ -435,6 +464,9 @@
"text_field_multilingual": payload_schema_text_multilingual,
"bool_field": payload_schema_bool,
"datetime_field": payload_schema_datetime,
"integer_lookup": payload_schema_integer_lookup,
"integer_range": payload_schema_integer_range,
"integer_lookup_and_range": payload_schema_integer_lookup_and_range,
},
)
quantization_config = grpc.QuantizationConfig(
Expand Down Expand Up @@ -967,6 +999,11 @@
text_index_params_2,
text_index_params_3,
],
"IntegerIndexParams": [
integer_index_params_0,
integer_index_params_1,
integer_index_params_2,
],
"CollectionParamsDiff": [collections_params_diff],
"LookupLocation": [lookup_location_1, lookup_location_2],
"ReadConsistency": [
Expand Down
Loading