How Filtering Works
Supermemory uses two types of filters for different purposes:Container Tags
Organize memories into isolated spaces by user, project, or workspace
Metadata Filtering
Query memories by custom properties like category, status, or date
- Independently - Use container tags alone OR metadata filters alone
- Together - Combine both for precise filtering (most common)
[Container Tags] → [Your Memories] ← [Metadata Filters]
Container Tags
Container tags create isolated memory spaces. They’re perfect for multi-tenant applications, user profiles, and project organization.How Container Tags Work
- Exact matching: Arrays must match exactly. A memory tagged with
["user_123", "project_ai"]will NOT match a search for just["user_123"] - Isolation: Each container tag combination creates a separate knowledge graph
- Naming patterns: Use consistent patterns like
user_{id},project_{id}, ororg_{id}_team_{id}
Basic Usage
- TypeScript
- Python
- cURL
Container Tag Patterns
Best Practice: Use single container tags when possible. Multi-tag arrays require exact matching, which can be restrictive.
Recommended Patterns
- User isolation:
user_{userId} - Project grouping:
project_{projectId} - Workspace separation:
workspace_{workspaceId} - Hierarchical:
org_{orgId}_team_{teamId} - Temporal:
user_{userId}_2024_q1
API Differences
| Endpoint | Field Name | Type | Example |
|---|---|---|---|
/v3/search | containerTags | Array | ["user_123"] |
/v4/search | containerTag | String | "user_123" |
/v3/documents/list | containerTags | Array | ["user_123"] |
Metadata Filtering
Metadata filters let you query memories by any custom property. They use SQL-like AND/OR logic with explicit grouping.Filter Structure
All metadata filters must be wrapped in AND or OR arrays:Why Explicit Grouping?
Without explicit grouping, this SQL query is ambiguous:Basic Metadata Filtering
- TypeScript
- Python
- cURL
Filter Types in Detail
Supermemory supports four filter types, each designed for specific use cases.1. String Equality (Default)
Exact string matching with optional case-insensitive comparison.- Basic
- Case-Insensitive
- Negation
2. String Contains
Search for substrings within text fields.- Basic
- Case-Insensitive
- Exclusion
3. Numeric Comparisons
Filter by numeric values with comparison operators.- Basic Operators
- With Negation
Numeric Negation Mapping:
When using
negate: true with numeric filters, operators are reversed:<→>=<=→>>→<=>=→<=→!=
4. Array Contains
Check if an array field contains a specific value.- Basic
- Exclusion
- Multiple Checks
Common Patterns
Ready-to-use filtering patterns for common scenarios.User-Specific Content with Category
- TypeScript
- Python
Recent High-Priority Content
- TypeScript
- Python
Team Collaboration Filter
- TypeScript
- Python
Exclude Drafts and Deprecated Content
- TypeScript
- Python
API-Specific Notes
Different endpoints have slightly different requirements:| Endpoint | Container Tag Field | Type | Filter Format | Notes |
|---|---|---|---|---|
/v3/search | containerTags | Array | JSON object | Document search |
/v4/search | containerTag | String | JSON object | Memory search |
/v3/documents/list | containerTags | Array | JSON string | Must use JSON.stringify() |
List API Special Requirement: The
/v3/documents/list endpoint requires filters as a JSON string:Combining Container Tags and Metadata
Most real-world applications combine both filtering types for precise control.Example: User’s Work Documents from 2024
- TypeScript
- Python
Example: Project’s Active High-Priority Tasks
- TypeScript
- Python
Document-Specific Search
Search within a single large document using thedocId parameter:
- TypeScript
- Python
- Large textbooks or manuals
- Multi-chapter books
- Long podcast transcripts
- Course materials
Validation & Limits
Metadata Key Requirements
- Pattern:
/^[a-zA-Z0-9_.-]+$/ - Allowed: Letters, numbers, underscore, hyphen, dot
- Max length: 64 characters
- No spaces or special characters
Valid vs Invalid Keys
Query Complexity Limits
- Maximum conditions: 200 per query
- Maximum nesting depth: 8 levels
- Container tag arrays: Must match exactly
Troubleshooting
No Results Returned
Container tag mismatch
Container tag mismatch
Problem: Container tags must match exactly as arrays.Solution: Verify the exact array structure.
["user_123"] ≠ ["user_123", "project_1"]Wrong metadata key casing
Wrong metadata key casing
Problem: Keys are case-sensitive by default.Solution: Check exact key spelling and casing, or use
ignoreCase: true for values.Incorrect negate value
Incorrect negate value
Problem: Using
negate: true when you meant false.Solution: Review your negate values. false = include, true = exclude.Validation Errors
Invalid metadata key format
Invalid metadata key format
Error: “Invalid metadata key: contains unsafe characters”Solution: Remove spaces, special characters. Use only alphanumeric, underscore, hyphen, dot.
Filter structure error
Filter structure error
Error: “Invalid filter structure”Solution: Ensure all conditions are wrapped in AND or OR arrays.
List API filter error
List API filter error
Error: “Invalid filter format”Solution: For
/v3/documents/list, use JSON.stringify() on the filter object.Performance Issues
Slow queries
Slow queries
Problem: Complex nested OR conditions with many branches.Solution: Simplify logic, reduce nesting, or split into multiple queries.
Hitting complexity limits
Hitting complexity limits
Problem: “Query exceeds maximum complexity”Solution: Reduce conditions (max 200) or nesting depth (max 8).