Overview
Custom metadata allows you to attach arbitrary key-value pairs to your memories, enabling powerful filtering capabilities when querying. This is useful for categorizing documents by department, priority level, confidentiality, or any other custom attributes relevant to your application.Adding Metadata
Text Memories
When adding text memories via/memories/add, include a metadata object with your custom fields:
Supported Value Types
Metadata values can be:- Strings:
"department": "engineering" - Numbers:
"priority": 5or"score": 0.95 - Booleans:
"confidential": true - ISO 8601 Dates:
"meeting_date": "2024-01-15T09:00:00Z"
File Uploads
When uploading files via/memories/upload, pass metadata as a JSON string in the form data:
For file uploads, metadata must be passed as a JSON-encoded string since the endpoint uses multipart form data.
Updating Metadata
When you add a memory with the sameresource_id, the metadata is merged with any existing metadata. New keys are added, and existing keys are overwritten:
Using the Update Endpoint
For more granular updates, use the/memories/update endpoint. This endpoint allows you to update metadata, title, or text without re-indexing if text is not provided. It works with documents from any source (vault, slack, gmail, etc.):
The update endpoint only modifies fields you explicitly provide. Fields you don’t include remain unchanged.
Querying with Metadata Filters
Use theoptions.filter parameter when querying to filter results by metadata. Filters use MongoDB-style operators and are combined with AND logic.
Basic Filtering
Filter by exact value match:Multiple Conditions
Multiple conditions are combined with AND logic:Comparison Operators
Use MongoDB-style operators for advanced filtering:Complex Filter Examples
High priority, non-confidential documents:Combining with Resource ID Filters
Metadata filters can be combined withresource_ids to search within specific documents:
Combining with Date Filters
Metadata filters can be combined with theafter and before date range options:
Filtering the List Endpoint
You can also use metadata filters when listing all memories via/memories/list. Pass the filter as a URL-encoded JSON string:
$eq, $ne, $gt, $gte, $lt, $lte, and $in.
Metadata in Query Results
When you query documents, the custom metadata is included in each document’smetadata field alongside system fields:
Best Practices
- Use consistent key names across your application to enable reliable filtering
- Keep metadata flat - nested objects are not supported for filtering
- Use appropriate types - numbers for numeric comparisons, booleans for true/false values
- Plan your taxonomy - decide on standard values for categorical fields like
departmentorcategory - Don’t over-filter - metadata filtering happens after semantic search, so overly restrictive filters may exclude relevant results