Skip to main content

Overview

The MemMachineMemory class provides the primary interface for interacting with the memory engine. It allows for high-granularity control over adding, searching, listing, and deleting memories.

Key Capabilities

  • Flexible Ingestion: Add raw text as memories with specific episode types.
  • Semantic Retrieval: Search memories using natural language queries.
  • Context Awareness: Retrieve combined project and memory metadata.

Constructor

new MemMachineMemory()

Initializes a new memory management instance. This is typically handled internally by the MemMachineProject.memory() factory method.
new MemMachineMemory(
  client: AxiosInstance, 
  projectContext: ProjectContext, 
  memoryContext?: MemoryContext
)
ParameterTypeDescription
clientAxiosInstanceInternal Axios instance for API communication.
projectContextProjectContextScoping options including org_id and project_id.
memoryContextMemoryContext(Optional) Specific identifiers for the memory scope (e.g., user_id).

Properties

PropertyTypeDescription
clientAxiosInstanceThe underlying HTTP client.
projectContextProjectContextThe organizational and project scope for this instance.
memoryContextMemoryContextThe specific user or session context for this instance.

Methods

add()

Adds a new memory to the system within the current project scope.
add(content: string, options?: AddMemoryOptions): Promise<AddMemoryResult>
ParameterTypeDescription
contentstringThe raw text content of the memory.
optionsAddMemoryOptions(Optional) Metadata like episode_type.
Performs a semantic and or episodic search against the stored memories.
search(query: string, options?: SearchMemoriesOptions): Promise<SearchMemoriesResult>
ParameterTypeDescription
querystringThe natural language search term.
optionsSearchMemoriesOptions(Optional) Search filters such as top_k, filter, types, and agent_mode.

list()

Retrieves a paginated list of memories.
list(options?: ListMemoriesOptions): Promise<SearchMemoriesResult>
ParameterTypeDescription
optionsListMemoriesOptions(Optional) Pagination settings (page_size, page_num).

delete()

Permanently removes a memory from the system.
delete(id: string, type: MemoryType): Promise<void>
ParameterTypeDescription
idstringThe unique identifier of the memory.
typeMemoryTypeThe classification of memory (e.g., episodic).

getContext()

Retrieves the active project and memory context used by this instance.
  • Returns: ProjectContext & MemoryContext

Usage Example

const memory = project.memory();

// 1. Add a memory with a specific type
await memory.add('User prefers dark mode and high-contrast settings.', { 
  episode_type: 'message' 
});

// 2. Search memories semantically
const results = await memory.search('What are the user preferences?', { 
  top_k: 3 
});

// 3. List recent memories
const history = await memory.list({ page_size: 10 });
All methods in this class throw a MemMachineAPIError if the server returns a non-200 status code.