Memory API¶
memory ¶
Memory subsystem for orqest agents.
Provides a pluggable memory protocol (MemoryStore) with a local SQLite backend. Three cognitive memory kinds are first-class:
- semantic — what's true (facts, summaries)
- episodic — what happened (sessions, traces)
- procedural — how to do things (skills via :class:
Skill)
MemoryConfig
dataclass
¶
MemoryConfig(
backend: Literal["local", "supabase"] = "local",
local_db_path: str = "~/.orqest/memory.db",
embedding_model: str = "all-MiniLM-L6-v2",
embedding_dim: int = 384,
supabase_url: str | None = None,
supabase_key: str | None = None,
semantic: PerKindConfig = PerKindConfig(),
episodic: PerKindConfig = PerKindConfig(),
procedural: PerKindConfig = PerKindConfig(),
tool: PerKindConfig = (
lambda: PerKindConfig(
ttl_days=None,
version_on_edit=True,
decay_on_failure=0.5,
)
)(),
)
Immutable configuration for the memory subsystem.
PerKindConfig
dataclass
¶
PerKindConfig(
decay_on_failure: float = 0.7,
prune_below: float = 0.1,
ttl_days: int | None = None,
version_on_edit: bool = False,
)
Per-kind reliability / retention / versioning policy.
decay_on_failure
class-attribute
instance-attribute
¶
Reliability multiplier applied on a failed-recall report.
prune_below
class-attribute
instance-attribute
¶
Reliability floor below which an entry is pruned after decay.
ttl_days
class-attribute
instance-attribute
¶
Retention window. None means keep forever; otherwise entries
older than this are deleted by :meth:LocalMemoryStore.prune_expired.
version_on_edit
class-attribute
instance-attribute
¶
When True, storing a procedural entry whose structured_content.name
matches an already-stored skill bumps the new entry's version one past
the highest stored version and keeps the prior rows — an audit trail.
LocalMemoryStore ¶
LocalMemoryStore(
db_path: str | Path | None = None,
*,
config: MemoryConfig | None = None,
embedder: EmbedderT | None = None,
strategies: dict[str, RetrievalStrategy] | None = None,
)
SQLite-backed memory store with optional FTS5 full-text search.
Per-kind retrieval strategies are configurable via the strategies
constructor argument; the default table provides Semantic / Episodic
/ Procedural strategies. Override individual entries to inject
custom behavior (e.g. a fuzzy judge for procedural recall).
Initialize the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
str | Path | None
|
SQLite file path (created lazily). When omitted,
|
None
|
config
|
MemoryConfig | None
|
Memory subsystem configuration. Supplies the per-kind
policy read by :meth: |
None
|
embedder
|
EmbedderT | None
|
Optional |
None
|
strategies
|
dict[str, RetrievalStrategy] | None
|
Optional override of the per-kind retrieval table.
Defaults to |
None
|
Source code in orqest/memory/local.py
store
async
¶
Persist a memory entry. Returns the entry id.
When the procedural per-kind policy has version_on_edit=True and
a procedural entry's structured_content.name matches an existing
stored skill, the new entry's version is bumped to one past the
highest stored version — the prior rows are kept (entries are keyed
by id, so this is always an INSERT, never an overwrite-by-name).
Source code in orqest/memory/local.py
recall
async
¶
Retrieve entries matching the query, applying optional filters.
Dispatches to the strategy keyed by filters.memory_type.
Unknown / missing memory_type → "semantic" strategy
(preserves v0.0.1 behavior).
Source code in orqest/memory/local.py
forget
async
¶
Remove a memory entry by id. No error if not found.
Source code in orqest/memory/local.py
update_reliability
async
¶
Decay an entry's reliability on a failed-recall report.
success is a no-op — reliability only decays. On failure the
entry's reliability is multiplied by the per-kind
decay_on_failure factor, and the entry is pruned if it drops
below the per-kind prune_below floor (see :class:PerKindConfig).
Source code in orqest/memory/local.py
prune_expired
async
¶
Delete entries older than their per-kind ttl_days.
Best-effort maintenance: a kind whose :class:PerKindConfig.ttl_days
is None is never pruned. Errors are logged, never raised — the
method returns the number of rows deleted (0 on failure).
Source code in orqest/memory/local.py
count
async
¶
Return the total number of stored entries.
Source code in orqest/memory/local.py
list_recent
async
¶
Return the most recently stored entries, newest first.
Browse-style enumeration that complements :meth:recall (which
is query-driven). Used by consumer surfaces that want to render
a "memory inspector" view without issuing a search. Filters
by memory_type when supplied; None returns every kind.
Best-effort like the other read paths — returns [] on any
SQLite failure rather than raising.
Source code in orqest/memory/local.py
MemoryEntry ¶
A single unit of stored knowledge.
structured_content
class-attribute
instance-attribute
¶
Typed payload for non-text memory (e.g. Skill for procedural).
When memory_type == "procedural" and this field is set, it must
validate against the :class:Skill schema. Validation is gated to
procedural entries to keep the legacy semantic/episodic paths
untouched.
MemoryFilter ¶
Query-time constraints for memory recall.
MemoryStore ¶
Skill ¶
Procedural memory content — a learned tool sequence with outcome.
Stored inside :class:MemoryEntry.structured_content when
memory_type == "procedural". The trigger field is the
natural-language phrase the agent matches against to decide whether
to invoke the skill; it is also written verbatim into
:class:MemoryEntry.content so FTS5 still indexes it.
SkillExample ¶
A worked example of a successful Skill invocation.
ToolCallSpec ¶
One step in a Skill's tool_sequence.
EpisodicStrategy ¶
Time-windowed search ordered by created_at DESC.
Same content matching as Semantic, but the ordering reflects the
"what happened" framing of episodic memory. A future extension may
honor filters.metadata.session_id for session-scoped recall.
ProceduralStrategy ¶
Trigger-match retrieval for skills.
Algorithm
- Lower-case the query.
- SQL: select procedural rows whose
structured_content -> '$.trigger'(lower-cased) equals the query OR contains the query as a substring. - Honor
filters.skill_name(exact match onstructured_content -> '$.name') andfilters.skill_min_version(versionnumeric compare). - Order by
reliability_score DESC, version DESC, last_accessed DESC. - If exact-match returns rows, return up to
k. - Else if
fuzzy_judgeis configured, ask it to pick from the top 20 candidate triggers and return judged matches. - Else return
[].
The fuzzy judge is injected, not built-in — Orqest core stays LLM-judge-neutral; the consumer wires one if desired.
Source code in orqest/memory/strategies.py
RetrievalStrategy ¶
One strategy per memory_type. The store dispatches to it.
SemanticStrategy ¶
Content retrieval — embedding cosine, or FTS5 / LIKE keyword match.
With no embedder this is identical to the v0.0.1 keyword behavior,
ordered by recency of access. With an embedder, recall embeds the
query, brute-force scores every stored vector by cosine similarity, and
returns the top-k — fine for the local SQLite store; the pgvector
backend is the path to scale.
Store the optional embedder; None selects the FTS5 path.
Source code in orqest/memory/strategies.py
default_strategy_table ¶
The default per-kind retrieval table used by :class:LocalMemoryStore.
When embedder is supplied, :class:SemanticStrategy ranks by
embedding cosine similarity; otherwise it falls back to FTS5 / LIKE.