Skip to main content

Class MemMachineMemory

The MemMachineMemory class is the primary interface for interacting with the MemMachine memory engine. It allows you to store natural language “episodes” and retrieve them later using semantic search. The recommended way to access this class is via an existing project instance:
const memory = project.memory();
Parameters
NameTypeDescription
memoryContextMemoryContextOptional scope settings to filter or categorize these memories.

Methods

add()

Adds a new memory to the MemMachine server.
await memory.add(content: string, options?: AddMemoryOptions)
Parameters
NameTypeDescription
contentstringThe text or data to be remembered.
optionsAddMemoryOptionsConfiguration like episode_type or producer role.
Returns
  • Promise<AddMemoryResult> — The result containing the unique id of the new memory.

Performs a semantic search to find relevant memories based on a natural language query.
await memory.search(query: string, options?: SearchMemoryOptions)
Parameters
NameTypeDescription
querystringThe question or phrase to search for.
optionsSearchMemoryOptionsLimits, filters, or minimum similarity scores.
Returns
  • Promise<SearchMemoryResult> — A list of relevant EpisodicMemory objects.

delete()

Permanently removes a specific memory from the system.
await memory.delete(id: string, type: MemoryType)
Parameters
NameTypeDescription
idstringThe unique ID of the memory (returned during add or search).
typeMemoryTypeSpecify either episodic or semantic.

getContext()

Returns the combined Project and Memory configuration currently in use by this instance.
memory.getContext()
Returns
  • ProjectContext & MemoryContext — The active scope for this memory instance.

Usage Example

import { MemMachineClient } from '@memmachine/client';

const client = new MemMachineClient({ base_url: 'https://your-base-url' });
const project = client.project({ org_id: 'your_org_id', project_id: 'your_project_id'})
const memory = project.memory();

// 1. Store a piece of information
await memory.add('The user mentioned they live in Seattle and love hiking.');

// 2. Retrieve information later
const response = await memory.search('Where does the user live?');

if (response.memories.length > 0) {
  console.log(`Found memory: ${response.memories[0].content}`);
}