Skip to main content
When basic dictionary filters aren’t enough, filter expressions give you logical control over knowledge searches. Use them to combine multiple conditions with AND/OR logic, exclude content with NOT, or perform comparisons like “greater than” and “less than”. For basic filtering with dictionary format, see Search & Retrieval.

Filter Expression Operators

Agno provides a rich set of filter expressions that can be combined to create sophisticated search criteria:

Comparison Operators

These operators let you match against specific values:

EQ (Equals)

Match content where a metadata field equals a specific value.

IN (Contains Any)

Match content where a metadata field contains any of the specified values.

GT (Greater Than) & LT (Less Than)

Match content based on numeric comparisons.

Logical Operators

Combine multiple conditions using logical operators:

AND

All conditions must be true.

OR

At least one condition must be true.

NOT

Exclude content that matches the condition.

Using Filters with Agents

Here’s how to apply filters when running agents with knowledge.
You need a contents database with your Knowledge base to use agentic filtering.

Basic Agent Filtering

Complex Filter Examples

Using Filters with Teams

Teams can also leverage filtered knowledge searches:

Advanced Filtering Patterns

User-Specific Content

Filter content based on user access or preferences:

Time-Based Filtering

Filter by recency or date ranges:

Progressive Filtering

Start broad, then narrow down based on results:

Best Practices for Filter Expressions

Filter Design

  • Start Simple: Begin with basic filters and add complexity as needed
  • Test Combinations: Verify that your logical combinations work as expected
  • Document Your Schema: Keep track of available metadata fields and their possible values
  • Performance Considerations: Some filter combinations may be slower than others

Troubleshooting

Filter Not Working

Check that the keys you’re filtering on actually exist in your knowledge base:
Print the filter to verify it’s constructed correctly:

Complex Filters Failing

Test each condition individually:
Check that nested logic is correctly structured:
Make sure nested logic is clear and well-structured:

Vector Database Support

Advanced filter expressions (using FilterExpr like EQ(), AND(), etc.) are currently only supported in PgVector.
What happens with unsupported FilterExpr:When using FilterExpr with unsupported vector databases:
  • You’ll see a warning like: WARNING: Filter Expressions are not yet supported in [DatabaseName]. No filters will be applied.
  • Search proceeds without filters (unfiltered results)
  • No errors thrown, but filtering is ignored
Workaround: Use dictionary format instead:

Agentic Filtering Compatibility

Advanced filter expressions (FilterExpr) are not compatible with agentic filtering, where agents dynamically construct filters based on conversation context. For agentic filtering, use dictionary format:
When to use each approach:

Using Filters Through the API

All the filter expressions shown in this guide can also be used through the Agent OS API. FilterExpressions serialize to JSON and are automatically reconstructed server-side, enabling the same filtering over REST endpoints.
FilterExpressions use a dictionary format with an "op" key (e.g., {"op": "EQ", "key": "status", "value": "published"}) which tells the API to deserialize them as FilterExpr objects. Regular dict filters without the "op" key continue to work for backward compatibility.
For detailed examples, API-specific patterns, and troubleshooting, see the API Filtering Guide.

Next Steps

API Filtering Guide

Use filter expressions through the Agent OS API

Search & Retrieval

Search types, direct and agentic retrieval, and dictionary filters

Content Database

Understand how content and metadata are stored and managed

Knowledge Bases

Give agents access to documents, databases, and domain expertise

Performance Tips

Optimize your filtered searches for speed and accuracy