Skip to content

Commit 4e1b22f

Browse files
updates
1 parent 1fd6c5b commit 4e1b22f

File tree

4 files changed

+277
-127
lines changed

4 files changed

+277
-127
lines changed

agent-os/customize/os/filter_knowledge.mdx

Lines changed: 8 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Knowledge Filtering
2+
title: Filter Knowledge
33
description: Learn how to use advanced filter expressions through the Agno API for precise knowledge base filtering.
44
keywords: [api, filtering, filterexpr, knowledge, search, rest api]
55
---
@@ -272,93 +272,6 @@ def validate_and_send_filter(filter_expr, message):
272272
return None
273273
```
274274

275-
## Complete Examples
276-
277-
### Example 1: Simple Dict Filter
278-
279-
For straightforward filtering with AND logic:
280-
281-
```python
282-
import requests
283-
import json
284-
285-
# Define your agent's API endpoint
286-
AGENT_URL = "http://localhost:7777/agents/agno-knowledge-agent/runs"
287-
288-
# Create simple dict filter
289-
filter_dict = {
290-
"docs": "agno",
291-
"category": "features",
292-
"status": "published"
293-
}
294-
295-
# Serialize filter
296-
filter_json = json.dumps(filter_dict)
297-
298-
# Send request
299-
response = requests.post(
300-
AGENT_URL,
301-
data={
302-
"message": "What are agno's key features?",
303-
"stream": "false",
304-
"knowledge_filters": filter_json,
305-
"session_id": "user-123",
306-
"user_id": "demo-user",
307-
}
308-
)
309-
310-
# Process response
311-
if response.ok:
312-
result = response.json()
313-
print(f"Agent response: {result.get('content')}")
314-
print(f"Documents used: {len(result.get('documents', []))}")
315-
else:
316-
print(f"Error: {response.status_code} - {response.text}")
317-
```
318-
319-
### Example 2: Advanced Filter Expression
320-
321-
For complex filtering with multiple logical operators:
322-
323-
```python
324-
import requests
325-
import json
326-
from agno.filters import EQ, GT, AND, IN, NOT
327-
328-
# Define your agent's API endpoint
329-
AGENT_URL = "http://localhost:7777/agents/tech-docs-agent/runs"
330-
331-
# Build a complex filter
332-
filter_expr = AND(
333-
EQ("status", "published"),
334-
IN("category", ["tutorial", "guide"]),
335-
GT("word_count", 500),
336-
NOT(EQ("difficulty", "beginner"))
337-
)
338-
339-
# Serialize filter
340-
filter_json = json.dumps(filter_expr.to_dict())
341-
342-
# Send request
343-
response = requests.post(
344-
AGENT_URL,
345-
data={
346-
"message": "Show me advanced tutorials on deployment",
347-
"stream": "false",
348-
"knowledge_filters": filter_json,
349-
"session_id": "user-123-session",
350-
}
351-
)
352-
353-
# Process response
354-
if response.ok:
355-
result = response.json()
356-
print(f"Agent response: {result.get('content')}")
357-
print(f"Documents used: {len(result.get('documents', []))}")
358-
else:
359-
print(f"Error: {response.status_code} - {response.text}")
360-
```
361-
362275
## Next Steps
363276

364277
<CardGroup cols={2}>
@@ -390,5 +303,12 @@ else:
390303
>
391304
Optimize your search strategies
392305
</Card>
306+
<Card
307+
title="Filter Expressions Example"
308+
icon="code"
309+
href="/examples/concepts/knowledge/filters/filter-expressions"
310+
>
311+
See working examples of filter expressions via API
312+
</Card>
393313
</CardGroup>
394314

concepts/knowledge/core-concepts/advanced-filtering.mdx

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,7 @@ def safe_filter_search(agent, query, filters):
419419

420420
### Vector Database Support
421421

422-
Advanced filter expressions (using `FilterExpr` like `EQ()`, `AND()`, etc.) have varying support across vector databases:
423-
424-
| Vector DB | Dictionary Filters `{"key": "value"}` | FilterExpr `EQ()`, `AND()`, etc. |
425-
|-----------|--------------------------------------|----------------------------------|
426-
| **PgVector** | ✅ Full support | ✅ Full support (native) |
427-
| **LanceDB** | ✅ Post-search filtering | ⚠️ Not yet supported* |
428-
| **ChromaDB** | ✅ Full support | ⚠️ Not yet supported |
429-
| **Pinecone** | ✅ Full support | ⚠️ Not yet supported |
430-
| **Qdrant** | ✅ Full support | ⚠️ Not yet supported |
422+
Advanced filter expressions (using `FilterExpr` like `EQ()`, `AND()`, etc.) is currently only supported in PGVector.
431423

432424
<Note>
433425
**What happens with unsupported FilterExpr:**
@@ -447,23 +439,17 @@ knowledge_filters=[AND(EQ("department", "hr"), EQ("year", 2024))]
447439
```
448440
</Note>
449441

450-
**Coming Soon:**
451-
- 🔄 LanceDB FilterExpr support (in development)
452-
- 🔄 ChromaDB FilterExpr support (planned)
453-
- 🔄 Pinecone FilterExpr support (planned)
454-
- 🔄 Universal FilterExpr support across all vector databases
455-
456442
### Agentic Filtering Compatibility
457443

458444
Advanced filter expressions (`FilterExpr`) are **not compatible with agentic filtering**, where agents dynamically construct filters based on conversation context.
459445

460446
**For agentic filtering, use dictionary format:**
461447

462448
```python
463-
# Works with agentic filtering (agent decides filters dynamically)
449+
# Works with agentic filtering (agent decides filters dynamically)
464450
knowledge_filters = [{"department": "hr", "document_type": "policy"}]
465451

466-
# Does not work with agentic filtering (static, predefined logic)
452+
# Does not work with agentic filtering (static, predefined logic)
467453
knowledge_filters = [AND(EQ("department", "hr"), EQ("document_type", "policy"))]
468454
```
469455

@@ -474,28 +460,6 @@ knowledge_filters = [AND(EQ("department", "hr"), EQ("document_type", "policy"))]
474460
| **Dictionary format** | Agent dynamically chooses filters based on conversation | User mentions "HR policies" → agent adds `{"department": "hr"}` |
475461
| **Filter expressions** | You need complex, predetermined logic with full control | Always exclude drafts AND filter by multiple regions with OR logic |
476462

477-
**Hybrid Approach:**
478-
479-
If you need both agentic decision-making and complex filtering:
480-
481-
```python
482-
from agno.filters import AND, EQ, GT, NOT
483-
484-
# Define filter presets
485-
FILTER_PRESETS = {
486-
"recent_hr": [AND(EQ("department", "hr"), GT("year", 2023))],
487-
"active_engineering": [AND(EQ("department", "engineering"), NOT(EQ("status", "archived")))],
488-
"all_public": [EQ("visibility", "public")]
489-
}
490-
491-
# Agent chooses which preset to use based on context
492-
def get_filter_for_context(user_query: str):
493-
if "recent" in user_query.lower() and "hr" in user_query.lower():
494-
return FILTER_PRESETS["recent_hr"]
495-
# ... more logic
496-
return None
497-
```
498-
499463

500464
## Using Filters Through the API
501465

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,7 @@
17031703
"pages": [
17041704
"examples/concepts/knowledge/filters/agentic-filtering",
17051705
"examples/concepts/knowledge/filters/async-filtering",
1706+
"examples/concepts/knowledge/filters/filter-expressions",
17061707
"examples/concepts/knowledge/filters/filtering",
17071708
"examples/concepts/knowledge/filters/filtering_on_load",
17081709
"examples/concepts/knowledge/filters/filtering_with_invalid_keys",

0 commit comments

Comments
 (0)