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

feature: Facets #759

Merged
merged 11 commits into from
Oct 2, 2024
Merged

feature: Facets #759

merged 11 commits into from
Oct 2, 2024

Conversation

coszio
Copy link
Contributor

@coszio coszio commented Aug 27, 2024

Needs #758

Adds facet functionality in both remote and local mode

WIP:

  • type stubs
  • congruence tests

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you installed pre-commit with pip3 install pre-commit and set up hooks with pre-commit install?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@coszio coszio requested a review from joein September 12, 2024 13:47
@coszio coszio marked this pull request as ready for review September 12, 2024 13:47
Comment on lines 1789 to 1809
def convert_facet_value(cls, model: grpc.FacetValue) -> rest.FacetValue:
name = model.WhichOneof("variant")
if name is None:
raise ValueError(f"invalid FacetValue model: {model}")

val = getattr(model, name)
return val

@classmethod
def convert_facet_value_hit(cls, model: grpc.FacetHit) -> rest.FacetValueHit:
return rest.FacetValueHit(
value=cls.convert_facet_value(model.value),
count=model.count,
)

@classmethod
def convert_facet_response(cls, model: grpc.FacetResponse) -> rest.FacetResponse:
return rest.FacetResponse(
hits=[cls.convert_facet_value_hit(hit) for hit in model.hits],
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • lacks conversion tests
  • lacks rest to grpc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are implementing the inverse conversions even for the structs which we are not using in order to increase test coverage. E.g. scored point, update result

@@ -1261,7 +1261,7 @@ def recommend_groups(
with_lookup = RestToGrpc.convert_with_lookup(with_lookup)

if isinstance(with_lookup, str):
with_lookup = grpc.WithLookup(lookup_index=with_lookup)
with_lookup = grpc.WithLookup(collection=with_lookup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasn't anyone ever used it? :'(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

Comment on lines +1133 to +1137
hits = [
models.FacetValueHit(value=value, count=count)
for value, count in sorted(
facet_hits.items(),
# order by count descending, then by value ascending
key=lambda x: (-x[1], x[0]),
)[:limit]
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is a facet request on a field which is not one of supported type (int, str), e.g. with a boolean, then we'll get an ugly pydantic error like

validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for FacetValueHit
value.int
  Input should be a valid integer [type=int_type, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.9/v/int_type
value.str
  Input should be a valid string [type=string_type, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.9/v/string_type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was already sanitized above. Did you create a failing test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that bool is a subclass of int, which is why it was getting through isinstance.

I now fixed it by using

if type(v) not in get_args_subscribed(types.FacetValue):
    continue

@coszio coszio requested a review from joein September 16, 2024 17:28
@coszio
Copy link
Contributor Author

coszio commented Oct 1, 2024

Just updated for testing bool facets. Right now CI fails because dev build is not yet ready, I'll rerun in a few hours

@joein joein merged commit 9f736ac into update-clients Oct 2, 2024
10 checks passed
joein added a commit that referenced this pull request Oct 5, 2024
* update rest client

* update grpc client with grpcio 1.65.4

* update grpc client with grpcio==1.49.1

* generate grpc client with grpcio==1.48.2

* generate grpc client with grpcio==1.66.1 and mypy-protobuf extension

* add mypy-protobuf to pyproject

* relax version for grpcio, but keep grpcio-tools at 1.48.2

* improve generation script

* fix bash script comment

Co-authored-by: George <[email protected]>

* use old grpcio to generate client

* rollbakc mypy-protobuf

* regenerate with distance matrix

* new: update clients (#774)

* new: update clients

* rollback grpcio version

* feature: Facets (#759)

* facet in local_collection.py

* replace usages of calculate_payload_mask

* - qdrant remote
- qdrant base
- qdrant client
- conversions

* congruence tests + local mode fixes

* generate async client

* add type stubs and misc fixes

* fix mypy in Python 3.8

* generate async client

* review remarks

* gen async client

* update for bool facets

* Feature: Distance Matrix API (#769)

* add remote impls

* add client impl

* regen async client

* start local

* regen async

* local mode

* start congruence

* Fix local mode

* regen async of course

* test filtering

* fix min samples count

* simplify comparaison loop

* simplify samples loop

* add rest/gRPC conversion tests

* fix conversions + tests

---------

Co-authored-by: George <[email protected]>
Co-authored-by: generall <[email protected]>
Co-authored-by: Arnaud Gourlay <[email protected]>
joein added a commit that referenced this pull request Oct 7, 2024
* update rest client

* update grpc client with grpcio 1.65.4

* update grpc client with grpcio==1.49.1

* generate grpc client with grpcio==1.48.2

* generate grpc client with grpcio==1.66.1 and mypy-protobuf extension

* add mypy-protobuf to pyproject

* relax version for grpcio, but keep grpcio-tools at 1.48.2

* improve generation script

* fix bash script comment

Co-authored-by: George <[email protected]>

* use old grpcio to generate client

* rollbakc mypy-protobuf

* regenerate with distance matrix

* new: update clients (#774)

* new: update clients

* rollback grpcio version

* feature: Facets (#759)

* facet in local_collection.py

* replace usages of calculate_payload_mask

* - qdrant remote
- qdrant base
- qdrant client
- conversions

* congruence tests + local mode fixes

* generate async client

* add type stubs and misc fixes

* fix mypy in Python 3.8

* generate async client

* review remarks

* gen async client

* update for bool facets

* Feature: Distance Matrix API (#769)

* add remote impls

* add client impl

* regen async client

* start local

* regen async

* local mode

* start congruence

* Fix local mode

* regen async of course

* test filtering

* fix min samples count

* simplify comparaison loop

* simplify samples loop

* add rest/gRPC conversion tests

* fix conversions + tests

---------

Co-authored-by: George <[email protected]>
Co-authored-by: generall <[email protected]>
Co-authored-by: Arnaud Gourlay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants