Skip to content

Commit

Permalink
V0.8.0 (#45)
Browse files Browse the repository at this point in the history
* updates for v0.8.0

* update dependencies

* fix: use strict bool
  • Loading branch information
generall authored Jun 8, 2022
1 parent 3f9f810 commit eb15dc3
Show file tree
Hide file tree
Showing 21 changed files with 1,344 additions and 748 deletions.
443 changes: 221 additions & 222 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "qdrant_client"
version = "0.7.3"
version = "0.8.0"
description = "Client library for the Qdrant vector search engine"
authors = ["Andrey Vasnetsov <[email protected]>"]
packages = [
Expand All @@ -15,7 +15,7 @@ keywords = ["vector", "search", "neural", "matching", "client"]

[tool.poetry.dependencies]
python = ">=3.7,<4.0"
httpx = "^0.22.0"
httpx = "^0.23.0"
numpy = "^1.21"
pydantic = "^1.8"
tqdm = "^4.56.0"
Expand Down
10 changes: 9 additions & 1 deletion qdrant_client/conversions/common_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Type, List
from typing import Union, Type, List, Optional

import betterproto
from pydantic import BaseModel
Expand All @@ -17,8 +17,16 @@
PayloadSchemaType = Union[rest.PayloadSchemaType, grpc.PayloadSchemaType]
Points = Union[rest.Batch, List[Union[rest.PointStruct, grpc.PointStruct]]]
PointsSelector = Union[rest.PointsSelector, grpc.PointsSelector]
AliasOperations = Union[
rest.CreateAliasOperation,
rest.RenameAliasOperation,
rest.DeleteAliasOperation,
grpc.AliasOperations
]
Payload = rest.Payload

ScoredPoint = rest.ScoredPoint
UpdateResult = rest.UpdateResult
Record = rest.Record
CollectionsResponse = rest.CollectionsResponse
CollectionInfo = rest.CollectionInfo
54 changes: 28 additions & 26 deletions qdrant_client/conversions/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qdrant_client import grpc
from qdrant_client.http.models import models as rest
from betterproto.lib.google.protobuf import Value, ListValue, Struct, NullValue
from qdrant_client.grpc import Value, ListValue, Struct, NullValue


def json_to_value(payload: Any) -> Value:
Expand All @@ -13,9 +13,9 @@ def json_to_value(payload: Any) -> Value:
if isinstance(payload, bool):
return Value(bool_value=payload)
if isinstance(payload, int):
return Value(number_value=payload)
return Value(integer_value=payload)
if isinstance(payload, float):
return Value(number_value=payload)
return Value(double_value=payload)
if isinstance(payload, str):
return Value(string_value=payload)
if isinstance(payload, list):
Expand All @@ -27,23 +27,29 @@ def json_to_value(payload: Any) -> Value:

def value_to_json(value: Value) -> Any:
if isinstance(value, Value):
value = value.to_dict(casing=betterproto.Casing.CAMEL)

if "numberValue" in value:
return value["numberValue"]
if "stringValue" in value:
return value["stringValue"]
if "boolValue" in value:
return value["boolValue"]
if "structValue" in value:
if 'fields' not in value['structValue']:
value_ = value.to_dict(casing=betterproto.Casing.CAMEL)
else:
value_ = value

if "integerValue" in value_:
# by default int are represented as string for precision
# But in python it is OK to just use `int`
return int(value_["integerValue"])
if "doubleValue" in value_:
return value_["doubleValue"]
if "stringValue" in value_:
return value_["stringValue"]
if "boolValue" in value_:
return value_["boolValue"]
if "structValue" in value_:
if 'fields' not in value_['structValue']:
return {}
return dict((key, value_to_json(val)) for key, val in value["structValue"]['fields'].items())
if "listValue" in value:
return list(value_to_json(val) for val in value["listValue"]['values'])
if "nullValue" in value:
return dict((key, value_to_json(val)) for key, val in value_["structValue"]['fields'].items())
if "listValue" in value_:
return list(value_to_json(val) for val in value_["listValue"]['values'])
if "nullValue" in value_:
return None
raise ValueError(f"Not supported value: {value}") # pragma: no cover
raise ValueError(f"Not supported value: {value_}") # pragma: no cover


def payload_to_grpc(payload: Dict[str, Any]) -> Dict[str, Value]:
Expand Down Expand Up @@ -160,7 +166,6 @@ def convert_optimizer_config(cls, model: grpc.OptimizersConfigDiff) -> rest.Opti
max_optimization_threads=model.max_optimization_threads,
max_segment_size=model.max_segment_size,
memmap_threshold=model.memmap_threshold,
payload_indexing_threshold=model.payload_indexing_threshold,
vacuum_min_vector_number=model.vacuum_min_vector_number
)

Expand Down Expand Up @@ -371,7 +376,6 @@ def convert_optimizers_config_diff(cls, model: grpc.OptimizersConfigDiff) -> res
max_optimization_threads=model.max_optimization_threads,
max_segment_size=model.max_segment_size,
memmap_threshold=model.memmap_threshold,
payload_indexing_threshold=model.payload_indexing_threshold,
vacuum_min_vector_number=model.vacuum_min_vector_number,
)

Expand Down Expand Up @@ -424,9 +428,9 @@ def convert_with_payload_selector(cls, model: grpc.WithPayloadSelector) -> rest.
if name == "enable":
return val
if name == "include":
return val.include
return val.fields
if name == "exclude":
return rest.PayloadSelectorExclude(exclude=val.exclude)
return rest.PayloadSelectorExclude(exclude=val.fields)

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

Expand Down Expand Up @@ -752,7 +756,6 @@ def convert_optimizers_config(cls, model: rest.OptimizersConfig) -> grpc.Optimiz
max_optimization_threads=model.max_optimization_threads,
max_segment_size=model.max_segment_size,
memmap_threshold=model.memmap_threshold,
payload_indexing_threshold=model.payload_indexing_threshold,
vacuum_min_vector_number=model.vacuum_min_vector_number,
)

Expand All @@ -766,7 +769,6 @@ def convert_optimizers_config_diff(cls, model: rest.OptimizersConfigDiff) -> grp
max_optimization_threads=model.max_optimization_threads,
max_segment_size=model.max_segment_size,
memmap_threshold=model.memmap_threshold,
payload_indexing_threshold=model.payload_indexing_threshold,
vacuum_min_vector_number=model.vacuum_min_vector_number,
)

Expand Down Expand Up @@ -849,11 +851,11 @@ def convert_condition(cls, model: rest.Condition) -> grpc.Condition:
def convert_payload_selector(cls, model: rest.PayloadSelector) -> grpc.WithPayloadSelector:
if isinstance(model, rest.PayloadSelectorInclude):
return grpc.WithPayloadSelector(
include=grpc.PayloadIncludeSelector(include=model.include)
include=grpc.PayloadIncludeSelector(fields=model.include)
)
if isinstance(model, rest.PayloadSelectorExclude):
return grpc.WithPayloadSelector(
exclude=grpc.PayloadExcludeSelector(exclude=model.exclude)
exclude=grpc.PayloadExcludeSelector(fields=model.exclude)
)
raise ValueError(f"invalid PayloadSelector model: {model}") # pragma: no cover

Expand Down
Loading

0 comments on commit eb15dc3

Please sign in to comment.