Skip to main content

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": 5 or "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 same resource_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 the options.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:
Documents from specific departments:
Exclude certain categories:
Range queries on numeric values:

Combining with Resource ID Filters

Metadata filters can be combined with resource_ids to search within specific documents:

Combining with Date Filters

Metadata filters can be combined with the after 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:
All the same filter operators work with the list endpoint: $eq, $ne, $gt, $gte, $lt, $lte, and $in.

Metadata in Query Results

When you query documents, the custom metadata is included in each document’s metadata field alongside system fields:
You can access this metadata in your code:

Best Practices

  1. Use consistent key names across your application to enable reliable filtering
  2. Keep metadata flat - nested objects are not supported for filtering
  3. Use appropriate types - numbers for numeric comparisons, booleans for true/false values
  4. Plan your taxonomy - decide on standard values for categorical fields like department or category
  5. Don’t over-filter - metadata filtering happens after semantic search, so overly restrictive filters may exclude relevant results