ConversationMemory class
Persists a conversation and assembles its context for the next turn.
Every message is stored with its embedding, so besides the most recent turns context can recall older turns relevant to the new question — the conversation can outgrow any context window without forgetting.
Messages are keyed by a monotonic timestamp rather than a position, so two handles on one conversation (a UI isolate and a background job, say) can both append without overwriting each other, and deleting messages never makes a later append collide with a surviving one. Each append first reads the newest stored message, so the order holds across handles even where the platform clock is coarse; two genuinely simultaneous appends may still tie, and then their relative order is arbitrary but neither is lost.
Properties
- conversationId → String
-
Conversation id.
final
- embedder → Embedder
-
Embeds messages and questions.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- length ↔ int
-
Messages this handle has seen: the count when it opened plus what it has
appended. Another handle's appends are not reflected; count asks the
store.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- store → DocumentStore
-
Where messages live (may be shared with other data; messages are
tagged with their conversation).
final
Methods
-
add(
ChatMessage message) → Future< void> - Appends one message.
-
addAll(
List< ChatMessage> messages) → Future<void> - Appends messages to the conversation.
-
clear(
) → Future< int> - Deletes the conversation; returns how many messages were removed.
-
context(
String query, {int recentCount = 8, int recalled = 4}) → Future< List< ChatMessage> > -
Context for answering
query: up torecalledrelevant older messages (wrapped in a system note so the model knows they are excerpts), then the lastrecentCountmessages. -
count(
) → Future< int> - Messages stored in this conversation right now, from the store.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recall(
String query, {int k = 4, int skipRecent = 0}) → Future< List< ChatMessage> > -
Up to
kearlier messages most relevant toquery, oldest first, excluding the lastskipRecent(which recent already covers). -
recent(
[int n = 10]) → Future< List< ChatMessage> > -
The last
nmessages, oldest first. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
open(
{required DocumentStore store, required Embedder embedder, required String conversationId}) → Future< ConversationMemory> -
Opens (or starts) conversation
conversationId.