Quick Start
How It Works
Knowledge.search() normalises every backend into one typed SearchResult.
The SearchResult shape
The container holds the ranked items plus search-level metadata.
| Field | Type | Description |
|---|---|---|
results | list[SearchResultItem] | Ranked items |
metadata | dict | Search-level metadata (always dict, never None) |
query | str | Original query string |
total_count | int | None | Total available (may exceed len(results) if paginated) |
The SearchResultItem shape
Each item carries the content, its score, and optional source hints.
| Field | Type | Description |
|---|---|---|
id | str | Backend identifier |
text | str | Content (normalised from memory / text / metadata.data) |
score | float | Relevance score (0.0 default) |
metadata | dict | Item metadata (always dict, never None) |
source | str | None | Optional source hint |
filename | str | None | Optional filename |
created_at | str | None | Timestamp |
updated_at | str | None | Timestamp |
Common Patterns
Show top-N with scores
Convert to legacy dict format
Handle any backend shape
Custom backends can return a typedSearchResult, a legacy dict, or a plain list. Normalise them with one call.
Best Practices
Check .results, not the object
Check .results, not the object
An empty
SearchResult is still a dataclass instance, so it is always truthy.Trust metadata is a dict
Trust metadata is a dict
metadata is never None on SearchResult or SearchResultItem — it defaults to an empty dict, so you never need to guard against None.Use to_legacy_format() for dict consumers
Use to_legacy_format() for dict consumers
Older code that expects mem0-shaped
{"results": [...]} dicts stays compatible.Prefer typed access over dict access
Prefer typed access over dict access
Typed attributes are clearer and safer than dict lookups.
Related
Knowledge Overview
Give agents access to your documents
Knowledge CLI
Search from the command line

