Skip to content

API Reference parrot.memory.episodic.backends.abstract

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.memory.episodic.backends.abstract

View source

Abstract backend protocol for episodic memory storage.

Class AbstractEpisodeBackend

Protocol defining the storage backend interface for episodes.

Implementations must provide methods for storing, searching, retrieving, and maintaining episodic memory records. Namespace filters may include every non-null MemoryNamespace dimension, including model_id. A dimension whose filter value is None matches only episodes that leave it unset; a backend that cannot apply that before its limit returns no rows rather than ignoring it. Transactional dynamics reviews are an optional ReviewBackend capability and are not required by this baseline protocol.

Method AbstractEpisodeBackend.store

Store an episode. Returns the episode_id.

store(episode: EpisodicMemory) -> str

Parameter Type Default Description
episode EpisodicMemory The episode to store.

Returns: str — The episode_id of the stored episode.

Method AbstractEpisodeBackend.search_similar

Search episodes by vector similarity with dimensional filters.

search_similar(embedding: list[float], namespace_filter: dict[str, Any], top_k: int = 5, score_threshold: float = 0.3, include_failures_only: bool = False) -> list[EpisodeSearchResult]

Parameter Type Default Description
embedding list[float] Query embedding vector.
namespace_filter dict[str, Any] Dict of field_name -> value for WHERE filtering.
top_k int 5 Maximum results to return.
score_threshold float 0.3 Minimum similarity score (0-1).
include_failures_only bool False If True, only return failure episodes.

Returns: list[EpisodeSearchResult] — List of episodes ranked by similarity score.

Method AbstractEpisodeBackend.get_recent

Get recent episodes by namespace, ordered by created_at DESC.

get_recent(namespace_filter: dict[str, Any], limit: int = 10, since: datetime | None = None) -> list[EpisodicMemory]

Parameter Type Default Description
namespace_filter dict[str, Any] Dict of field_name -> value for WHERE filtering.
limit int 10 Maximum results to return.
since datetime | None None Only return episodes created after this datetime.

Returns: list[EpisodicMemory] — List of recent episodes.

Method AbstractEpisodeBackend.get_failures

Get recent failure episodes for an agent.

This baseline compatibility lookup remains limited to agent and tenant scope. Backends that support more narrowly scoped retrieval use the namespace_filter accepted by get_recent and search_similar.

get_failures(agent_id: str, tenant_id: str = 'default', limit: int = 5) -> list[EpisodicMemory]

Parameter Type Default Description
agent_id str Agent identifier.
tenant_id str 'default' Tenant identifier.
limit int 5 Maximum results to return.

Returns: list[EpisodicMemory] — List of failure episodes, most recent first.

Method AbstractEpisodeBackend.delete_expired

Delete episodes that have passed their expires_at timestamp.

delete_expired() -> int

Returns: int — Number of episodes deleted.

Method AbstractEpisodeBackend.count

Count episodes matching a namespace filter.

count(namespace_filter: dict[str, Any]) -> int

Parameter Type Default Description
namespace_filter dict[str, Any] Dict of field_name -> value for WHERE filtering.

Returns: int — Number of matching episodes.

Method AbstractEpisodeBackend.update_metadata

Merge patch into the metadata dict of the given episodes.

Used by the dream cycle (FEAT-390) to mark episodes as consolidated (metadata["consolidated_into"] = <page_id>) without deleting them — existing TTL/compaction keeps pruning.

update_metadata(episode_ids: list[str], patch: dict[str, Any]) -> int

Parameter Type Default Description
episode_ids list[str] Episode ids to patch. Unknown ids are ignored (not an error).
patch dict[str, Any] Key-value pairs merged into each episode's metadata.

Returns: int — Number of episodes actually updated.

Alias EpisodeSearchResult

Re-exported from parrot.memory.episodic.models.EpisodeSearchResult.

Alias EpisodicMemory

Re-exported from parrot.memory.episodic.models.EpisodicMemory.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally