Skip to content

Memory

Defined in: .build/typescript/packages/core/src/memory/memory.ts:49

TAdapters extends Record<string, MessageAdapter<unknown, TMessageOptions>> = Record<string, never>

TMessageOptions extends object = object

new Memory<TAdapters, TMessageOptions>(messages, options): Memory<TAdapters, TMessageOptions>

Defined in: .build/typescript/packages/core/src/memory/memory.ts:90

MemoryMessage<TMessageOptions>[] = []

MemoryOptions<TMessageOptions> = {}

Memory<TAdapters, TMessageOptions>

add(message): Promise<void>

Defined in: .build/typescript/packages/core/src/memory/memory.ts:123

Add a message to the memory

unknown

The message to add to the memory

Promise<void>


get<K>(options): Promise<K extends keyof TAdapters | 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

K extends string | number | symbol = "llamaindex"

The options for the get method

K

ChatMessage<TMessageOptions>[]

Promise<K extends keyof TAdapters | keyof BuiltinAdapters<TMessageOptions> ? ReturnType<TAdapters & BuiltinAdapters<TMessageOptions>[K<K>]["fromMemory"]>[] : never>

The messages of specific type


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

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>

ChatMessage<TMessageOptions>[]

Optional transient messages to include.

Promise<ChatMessage[]>

The messages from the memory, optionally including transient messages.


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.

Promise<void>


clear(): Promise<void>

Defined in: .build/typescript/packages/core/src/memory/memory.ts:409

Clear all the messages in the memory

Promise<void>


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.

string

A JSON-serializable object containing the memory state