Memory Architecture and Vector Store
Palyra utilizes a SQLite-backedJournalStore to manage memory items. Each memory item consists of raw text, metadata (tags, source, confidence), and an embedding vector for semantic retrieval [crates/palyra-daemon/src/journal.rs#64-100](http://crates/palyra-daemon/src/journal.rs#64-100).
Implementation Details
- Storage: Memory is stored in the
memory_itemstable within the SQLite journal. - Search: The system performs hybrid search by combining:
- Vector Search: Uses cosine similarity against embeddings generated by a
MemoryEmbeddingProvider[crates/palyra-daemon/src/journal.rs#64-68](http://crates/palyra-daemon/src/journal.rs#64-68). - Lexical Search: Integrated via SQLite FTS5 for exact keyword matching.
- Recency: Scoring is weighted by the
created_at_unix_mstimestamp to prefer fresher information[crates/palyra-cli/src/commands/memory.rs#131-139](http://crates/palyra-cli/src/commands/memory.rs#131-139).
- Vector Search: Uses cosine similarity against embeddings generated by a
- Embeddings: By default, the system uses a
HashMemoryEmbeddingProvider(64 dimensions) for local, deterministic testing, but supports pluggable models[crates/palyra-daemon/src/journal.rs#71-79](http://crates/palyra-daemon/src/journal.rs#71-79).
Data Flow: Memory Injection
When a run is initialized, theprepare_model_provider_input function automatically queries the memory store based on the current session context and injects relevant snippets into the LLM prompt [crates/palyra-daemon/src/application/run_stream/orchestration.rs#16-18](http://crates/palyra-daemon/src/application/run_stream/orchestration.rs#16-18).
The Learning Subsystem
The Learning subsystem is a background process that reflects on completed conversations to extract “Durable Facts” and “User Preferences”[crates/palyra-daemon/src/gateway/runtime.rs#85-97](http://crates/palyra-daemon/src/gateway/runtime.rs#85-97).
Learning Pipeline
- Post-Run Reflection: After a run completes, a
REFLECTION_TASK_KINDbackground task is scheduled[crates/palyra-daemon/src/background_queue.rs#11-12](http://crates/palyra-daemon/src/background_queue.rs#11-12). - Candidate Extraction: The system analyzes the transcript to identify potential new facts or preferences, assigning them a Confidence Score in basis points (bps)
[crates/palyra-daemon/src/gateway/runtime.rs#151-166](http://crates/palyra-daemon/src/gateway/runtime.rs#151-166). - Thresholds:
- Auto-Write: If confidence exceeds
durable_fact_auto_write_threshold_bps(default 9000), the fact is committed to memory immediately[crates/palyra-daemon/src/gateway/runtime.rs#160](http://crates/palyra-daemon/src/gateway/runtime.rs#160). - Review: If confidence is lower but above the
review_min_confidence_bps, it is placed in a “Learning Candidate” state for manual operator approval[crates/palyra-daemon/src/gateway/runtime.rs#159-161](http://crates/palyra-daemon/src/gateway/runtime.rs#159-161).
- Auto-Write: If confidence exceeds
Natural Language to Code Entity Mapping: Learning Flow
This diagram shows how a user message results in a durable code entity in the database. Title: Learning Extraction Pipeline Sources:[crates/palyra-daemon/src/background_queue.rs#11-15](http://crates/palyra-daemon/src/background_queue.rs#11-15), [crates/palyra-daemon/src/gateway/runtime.rs#8-27](http://crates/palyra-daemon/src/gateway/runtime.rs#8-27), [crates/palyra-daemon/src/journal.rs#64-71](http://crates/palyra-daemon/src/journal.rs#64-71)
Memory Maintenance and Retention
Memory is not infinite; it is managed by a background loop that enforcesMemoryRetentionPolicy [crates/palyra-daemon/src/journal.rs#64-66](http://crates/palyra-daemon/src/journal.rs#64-66).
Maintenance Loop
Thespawn_background_queue_loop handles periodic maintenance tasks [crates/palyra-daemon/src/background_queue.rs#31-35](http://crates/palyra-daemon/src/background_queue.rs#31-35):
- TTL Expiry: Items with a
ttl_unix_msin the past are purged. - Size Constraints: If
retention_max_bytesorretention_max_entriesare exceeded, the system evicts the oldest/lowest confidence items[crates/palyra-daemon/src/gateway/runtime.rs#78-80](http://crates/palyra-daemon/src/gateway/runtime.rs#78-80). - Embedding Backfill: A background process scans for memory items missing vectors and generates them using the configured provider
[crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#143-147](http://crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#143-147).
Memory Management Components
Title: Memory System Class Interactions Sources:[crates/palyra-daemon/src/journal.rs#64-100](http://crates/palyra-daemon/src/journal.rs#64-100), [crates/palyra-daemon/src/gateway/runtime.rs#72-82](http://crates/palyra-daemon/src/gateway/runtime.rs#72-82), [crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#11-22](http://crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#11-22)
Configuration and Limits
Memory behavior is governed byFileMemoryConfig in the daemon configuration [crates/palyra-common/src/daemon_config_schema.rs#183-190](http://crates/palyra-common/src/daemon_config_schema.rs#183-190).
| Constant / Config | Default Value | Description |
|---|---|---|
MAX_MEMORY_ITEM_BYTES | 16 KB | Maximum size of a single memory string [crates/palyra-daemon/src/gateway.rs#118](http://crates/palyra-daemon/src/gateway.rs#118). |
MAX_MEMORY_SEARCH_TOP_K | 64 | Maximum number of hits returned per query [crates/palyra-daemon/src/gateway.rs#117](http://crates/palyra-daemon/src/gateway.rs#117). |
auto_inject_max_items | 3 | Number of memory snippets injected into LLM context [crates/palyra-daemon/src/gateway/runtime.rs#141](http://crates/palyra-daemon/src/gateway/runtime.rs#141). |
retention_vacuum_schedule | 0 0 * * 0 | Cron expression for database vacuum (Weekly) [crates/palyra-daemon/src/gateway/runtime.rs#146](http://crates/palyra-daemon/src/gateway/runtime.rs#146). |
API and CLI Interface
Operators can manage knowledge via thepalyra memory command group [crates/palyra-cli/src/commands/memory.rs#4-14](http://crates/palyra-cli/src/commands/memory.rs#4-14).
- Search:
palyra memory search "query"triggersMemoryServiceClient::search_memory[crates/palyra-cli/src/commands/memory.rs#69-72](http://crates/palyra-cli/src/commands/memory.rs#69-72). - Recall: Simulates the auto-injection logic to show what the agent “sees” for a given prompt.
- Index: Manually triggers the embeddings backfill loop
[crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#143-150](http://crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#143-150).
crates/palyra-daemon/src/journal.rscrates/palyra-daemon/src/gateway.rscrates/palyra-daemon/src/gateway/runtime.rscrates/palyra-daemon/src/background_queue.rscrates/palyra-daemon/src/transport/http/handlers/console/memory.rscrates/palyra-cli/src/commands/memory.rscrates/palyra-common/src/daemon_config_schema.rs