Skip to content

Conversation

@willemcdejongh
Copy link
Contributor

@willemcdejongh willemcdejongh commented Oct 28, 2025

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

  1. Knowledge Filter DSL (agno/knowledge/filters.py)
    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
  2. Vector Database Integration
    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
  3. Knowledge API Updates
    Added knowledge_filters parameter to search methods
    Support for filtering in Agent, Team, and Workflow classes
  4. Examples & Documentation
    cookbook/knowledge/filters/filtering_with_conditions_on_agent.py
    cookbook/knowledge/filters/filtering_with_conditions_on_team.py

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Improvement
  • Model update
  • Other:

Checklist

  • Code complies with style guidelines
  • Ran format/validation scripts (./scripts/format.sh and ./scripts/validate.sh)
  • Self-review completed
  • Documentation updated (comments, docstrings)
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable)
  • Tested in clean environment
  • Tests added/updated (if applicable)

Additional Notes

Add any important context (deployment instructions, screenshots, security considerations, etc.)

@willemcdejongh willemcdejongh requested a review from a team as a code owner October 28, 2025 17:16
@willemcdejongh willemcdejongh force-pushed the knowledge-advanced-filtering branch 2 times, most recently from 66acbac to 7a17d27 Compare October 29, 2025 07:17
Copy link
Contributor

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):
Copy link
Contributor

@kausmeows kausmeows Oct 29, 2025

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)

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@dirkbrnd dirkbrnd left a 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

@willemcdejongh willemcdejongh force-pushed the knowledge-advanced-filtering branch 3 times, most recently from f77fc53 to 1327bb6 Compare November 4, 2025 17:06
@willemcdejongh willemcdejongh force-pushed the knowledge-advanced-filtering branch from 1327bb6 to 528b035 Compare November 5, 2025 09:13
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.

4 participants