Skip to main content

Overview

The SearchMemoriesOptions interface allows you to refine how the memory engine retrieves and ranks results. It is used as the optional second argument in the MemMachineMemory.search() method.

Properties

All properties in this interface are optional.
PropertyTypeDescription
top_knumberThe maximum number of relevant memories to return.
score_thresholdnumberThe minimum similarity score required for a memory to be included in results.
filterstringA metadata-based filter string to narrow the search scope.
expand_contextnumberThe number of surrounding chronological episodes to retrieve for each hit.
typesMemoryType[]Restricts the search to specific memory classifications (e.g., semantic).

Usage Example

The following example demonstrates how to perform a filtered search with a specific limit and context expansion.
import { SearchMemoriesOptions } from '@memmachine/client';

const memory = project.memory();

const searchConfig: SearchMemoriesOptions = {
  top_k: 5,
  score_threshold: 0.75,
  expand_context: 2, // Get 2 messages before and after each hit
  types: ['episodic']
};

const results = await memory.search(
  'What are the user preferences for UI themes?', 
  searchConfig
);
Use expand_context when you need the LLM to understand the conversation flow surrounding a specific memory hit, rather than just the hit itself.