Skip to content

Commit 8c4488b

Browse files
committed
Switch to enums, remove repeated path
1 parent 3c53626 commit 8c4488b

19 files changed

Lines changed: 267 additions & 141 deletions

weaviate/collections/grpc/query.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -540,37 +540,50 @@ def _metadata_to_grpc(self, metadata: _MetadataQuery) -> search_get_pb2.Metadata
540540
vectors=metadata.vectors,
541541
)
542542

543+
_CURVE_TO_PROTO = {
544+
"exp": search_get_pb2.DECAY_CURVE_EXPONENTIAL,
545+
"gauss": search_get_pb2.DECAY_CURVE_GAUSS,
546+
"linear": search_get_pb2.DECAY_CURVE_LINEAR,
547+
}
548+
549+
_MODIFIER_TO_PROTO = {
550+
"none": search_get_pb2.PROPERTY_VALUE_MODIFIER_NONE,
551+
"log1p": search_get_pb2.PROPERTY_VALUE_MODIFIER_LOG1P,
552+
"sqrt": search_get_pb2.PROPERTY_VALUE_MODIFIER_SQRT,
553+
}
554+
543555
def __boost_to_grpc(
544556
self, boost: Optional[_Boost]
545557
) -> Optional[search_get_pb2.Boost]:
546558
if boost is None:
547559
return None
548560
conditions = []
549561
for cond in boost.conditions:
550-
grpc_cond = search_get_pb2.BoostCondition(
551-
filter=_FilterToGRPC.convert(cond.filter) if cond.filter is not None else None,
552-
decay=(
562+
grpc_cond = search_get_pb2.BoostCondition(weight=cond.weight)
563+
if cond.filter is not None:
564+
grpc_cond.filter.CopyFrom(_FilterToGRPC.convert(cond.filter))
565+
elif cond.decay is not None:
566+
grpc_cond.decay.CopyFrom(
553567
search_get_pb2.DecayFunction(
554-
path=[cond.decay.property],
568+
property=cond.decay.property,
555569
origin=cond.decay.origin,
556570
scale=cond.decay.scale,
557571
offset=cond.decay.offset,
558-
curve=cond.decay.curve,
572+
curve=self._CURVE_TO_PROTO.get(
573+
cond.decay.curve, search_get_pb2.DECAY_CURVE_EXPONENTIAL
574+
) if cond.decay.curve is not None else search_get_pb2.DECAY_CURVE_EXPONENTIAL,
559575
decay_value=cond.decay.decay_value,
560576
)
561-
if cond.decay is not None
562-
else None
563-
),
564-
property_value=(
577+
)
578+
elif cond.property_value is not None:
579+
grpc_cond.property_value.CopyFrom(
565580
search_get_pb2.PropertyValueFunction(
566-
path=[cond.property_value.property],
567-
modifier=cond.property_value.modifier,
581+
property=cond.property_value.property,
582+
modifier=self._MODIFIER_TO_PROTO.get(
583+
cond.property_value.modifier, search_get_pb2.PROPERTY_VALUE_MODIFIER_NONE
584+
) if cond.property_value.modifier is not None else search_get_pb2.PROPERTY_VALUE_MODIFIER_NONE,
568585
)
569-
if cond.property_value is not None
570-
else None
571-
),
572-
weight=cond.weight,
573-
)
586+
)
574587
conditions.append(grpc_cond)
575588
return search_get_pb2.Boost(conditions=conditions, weight=boost.weight, depth=boost.depth)
576589

weaviate/proto/v1/v4216/v1/search_get_pb2.py

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

weaviate/proto/v1/v4216/v1/search_get_pb2.pyi

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@ from weaviate.proto.v1.v4216.v1 import base_search_pb2 as _base_search_pb2
33
from weaviate.proto.v1.v4216.v1 import generative_pb2 as _generative_pb2
44
from weaviate.proto.v1.v4216.v1 import properties_pb2 as _properties_pb2
55
from google.protobuf.internal import containers as _containers
6+
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
67
from google.protobuf import descriptor as _descriptor
78
from google.protobuf import message as _message
89
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union
910

1011
DESCRIPTOR: _descriptor.FileDescriptor
1112

13+
class PropertyValueModifier(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
14+
__slots__ = ()
15+
PROPERTY_VALUE_MODIFIER_NONE: _ClassVar[PropertyValueModifier]
16+
PROPERTY_VALUE_MODIFIER_LOG1P: _ClassVar[PropertyValueModifier]
17+
PROPERTY_VALUE_MODIFIER_SQRT: _ClassVar[PropertyValueModifier]
18+
19+
class DecayCurve(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
20+
__slots__ = ()
21+
DECAY_CURVE_EXPONENTIAL: _ClassVar[DecayCurve]
22+
DECAY_CURVE_GAUSS: _ClassVar[DecayCurve]
23+
DECAY_CURVE_LINEAR: _ClassVar[DecayCurve]
24+
PROPERTY_VALUE_MODIFIER_NONE: PropertyValueModifier
25+
PROPERTY_VALUE_MODIFIER_LOG1P: PropertyValueModifier
26+
PROPERTY_VALUE_MODIFIER_SQRT: PropertyValueModifier
27+
DECAY_CURVE_EXPONENTIAL: DecayCurve
28+
DECAY_CURVE_GAUSS: DecayCurve
29+
DECAY_CURVE_LINEAR: DecayCurve
30+
1231
class SearchRequest(_message.Message):
1332
__slots__ = ("collection", "tenant", "consistency_level", "properties", "metadata", "group_by", "limit", "offset", "autocut", "after", "sort_by", "filters", "hybrid_search", "bm25_search", "near_vector", "near_object", "near_text", "near_image", "near_audio", "near_video", "near_depth", "near_thermal", "near_imu", "generative", "rerank", "boost", "uses_123_api", "uses_125_api", "uses_127_api")
1433
COLLECTION_FIELD_NUMBER: _ClassVar[int]
@@ -326,37 +345,37 @@ class Boost(_message.Message):
326345
def __init__(self, conditions: _Optional[_Iterable[_Union[BoostCondition, _Mapping]]] = ..., weight: _Optional[float] = ..., depth: _Optional[int] = ...) -> None: ...
327346

328347
class BoostCondition(_message.Message):
329-
__slots__ = ("filter", "decay", "weight", "property_value")
348+
__slots__ = ("filter", "decay", "property_value", "weight")
330349
FILTER_FIELD_NUMBER: _ClassVar[int]
331350
DECAY_FIELD_NUMBER: _ClassVar[int]
332-
WEIGHT_FIELD_NUMBER: _ClassVar[int]
333351
PROPERTY_VALUE_FIELD_NUMBER: _ClassVar[int]
352+
WEIGHT_FIELD_NUMBER: _ClassVar[int]
334353
filter: _base_pb2.Filters
335354
decay: DecayFunction
336-
weight: float
337355
property_value: PropertyValueFunction
338-
def __init__(self, filter: _Optional[_Union[_base_pb2.Filters, _Mapping]] = ..., decay: _Optional[_Union[DecayFunction, _Mapping]] = ..., weight: _Optional[float] = ..., property_value: _Optional[_Union[PropertyValueFunction, _Mapping]] = ...) -> None: ...
356+
weight: float
357+
def __init__(self, filter: _Optional[_Union[_base_pb2.Filters, _Mapping]] = ..., decay: _Optional[_Union[DecayFunction, _Mapping]] = ..., property_value: _Optional[_Union[PropertyValueFunction, _Mapping]] = ..., weight: _Optional[float] = ...) -> None: ...
339358

340359
class PropertyValueFunction(_message.Message):
341-
__slots__ = ("path", "modifier")
342-
PATH_FIELD_NUMBER: _ClassVar[int]
360+
__slots__ = ("property", "modifier")
361+
PROPERTY_FIELD_NUMBER: _ClassVar[int]
343362
MODIFIER_FIELD_NUMBER: _ClassVar[int]
344-
path: _containers.RepeatedScalarFieldContainer[str]
345-
modifier: str
346-
def __init__(self, path: _Optional[_Iterable[str]] = ..., modifier: _Optional[str] = ...) -> None: ...
363+
property: str
364+
modifier: PropertyValueModifier
365+
def __init__(self, property: _Optional[str] = ..., modifier: _Optional[_Union[PropertyValueModifier, str]] = ...) -> None: ...
347366

348367
class DecayFunction(_message.Message):
349-
__slots__ = ("path", "origin", "scale", "offset", "curve", "decay_value")
350-
PATH_FIELD_NUMBER: _ClassVar[int]
368+
__slots__ = ("property", "origin", "scale", "offset", "curve", "decay_value")
369+
PROPERTY_FIELD_NUMBER: _ClassVar[int]
351370
ORIGIN_FIELD_NUMBER: _ClassVar[int]
352371
SCALE_FIELD_NUMBER: _ClassVar[int]
353372
OFFSET_FIELD_NUMBER: _ClassVar[int]
354373
CURVE_FIELD_NUMBER: _ClassVar[int]
355374
DECAY_VALUE_FIELD_NUMBER: _ClassVar[int]
356-
path: _containers.RepeatedScalarFieldContainer[str]
375+
property: str
357376
origin: str
358377
scale: str
359378
offset: str
360-
curve: str
379+
curve: DecayCurve
361380
decay_value: float
362-
def __init__(self, path: _Optional[_Iterable[str]] = ..., origin: _Optional[str] = ..., scale: _Optional[str] = ..., offset: _Optional[str] = ..., curve: _Optional[str] = ..., decay_value: _Optional[float] = ...) -> None: ...
381+
def __init__(self, property: _Optional[str] = ..., origin: _Optional[str] = ..., scale: _Optional[str] = ..., offset: _Optional[str] = ..., curve: _Optional[_Union[DecayCurve, str]] = ..., decay_value: _Optional[float] = ...) -> None: ...

weaviate/proto/v1/v5261/v1/aggregate_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55

66

7-
GRPC_GENERATED_VERSION = '1.63.0'
7+
GRPC_GENERATED_VERSION = '1.64.1'
88
GRPC_VERSION = grpc.__version__
99
EXPECTED_ERROR_RELEASE = '1.65.0'
1010
SCHEDULED_RELEASE_DATE = 'June 25, 2024'

weaviate/proto/v1/v5261/v1/base_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55

66

7-
GRPC_GENERATED_VERSION = '1.63.0'
7+
GRPC_GENERATED_VERSION = '1.64.1'
88
GRPC_VERSION = grpc.__version__
99
EXPECTED_ERROR_RELEASE = '1.65.0'
1010
SCHEDULED_RELEASE_DATE = 'June 25, 2024'

0 commit comments

Comments
 (0)