Memory class
Constructor
Session ID. If
None, generates a new UUID. Used to track session-level memory.Custom vector backend (for advanced use — usually auto-configured).
Custom storage backend (for advanced use — usually auto-configured).
remember()
Write to all three memory layers in one call.recall()
Search across all three layers and return ranked results.Results object with:
results: list ofRankedMemoryranked by composite scoretotal_found: total matches before rankingcache_hit: whether result came from semantic cachelatency_ms: query time in milliseconds
context_for()
Build a token-budgeted context string for prompt injection.Maximum tokens (default from config: 2048). Memories are included until budget is reached.
content: Formatted string ready for injectiontoken_count: Actual tokens usedtoken_budget: Budget providedmemories_used: Number of results includedcache_hit: Whether result came from cache
flush()
End current session and flush working memory to episodic.close()
Close database connections and cleanup.Layer access
All three layers are available as direct attributes:working
Direct access to working memory layer.episodic
Direct access to episodic memory layer.semantic
Direct access to semantic memory (knowledge graph).Fact
Semantic memory triple: subject–predicate–object.FactRelation enum
See Memory layers for complete list and descriptions. Values:PREFERS, DISLIKES, IS, IS_A, HAS, HAS_PROPERTY, KNOWS, USES, WORKS_ON, LOCATED_IN, BELONGS_TO, RELATED_TO, REQUIRES, LEARNED_FROM, CUSTOM
MemoryConfig
Configuration class (Pydantic BaseSettings). All fields supportPLYRA_* environment variables.
MemoryLayer enum
Values:WORKING, EPISODIC, SEMANTIC
Environment variables
All configuration can be set viaPLYRA_* env vars: