Skip to Content
Anuma SDKReactInternalFunctionschunkAndEmbedAllMessages

chunkAndEmbedAllMessages

chunkAndEmbedAllMessages(ctx: StorageOperationsContext, options: MemoryEngineEmbeddingOptions & ChunkingOptions, filter?: object): Promise<number>

Defined in: src/lib/memoryEngine/embeddings.ts:340 

Chunk and embed messages that don’t yet have embeddings/chunks in the database. Uses chunking for long messages, whole-message embedding for short ones.

Upgrade note: by default this SKIPS messages that already have a whole-message vector. An app migrating from whole-message embeddings to chunk-based search must pass filter.rechunkExisting: true to (re)chunk those existing messages — otherwise they get no chunk rows and chunk search stays incomplete for the back-catalog.

Requires embedding auth (apiKey or getToken in options; see EmbeddingOptions) — rejects with "Either apiKey or getToken must be provided" if neither is set.

Parameters

ParameterTypeDescription

ctx

StorageOperationsContext

Storage operations context

options

MemoryEngineEmbeddingOptions & ChunkingOptions

Embedding and chunking options (auth required — see above)

filter?

object

Optional filter for which messages to embed

filter.conversationId?

string

Only embed messages from this conversation

filter.minContentLength?

number

Minimum content length to embed (default: 30). Shorter messages are skipped.

filter.rechunkExisting?

boolean

Re-chunk messages that have whole-message embeddings but no chunks

filter.reembedDiscarded?

boolean

Re-index rows the ciphertext sweep marked CHUNKS_DISCARDED_ORIGIN. Off by default: this spends the user’s own embedding credits, so it belongs to an explicit user action, never to a background pass. Opens that marker only — tool_result rows stay excluded.

rechunkExisting cannot substitute for it: a discarded row has neither chunks nor vector, so it never reaches that check and falls straight to the origin gate.

A successful repair clears the marker. Later model migrations include the repaired row without this flag. See CHUNKS_DISCARDED_ORIGIN.

filter.roles?

("user" | "assistant")[]

Only embed messages with these roles

Returns

Promise<number>

Number of messages embedded

Last updated on