Memory
Defined in: .build/typescript/packages/core/src/memory/memory.ts:49
Type Parameters
Section titled “Type Parameters”TAdapters
Section titled “TAdapters”TAdapters
extends Record
<string
, MessageAdapter
<unknown
, TMessageOptions
>> = Record
<string
, never
>
TMessageOptions
Section titled “TMessageOptions”TMessageOptions
extends object
= object
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Memory<
TAdapters
,TMessageOptions
>(messages
,options
):Memory
<TAdapters
,TMessageOptions
>
Defined in: .build/typescript/packages/core/src/memory/memory.ts:90
Parameters
Section titled “Parameters”messages
Section titled “messages”MemoryMessage
<TMessageOptions
>[] = []
options
Section titled “options”MemoryOptions
<TMessageOptions
> = {}
Returns
Section titled “Returns”Memory
<TAdapters
, TMessageOptions
>
Methods
Section titled “Methods”add(
message
):Promise
<void
>
Defined in: .build/typescript/packages/core/src/memory/memory.ts:123
Add a message to the memory
Parameters
Section titled “Parameters”message
Section titled “message”unknown
The message to add to the memory
Returns
Section titled “Returns”Promise
<void
>
get<
K
>(options
):Promise
<K
extends keyofTAdapters
| keyof BuiltinAdapters<TMessageOptions> ?ReturnType
<TAdapters
&BuiltinAdapters
<TMessageOptions
>[K
<K
>]["fromMemory"
]>[] :never
>
Defined in: .build/typescript/packages/core/src/memory/memory.ts:151
Get the messages of specific type from the memory
Type Parameters
Section titled “Type Parameters”K
extends string
| number
| symbol
= "llamaindex"
Parameters
Section titled “Parameters”options
Section titled “options”The options for the get method
K
transientMessages?
Section titled “transientMessages?”ChatMessage
<TMessageOptions
>[]
Returns
Section titled “Returns”Promise
<K
extends keyof TAdapters
| keyof BuiltinAdapters<TMessageOptions> ? ReturnType
<TAdapters
& BuiltinAdapters
<TMessageOptions
>[K
<K
>]["fromMemory"
]>[] : never
>
The messages of specific type
getLLM()
Section titled “getLLM()”getLLM(
llm
,transientMessages?
):Promise
<ChatMessage
[]>
Defined in: .build/typescript/packages/core/src/memory/memory.ts:200
Get the messages from the memory, optionally including transient messages. only return messages that are within context window of the LLM
Parameters
Section titled “Parameters”To fit the result messages to the context window of the LLM (fallback to default llm if not provided). If llm is not specified in both the constructor and the method, the default token limit will be used.
undefined
| LLM
<object
, object
>
transientMessages?
Section titled “transientMessages?”ChatMessage
<TMessageOptions
>[]
Optional transient messages to include.
Returns
Section titled “Returns”Promise
<ChatMessage
[]>
The messages from the memory, optionally including transient messages.
manageMemoryBlocks()
Section titled “manageMemoryBlocks()”manageMemoryBlocks():
Promise
<void
>
Defined in: .build/typescript/packages/core/src/memory/memory.ts:338
Manage the memory blocks This method processes new messages into memory blocks when short-term memory exceeds its token limit. It uses a cursor system to track which messages have already been processed into long-term memory.
Returns
Section titled “Returns”Promise
<void
>
clear()
Section titled “clear()”clear():
Promise
<void
>
Defined in: .build/typescript/packages/core/src/memory/memory.ts:409
Clear all the messages in the memory
Returns
Section titled “Returns”Promise
<void
>
snapshot()
Section titled “snapshot()”snapshot():
string
Defined in: .build/typescript/packages/core/src/memory/memory.ts:420
Creates a snapshot of the current memory state Note: Memory blocks are not included in snapshots as they may contain non-serializable content. Memory blocks should be recreated when loading from snapshot.
Returns
Section titled “Returns”string
A JSON-serializable object containing the memory state