-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: Knowledge advanced filtering #5223
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
base: main
Are you sure you want to change the base?
Conversation
66acbac to
7a17d27
Compare
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.
We should also add unit tests using all for these
| return {"op": "IN", "key": self.key, "values": self.values} | ||
|
|
||
|
|
||
| class GT(FilterExpr): |
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.
What does LT and GT mean? I'm a bit out of loop but maybe lets add a comment too
(edit- ok got it, greater than/less than)
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.
We should really add docstrings and in general document this well
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 think these should be at a higher level than knowledge, so /agno/filters.py
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.
Ruan had a similar comment, but we moved it to agno/utils
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 don't think we can release this without support on all the DBs, I think we push through and first get full coverage before release.
Or alternatively do 1 for the customer and the rest in another PR
f77fc53 to
1327bb6
Compare
1327bb6 to
528b035
Compare
Summary
This PR introduces advanced filtering capabilities for Knowledge searches, enabling developers to filter knowledge base results using expressive filter conditions. Users can now apply metadata-based filters using operators like EQ, IN, NOT, AND, and OR to create precise, targeted knowledge searches.
Key Features:
Filter expressions DSL with support for equality, inclusion, and logical operators
Integration with vector databases (PgVector, SurrealDB, etc.)
Support for filtering at Agent, Team, and Workflow levels
Comprehensive cookbook examples demonstrating filter usage
Related to: Enhanced knowledge search and retrieval capabilities
Key Changes
Added filter expression classes:
EQ(key, value) - Equality comparison
IN(key, values) - Check if value is in list
GT(key, value) / LT(key, value) - Greater than/Less than comparisons
NOT(condition) - Logical negation
AND(*conditions) / OR(*conditions) - Logical combinations
Updated pgvector.py to translate filter DSL to SQLAlchemy queries
Fixed type annotations (ColumnElement[bool] instead of BinaryExpression)
Added filter support for hybrid and vector searches
Added knowledge_filters parameter to search methods
Support for filtering in Agent, Team, and Workflow classes
cookbook/knowledge/filters/filtering_with_conditions_on_agent.py
cookbook/knowledge/filters/filtering_with_conditions_on_team.py
Type of change
Checklist
./scripts/format.shand./scripts/validate.sh)Additional Notes
Add any important context (deployment instructions, screenshots, security considerations, etc.)