Skip to main content

Class: MemoryManager

Manage memories in the database.

Constructors

constructor

new MemoryManager(opts): MemoryManager

Constructs a new MemoryManager instance.

Parameters

NameTypeDescription
optsObjectOptions for the manager.
opts.runtimeAgentRuntimeThe AgentRuntime instance associated with this manager.
opts.tableNamestringThe name of the table this manager will operate on.

Returns

MemoryManager

Properties

runtime

runtime: AgentRuntime

The AgentRuntime instance associated with this manager.


tableName

tableName: string

The name of the database table this manager operates on.

Methods

addEmbeddingToMemory

addEmbeddingToMemory(memory): Promise<Memory>

Adds an embedding vector to a memory object. If the memory already has an embedding, it is returned as is.

Parameters

NameTypeDescription
memoryMemoryThe memory object to add an embedding to.

Returns

Promise<Memory>

A Promise resolving to the memory object, potentially updated with an embedding vector.


countMemories

countMemories(room_id, unique?): Promise<number>

Counts the number of memories associated with a set of user IDs, with an option for uniqueness.

Parameters

NameTypeDefault valueDescription
room_id`${string}-${string}-${string}-${string}-${string}`undefinedThe room ID to count memories for.
uniquebooleantrueWhether to count unique memories only.

Returns

Promise<number>

A Promise resolving to the count of memories.


createMemory

createMemory(memory, unique?): Promise<void>

Creates a new memory in the database, with an option to check for similarity before insertion.

Parameters

NameTypeDefault valueDescription
memoryMemoryundefinedThe memory object to create.
uniquebooleanfalseWhether to check for similarity before insertion.

Returns

Promise<void>

A Promise that resolves when the operation completes.


getCachedEmbeddings

getCachedEmbeddings(content): Promise<{ embedding: number[] ; levenshtein_score: number }[]>

Parameters

NameType
contentstring

Returns

Promise<{ embedding: number[] ; levenshtein_score: number }[]>


getMemories

getMemories(opts): Promise<Memory[]>

Retrieves a list of memories by user IDs, with optional deduplication.

Parameters

NameTypeDefault valueDescription
optsObjectundefinedOptions including user IDs, count, and uniqueness.
opts.count?number10The number of memories to retrieve.
opts.room_id`${string}-${string}-${string}-${string}-${string}`undefinedThe room ID to retrieve memories for.
opts.unique?booleantrueWhether to retrieve unique memories only.

Returns

Promise<Memory[]>

A Promise resolving to an array of Memory objects.


removeAllMemories

removeAllMemories(room_id): Promise<void>

Removes all memories associated with a set of user IDs.

Parameters

NameTypeDescription
room_id`${string}-${string}-${string}-${string}-${string}`The room ID to remove memories for.

Returns

Promise<void>

A Promise that resolves when the operation completes.


removeMemory

removeMemory(memoryId): Promise<void>

Removes a memory from the database by its ID.

Parameters

NameTypeDescription
memoryId`${string}-${string}-${string}-${string}-${string}`The ID of the memory to remove.

Returns

Promise<void>

A Promise that resolves when the operation completes.


searchMemoriesByEmbedding

searchMemoriesByEmbedding(embedding, opts): Promise<Memory[]>

Searches for memories similar to a given embedding vector.

Parameters

NameTypeDescription
embeddingnumber[]The embedding vector to search with.
optsObjectOptions including match threshold, count, user IDs, and uniqueness.
opts.count?numberThe maximum number of memories to retrieve.
opts.match_threshold?numberThe similarity threshold for matching memories.
opts.room_id`${string}-${string}-${string}-${string}-${string}`The room ID to retrieve memories for.
opts.unique?booleanWhether to retrieve unique memories only.

Returns

Promise<Memory[]>

A Promise resolving to an array of Memory objects that match the embedding.