@okcashpro/okai v0.1.7-alpha.1 / MemoryManager
Class: MemoryManager
Manage memories in the database.
Implements
Constructors
new MemoryManager()
new MemoryManager(
opts
):MemoryManager
Constructs a new MemoryManager instance.
Parameters
• opts
Options for the manager.
• opts.tableName: string
The name of the table this manager will operate on.
• opts.runtime: IAgentRuntime
The AgentRuntime instance associated with this manager.
Returns
Defined in
packages/core/src/memory.ts:33
Properties
runtime
runtime:
IAgentRuntime
The AgentRuntime instance associated with this manager.
Implementation of
Defined in
packages/core/src/memory.ts:20
tableName
tableName:
string
The name of the database table this manager operates on.
Implementation of
Defined in
packages/core/src/memory.ts:25
Methods
addEmbeddingToMemory()
addEmbeddingToMemory(
memory
):Promise
<Memory
>
Adds an embedding vector to a memory object if one doesn't already exist. The embedding is generated from the memory's text content using the runtime's embedding model. If the memory has no text content, an error is thrown.
Parameters
• memory: Memory
The memory object to add an embedding to
Returns
Promise
<Memory
>
The memory object with an embedding vector added
Throws
Error if the memory content is empty
Implementation of
IMemoryManager
.addEmbeddingToMemory
Defined in
packages/core/src/memory.ts:52
getMemories()
getMemories(
opts
):Promise
<Memory
[]>
Retrieves a list of memories by user IDs, with optional deduplication.
Parameters
• opts
Options including user IDs, count, and uniqueness.
• opts.roomId: `${string}-${string}-${string}-${string}-${string}`
The room ID to retrieve memories for.
• opts.count?: number
= 10
The number of memories to retrieve.
• opts.unique?: boolean
= true
Whether to retrieve unique memories only.
• opts.start?: number
• opts.end?: number
Returns
Promise
<Memory
[]>
A Promise resolving to an array of Memory objects.
Implementation of
Defined in
packages/core/src/memory.ts:87
getCachedEmbeddings()
getCachedEmbeddings(
content
):Promise
<object
[]>
Parameters
• content: string
Returns
Promise
<object
[]>
Implementation of
IMemoryManager
.getCachedEmbeddings
Defined in
packages/core/src/memory.ts:111
searchMemoriesByEmbedding()
searchMemoriesByEmbedding(
embedding
,opts
):Promise
<Memory
[]>
Searches for memories similar to a given embedding vector.
Parameters
• embedding: number
[]
The embedding vector to search with.
• opts
Options including match threshold, count, user IDs, and uniqueness.
• opts.match_threshold?: number
The similarity threshold for matching memories.
• opts.count?: number
The maximum number of memories to retrieve.
• opts.roomId: `${string}-${string}-${string}-${string}-${string}`
The room ID to retrieve memories for.
• opts.unique?: boolean
Whether to retrieve unique memories only.
Returns
Promise
<Memory
[]>
A Promise resolving to an array of Memory objects that match the embedding.
Implementation of
IMemoryManager
.searchMemoriesByEmbedding
Defined in
packages/core/src/memory.ts:137
createMemory()
createMemory(
memory
,unique
):Promise
<void
>
Creates a new memory in the database, with an option to check for similarity before insertion.
Parameters
• memory: Memory
The memory object to create.
• unique: boolean
= false
Whether to check for similarity before insertion.
Returns
Promise
<void
>
A Promise that resolves when the operation completes.
Implementation of
Defined in
packages/core/src/memory.ts:172
getMemoriesByRoomIds()
getMemoriesByRoomIds(
params
):Promise
<Memory
[]>
Parameters
• params
• params.roomIds: `${string}-${string}-${string}-${string}-${string}`[]
Returns
Promise
<Memory
[]>
Implementation of
IMemoryManager
.getMemoriesByRoomIds
Defined in
packages/core/src/memory.ts:192
getMemoryById()
getMemoryById(
id
):Promise
<Memory
>
Parameters
• id: `${string}-${string}-${string}-${string}-${string}`
Returns
Promise
<Memory
>
Implementation of
Defined in
packages/core/src/memory.ts:200
removeMemory()
removeMemory(
memoryId
):Promise
<void
>
Removes a memory from the database by its ID.
Parameters
• memoryId: `${string}-${string}-${string}-${string}-${string}`
The ID of the memory to remove.
Returns
Promise
<void
>
A Promise that resolves when the operation completes.
Implementation of
Defined in
packages/core/src/memory.ts:211
removeAllMemories()
removeAllMemories(
roomId
):Promise
<void
>
Removes all memories associated with a set of user IDs.
Parameters
• roomId: `${string}-${string}-${string}-${string}-${string}`
The room ID to remove memories for.
Returns
Promise
<void
>
A Promise that resolves when the operation completes.
Implementation of
IMemoryManager
.removeAllMemories
Defined in
packages/core/src/memory.ts:223
countMemories()
countMemories(
roomId
,unique
):Promise
<number
>
Counts the number of memories associated with a set of user IDs, with an option for uniqueness.
Parameters
• roomId: `${string}-${string}-${string}-${string}-${string}`
The room ID to count memories for.
• unique: boolean
= true
Whether to count unique memories only.
Returns
Promise
<number
>
A Promise resolving to the count of memories.