Memory API
The Memory API provides a robust system for storing, retrieving, and managing different types of memories for AI agents. This system enables agents to maintain context, learn from past interactions, and build knowledge graphs over time.
Memory Types
Section titled “Memory Types”The system supports four distinct memory types, each optimized for different use cases:
Short-Term Memory
Section titled “Short-Term Memory”Short-term memory is designed for temporary storage of information that’s only relevant for a limited time. It’s automatically expired after a configurable TTL (Time To Live).
Long-Term Memory
Section titled “Long-Term Memory”Long-term memory provides persistent storage for important information that should be retained indefinitely. These memories can be retrieved later for context or learning.
Graph Memory
Section titled “Graph Memory”Graph memory stores interconnected information as nodes and relationships, enabling complex knowledge representation and reasoning.
// Example of creating a graph memoryconst graphMemory = { tenantId: "tenant-123", content: JSON.stringify({ nodes: [ { id: "person1", type: "Person", properties: { name: "Alice" } }, { id: "person2", type: "Person", properties: { name: "Bob" } } ], relationships: [ { source: "person1", target: "person2", type: "KNOWS", properties: { since: "2023-01-01" } } ] }), type: "graph", tags: ["knowledge_graph", "people"], metadata: { version: "1.0", created_by: "agent-123" }};Semantic RAG Memory
Section titled “Semantic RAG Memory”Semantic RAG (Retrieval Augmented Generation) memory enables powerful semantic search and retrieval based on the meaning of content rather than exact keyword matching.
Creating Memories
Section titled “Creating Memories”To create a new memory, send a POST request to the /memory endpoint with the appropriate payload:
// Example of creating a long-term memoryconst response = await fetch('https://api.example.com/memory', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_API_KEY' }, body: JSON.stringify({ tenantId: "tenant-123", content: "The user prefers dark mode in all applications.", type: "long-term", tags: ["preferences", "ui"], source: "conversation", metadata: { confidence: 0.95, session_id: "session-456" } })});
const result = await response.json();console.log(result.memory.id); // The unique ID of the created memoryRequired Parameters
Section titled “Required Parameters”| Parameter | Type | Description |
|---|---|---|
tenantId | string | ID of the tenant this memory belongs to |
content | string | The actual content of the memory |
type | enum | One of: short-term, long-term, graph, semantic-rag |
Optional Parameters
Section titled “Optional Parameters”| Parameter | Type | Description |
|---|---|---|
tags | string[] | Array of tags for categorizing the memory |
source | string | Where the memory came from (e.g., “conversation”, “document”) |
ttl | number | Time to live in seconds (for short-term memory) |
metadata | object | Additional metadata for the memory |
entityIds | string[] | IDs of entities mentioned in this memory |
Entity Relationships
Section titled “Entity Relationships”When creating a memory with entityIds, the system automatically establishes relationships between the memory and those entities. This enables:
- Tracking which memories mention specific entities
- Building a knowledge graph of interconnected information
- Retrieving all memories related to a particular entity
// Example of creating a memory with entity relationshipsconst memory = { tenantId: "tenant-123", content: "Alice and Bob met at the conference.", type: "long-term", entityIds: ["person-alice", "person-bob", "event-conference"]};Next Steps
Section titled “Next Steps”What to Learn Next
Section titled “What to Learn Next”Now that you understand the Memory API, your next steps should be:
- First: Retrieving Memories - Learn how to fetch and search memories efficiently
- Then: Entity Management - Master working with entities and their relationships
- Finally: Advanced RAG Techniques - Implement semantic search for better context
Following this sequence will build your knowledge systematically and prepare you for advanced implementation.