Skip to content

Retrieval

Best-effort retrieval bookkeeping for vector memories.

RetrievalTouchBatcher(*, memory_client, batch_delay_seconds=DEFAULT_RETRIEVAL_TOUCH_BATCH_DELAY_SECONDS, max_batch_size=DEFAULT_RETRIEVAL_TOUCH_MAX_BATCH_SIZE, max_pending_memory_ids=DEFAULT_RETRIEVAL_TOUCH_MAX_PENDING_MEMORY_IDS)

Batch best-effort retrieval timestamp writes outside the search path.

One batcher belongs to one memory manager. It keeps one background task and a bounded set of pending IDs, so a slow provider cannot accumulate a task or write for every successful search.

Parameters:

Name Type Description Default
memory_client BaseMemoryClient

Provider client that owns memory rows.

required
batch_delay_seconds float

Delay used to coalesce nearby searches. Defaults to DEFAULT_RETRIEVAL_TOUCH_BATCH_DELAY_SECONDS.

DEFAULT_RETRIEVAL_TOUCH_BATCH_DELAY_SECONDS
max_batch_size int

Maximum IDs in one provider touch. Defaults to DEFAULT_RETRIEVAL_TOUCH_MAX_BATCH_SIZE.

DEFAULT_RETRIEVAL_TOUCH_MAX_BATCH_SIZE
max_pending_memory_ids int

Maximum unique IDs retained while a provider touch is in progress. Defaults to DEFAULT_RETRIEVAL_TOUCH_MAX_PENDING_MEMORY_IDS.

DEFAULT_RETRIEVAL_TOUCH_MAX_PENDING_MEMORY_IDS

Initialize bounded background retrieval bookkeeping.

aclose() async

Cancel and await pending background retrieval bookkeeping.

close()

Cancel pending bookkeeping without waiting for its background task.

This synchronous method is safe for weakref.finalize. Call :meth:aclose when the caller can await cancellation.

enqueue(memory_ids)

Queue unique memory IDs without waiting for provider bookkeeping.

Parameters:

Name Type Description Default
memory_ids list[str]

Final vector-memory identifiers returned to the caller.

required

extract_vector_memory_ids(chunks)

Return unique vector-memory identifiers from final search results.

Parameters:

Name Type Description Default
chunks list[Chunk]

Final chunks selected for the search response.

required

Returns:

Type Description
list[str]

list[str]: Unique vector-memory identifiers in result order.

Notes

Vector memories retain the stored conversation role. Knowledge Graph chunks do not use that role and are excluded.