Skip to content

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.

The system supports four distinct memory types, each optimized for different use cases:

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).

Short-term memories are automatically expired after their TTL, making them perfect for maintaining conversation context or temporary state.

Long-term memory provides persistent storage for important information that should be retained indefinitely. These memories can be retrieved later for context or learning.

Long-term memories can be retrieved using semantic search when AutoRAG is enabled, allowing for retrieval based on content similarity rather than exact matching.

Graph memory stores interconnected information as nodes and relationships, enabling complex knowledge representation and reasoning.

// Example of creating a graph memory
const 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 (Retrieval Augmented Generation) memory enables powerful semantic search and retrieval based on the meaning of content rather than exact keyword matching.

Semantic RAG memories require more processing resources as they enable advanced semantic search capabilities.

To create a new memory, send a POST request to the /memory endpoint with the appropriate payload:

// Example of creating a long-term memory
const 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 memory
ParameterTypeDescription
tenantIdstringID of the tenant this memory belongs to
contentstringThe actual content of the memory
typeenumOne of: short-term, long-term, graph, semantic-rag
ParameterTypeDescription
tagsstring[]Array of tags for categorizing the memory
sourcestringWhere the memory came from (e.g., “conversation”, “document”)
ttlnumberTime to live in seconds (for short-term memory)
metadataobjectAdditional metadata for the memory
entityIdsstring[]IDs of entities mentioned in this memory

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 relationships
const memory = {
tenantId: "tenant-123",
content: "Alice and Bob met at the conference.",
type: "long-term",
entityIds: ["person-alice", "person-bob", "event-conference"]
};
Choose the appropriate memory type for your use case: - Use short-term memory for temporary context that doesn't need to be retained long-term - Use long-term memory for important information that should be preserved - Use graph memory when you need to represent relationships between entities - Use semantic RAG when you need to find memories based on meaning rather than exact matching

Now that you understand the Memory API, your next steps should be:

  1. First: Retrieving Memories - Learn how to fetch and search memories efficiently
  2. Then: Entity Management - Master working with entities and their relationships
  3. Finally: Advanced RAG Techniques - Implement semantic search for better context

Following this sequence will build your knowledge systematically and prepare you for advanced implementation.