-
Notifications
You must be signed in to change notification settings - Fork 2
Personalised queries #31
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orca Security Scan Summary
Status | Check | Issues by priority | |
---|---|---|---|
![]() |
Infrastructure as Code | ![]() ![]() ![]() ![]() |
View in Orca |
![]() |
SAST | ![]() ![]() ![]() ![]() |
View in Orca |
![]() |
Secrets | ![]() ![]() ![]() ![]() |
View in Orca |
![]() |
Vulnerabilities | ![]() ![]() ![]() ![]() |
View in Orca |
f9ea440
to
547006d
Compare
bff0042
to
4fc03ac
Compare
34b4b11
to
d31606d
Compare
d31606d
to
3446521
Compare
fe4ffbf
to
c5d8b5b
Compare
11b94bd
to
700b913
Compare
@@ -439,3 +441,29 @@ def exists( | |||
) | |||
|
|||
return response.json()["persona_collection_exists"] | |||
|
|||
def query( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to match the collections.query API, this method just returns a configured instance of PersonalizedQuery
which implements all the query methods
self.recent_interactions_count = recent_interactions_count | ||
self.decay_rate = decay_rate | ||
|
||
def near_text( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where all the query methods are implemented. The only difference between each method is what model to use for the query parameters - these models are a tagged union and all have a query_method
field which disambiguates them on the backend.
from weaviate.collections.classes.internal import ReturnProperties, ReturnReferences | ||
|
||
|
||
class NearTextQueryParameters(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, these are the query parameter models (all with query_method
fields). The serialise_X
annotations use pydantic's custom serialiser hooks (PlainSerializer) to turn that field into a dict the backend can deserialise back into that object.
overfetch_factor: float = 1.5, | ||
recent_interactions_count: int = 100, | ||
decay_rate: float = 0.1, | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a return type hint here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done! 👍
) | ||
|
||
|
||
class PersonalizedQuery: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to figure out which new classes in this PR would need to be exported in weaviate_agents/classes/__init__.py
.
The motivation for this being that with the extras structure we do in the main python client weaviate-client[agents]
we have essentially a set of stubs inside that repo ( https://github.com/weaviate/weaviate-python-client/tree/main/weaviate/agents). These stubs allow us to not require changes in the main client for every change we do in this one but still allow for the types to exported if the agents extra is installed.
So for any types in weaviate_agents/personalization/classes/__init__.py
that might be used for typing reasons etc in future we might need to bring those up one level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to follow the existing exports, so have just added PersonalizedQueryResponse
(the output from all the query methods). I've skipped PersonalizedQuery
(the class which implements all the query methods) since that's not a plain model like the rest of these exports (and is importable from personalization_agent.py
like the PersonalizationAgent
class) but can add this if you think it's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were also two definitions of Usage
in personalization
and query
that had all the same fields/types but were different definitions so wouldn't have been recognised as the same types - I've moved these into a shared core
classes file, but all the external export paths should be the same.
json=self._get_request_data(query_parameters), | ||
timeout=self.timeout, | ||
) | ||
response_data = response.raise_for_status().json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise_for_status
only returns the status code message to the user.
And we often return detailed error messages in response body.
So most flexible way to handle errors is like we do in other places:
if response.is_error:
raise Exception(response.text)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I thought these were equivalent, didn't realise that raise_for_status
swallows the error text - changed 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I def wish it were 😅
Closes https://github.com/weaviate/agents/issues/416.
This adds the personlized queries to the PersonalizationAgent client. The
query()
method on the PA returns an instance ofPersonalizedQuery
which implements methods matching the existing collections query methods.See the corresponding backend changes here.