mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-31 01:55:25 +00:00
docs: add filtered writes documentation (#834)
### TL;DR Documents the new `filterByMetadata` parameter for the memory ingestion API, added in [supermemoryai/mono#1283](https://github.com/supermemoryai/mono/pull/1283). ### What changed? - Added a new "Filtered Writes" section to the `add-memories.mdx` page explaining how to scope memory context during ingestion - Added `filterByMetadata` to the Parameters table with a link to the new section - Included TypeScript, Python, and cURL examples - Documented scalar vs array value matching semantics (AND/OR logic) ### Key documentation points - The metadata itself is still written to the document, but memories are only built on top of existing memories matching the filter - Scalar values match exactly, array values create OR conditions - Multiple keys are combined with AND logic ### Related - Implementation PR: [supermemoryai/mono#1283](https://github.com/supermemoryai/mono/pull/1283) --- **Session Details** - Session: [View Session](https://supermemory.us1.vorflux.com/agent-sessions/14d33783-50b0-4fc8-8e0f-abc6346336f1) - Requested by: Dhravya Shah (dhravya@supermemory.com) - Address comments on this PR. Add `(aside)` to your comment to have me ignore it.
This commit is contained in:
parent
aa83c0bc12
commit
1f2b5dfca2
1 changed files with 78 additions and 0 deletions
|
|
@ -199,6 +199,7 @@ Upload PDFs, images, and documents directly.
|
|||
| `customId` | string | **Recommended.** Your ID for the content (conversation ID, doc ID). Enables updates and deduplication |
|
||||
| `containerTag` | string | Group by user/project. Required for user profiles |
|
||||
| `metadata` | object | Key-value pairs for filtering (strings, numbers, booleans) |
|
||||
| `filterByMetadata` | object | Filter which existing memories are used as context during ingestion. See [Filtered Writes](#filtered-writes) |
|
||||
| `entityContext` | string | Context for memory extraction on this container tag. Max 1500 chars. See [Customization](/concepts/customization#entity-context) |
|
||||
|
||||
<AccordionGroup>
|
||||
|
|
@ -276,6 +277,83 @@ Upload PDFs, images, and documents directly.
|
|||
|
||||
---
|
||||
|
||||
## Filtered Writes
|
||||
|
||||
By default, when you add content, Supermemory uses **all** existing memories in the space as context for generating new memories. With **filtered writes**, you can scope this context to only memories from documents matching specific metadata.
|
||||
|
||||
This is useful when you have many documents in a space but want new memories to build on top of a specific subset — for example, only memories from a particular source, category, or user.
|
||||
|
||||
<Note>
|
||||
The metadata itself is still written to the document, but the memories will only be built on top of what's already there matching the filter.
|
||||
</Note>
|
||||
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
```typescript
|
||||
await client.add({
|
||||
content: "New research findings on transformer architectures...",
|
||||
containerTag: "user_123",
|
||||
metadata: { category: "ml", source: "arxiv" },
|
||||
filterByMetadata: { category: "ml" }
|
||||
});
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Python">
|
||||
```python
|
||||
client.add(
|
||||
content="New research findings on transformer architectures...",
|
||||
container_tag="user_123",
|
||||
metadata={"category": "ml", "source": "arxiv"},
|
||||
filter_by_metadata={"category": "ml"}
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="cURL">
|
||||
```bash
|
||||
curl -X POST "https://api.supermemory.ai/v3/documents" \
|
||||
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"content": "New research findings on transformer architectures...",
|
||||
"containerTag": "user_123",
|
||||
"metadata": {"category": "ml", "source": "arxiv"},
|
||||
"filterByMetadata": {"category": "ml"}
|
||||
}'
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
### How it works
|
||||
|
||||
When `filterByMetadata` is provided:
|
||||
- **Profile memories** (static context) are filtered to only those from documents matching the metadata
|
||||
- **Similar memories** used as context during ingestion are filtered the same way
|
||||
- The new document's own metadata is written normally — the filter only affects which **existing** memories are used as context
|
||||
|
||||
### `filterByMetadata` parameter
|
||||
|
||||
| Key | Type | Description |
|
||||
|-----|------|-------------|
|
||||
| `filterByMetadata` | `Record<string, string \| number \| boolean \| string[]>` | Key-value pairs to filter existing memories by their source document metadata |
|
||||
|
||||
- **Scalar values** (string, number, boolean) match exactly
|
||||
- **Array values** match if **any** value in the array matches (OR logic)
|
||||
- **Multiple keys** are combined with AND logic
|
||||
|
||||
```typescript
|
||||
// Match documents where category is "ml" AND source is either "arxiv" or "pubmed"
|
||||
await client.add({
|
||||
content: "...",
|
||||
containerTag: "user_123",
|
||||
filterByMetadata: {
|
||||
category: "ml",
|
||||
source: ["arxiv", "pubmed"]
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Processing Pipeline
|
||||
|
||||
When you add content, Supermemory:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue