Memory API
API Reference
Memory API
Store and retrieve long-term knowledge with semantic search
POST
Memory API
Documentation Index
Fetch the complete documentation index at: https://docs.statebase.org/llms.txt
Use this file to discover all available pages before exploring further.
Memory API
Memory enables your agents to remember facts across sessions. Unlike session state (which is ephemeral), memories are permanent and searchable via semantic similarity.Memory vs State
| Aspect | State | Memory |
|---|---|---|
| Scope | Single session | Cross-session |
| Lifecycle | Ephemeral (TTL) | Permanent |
| Structure | Nested JSON | Flat text + embeddings |
| Access | Direct read | Semantic search |
| Use Case | Working memory | Long-term knowledge |
Add Memory
POST /v1/memory
Stores a new memory with optional vector embedding for semantic search.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
session_id | string | ✅ Yes | Session to associate memory with |
content | string | ✅ Yes | Memory text (max 10,000 chars) |
type | string | No | Memory classification: "fact", "preference", "event", "policy" (default: "general") |
tags | array | No | Tags for categorization (e.g., ["travel", "preferences"]) |
metadata | object | No | Custom metadata |
embed | boolean | No | Generate vector embedding (default: true) |
Response
| Field | Type | Description |
|---|---|---|
id | string | Unique memory ID (format: mem_<12_chars>) |
session_id | string | Associated session |
content | string | Memory text |
type | string | Memory type |
tags | array | Tags |
metadata | object | Custom metadata |
created_at | string | ISO 8601 timestamp |
embedding_id | string | Vector DB ID (if embedded) |
vector_available | boolean | Whether semantic search is enabled |
Example
Search Memories
POST /v1/memory/search
Performs semantic similarity search across all memories. Returns the most relevant memories based on vector similarity.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
query | string | ✅ Yes | Search query (will be embedded and compared) |
session_id | string | No | Filter to specific session’s memories |
user_id | string | No | Filter to specific user’s memories |
type | string | No | Filter by memory type |
tags | array | No | Filter by tags (returns memories with ANY of these tags) |
limit | integer | No | Max results to return (default: 10, max: 50) |
threshold | float | No | Minimum similarity score (0.0-1.0, default: 0.7) |
Response
| Field | Type | Description |
|---|---|---|
data | array | Array of memory results |
query | string | Original search query |
Memory Result Object
| Field | Type | Description |
|---|---|---|
id | string | Memory ID |
session_id | string | Associated session |
content | string | Memory text |
type | string | Memory type |
tags | array | Tags |
score | float | Similarity score (0.0-1.0, higher = more relevant) |
created_at | string | When memory was created |
Example
Get Memory
GET /v1/memory/{memory_id}
Retrieves a specific memory by ID.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
memory_id | string | ✅ Yes | Memory ID |
Example
Update Memory
PATCH /v1/memory/{memory_id}
Updates an existing memory. If content is changed, a new embedding is generated.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
memory_id | string | ✅ Yes | Memory ID to update |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
content | string | No | New memory text |
type | string | No | New memory type |
tags | array | No | New tags (replaces existing) |
metadata | object | No | New metadata (merges with existing) |
Example
Delete Memory
DELETE /v1/memory/{memory_id}
Permanently deletes a memory and its vector embedding.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
memory_id | string | ✅ Yes | Memory ID to delete |
Example
List Memories
GET /v1/memory
Lists all memories with optional filtering.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
session_id | string | No | Filter by session |
user_id | string | No | Filter by user |
type | string | No | Filter by type |
tags | string | No | Comma-separated tags to filter by |
limit | integer | No | Max results (default: 20, max: 100) |
starting_after | string | No | Memory ID for pagination |
Example
Memory Types
Use these standard types for consistency:| Type | Description | Example |
|---|---|---|
fact | Objective information | "User's company is Acme Corp" |
preference | User preferences | "User prefers dark mode" |
event | Historical events | "User completed onboarding on 2026-01-15" |
policy | Rules and policies | "Always ask for confirmation before deleting data" |
observation | Behavioral insights | "User tends to ask follow-up questions" |
general | Uncategorized | Any other memory |
Common Use Cases
1. User Preferences
2. Conversation Summaries
3. Knowledge Base
4. User History
Best Practices
✅ Do This
- Use semantic search instead of keyword matching
- Tag memories for easy filtering
- Set confidence scores in metadata
- Consolidate similar memories (avoid duplicates)
- Use specific memory types (not just “general”)
❌ Avoid This
- Don’t store temporary data (use session state instead)
- Don’t store sensitive data unencrypted (use metadata encryption)
- Don’t create too many memories (focus on high-signal information)
- Don’t forget to clean up (delete outdated memories)
Embeddings
StateBase automatically generates vector embeddings using:- Default: Google Gemini (
text-embedding-004) - Alternative: OpenAI (
text-embedding-3-small)
Error Responses
| Status Code | Error Code | Description |
|---|---|---|
| 400 | invalid_request | Missing or invalid fields |
| 404 | memory_not_found | Memory doesn’t exist |
| 404 | session_not_found | Session doesn’t exist |
| 413 | content_too_large | Content exceeds 10,000 chars |
| 429 | rate_limit_exceeded | Too many requests |
Next Steps
- Sessions API: Manage session lifecycle
- Turns API: Log conversations
- RAG Agents Pattern: Build retrieval-augmented agents
Key Takeaway: Memory is how your agent learns over time. Use it for facts that should persist across sessions.