LemonMemory. Store
(lemon_memory v0.1.0)
View Source
Durable store for normalized memory documents, isolated from RunHistoryStore.
Uses its own SQLite database (memory.sqlite3) so that large conversation
payloads in run history never block memory reads, and so that memory can be
managed independently (retention, erasure by scope).
Memory documents are compact, indexed summaries of finalized runs. They are intended to support full-text search (M5-02) and routing feedback analytics (M6).
Configuration
config :lemon_memory, LemonMemory.Store,
path: "~/.lemon/store", # directory — memory.sqlite3 created inside
retention_ms: 30 * 24 * 3600_000, # 30 days (default)
max_per_scope: 500 # max documents per scope keySchema
The memory_documents table stores one row per memory document. FTS support
(M5-02) will add a virtual memory_fts table over prompt_summary and
answer_summary.
Summary
Functions
Returns a specification to start this module under a supervisor.
Delete all documents for an agent scope.
Delete all documents for a session scope.
Delete all documents for a workspace scope.
Fetch the limit most recent documents for an agent across all sessions.
Fetch the limit most recent documents for a session.
Fetch the limit most recent documents for a workspace.
Synchronously enforce retention and max-per-scope limits.
Persist a Document. This is a cast — write failures are logged but
do not propagate to the caller.
Full-text search over prompt_summary and answer_summary.
Returns aggregate stats: total count, oldest/newest ingestion timestamps.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec delete_by_agent(binary()) :: :ok
Delete all documents for an agent scope.
@spec delete_by_agent(GenServer.server(), binary()) :: :ok
@spec delete_by_session(binary()) :: :ok
Delete all documents for a session scope.
@spec delete_by_session(GenServer.server(), binary()) :: :ok
@spec delete_by_workspace(binary()) :: :ok
Delete all documents for a workspace scope.
@spec delete_by_workspace(GenServer.server(), binary()) :: :ok
@spec get_by_agent( binary(), keyword() ) :: [LemonMemory.Document.t()]
Fetch the limit most recent documents for an agent across all sessions.
@spec get_by_agent(GenServer.server(), binary(), keyword()) :: [ LemonMemory.Document.t() ]
@spec get_by_session( binary(), keyword() ) :: [LemonMemory.Document.t()]
Fetch the limit most recent documents for a session.
@spec get_by_session(GenServer.server(), binary(), keyword()) :: [ LemonMemory.Document.t() ]
@spec get_by_workspace( binary(), keyword() ) :: [LemonMemory.Document.t()]
Fetch the limit most recent documents for a workspace.
@spec get_by_workspace(GenServer.server(), binary(), keyword()) :: [ LemonMemory.Document.t() ]
Synchronously enforce retention and max-per-scope limits.
Deletes documents older than retention_ms and trims any session that
exceeds max_per_scope documents (keeping the most recent ones).
Returns {:ok, %{swept: integer(), pruned: integer()}}.
@spec prune(GenServer.server()) :: {:ok, map()} | {:error, term()}
@spec put(LemonMemory.Document.t()) :: :ok
Persist a Document. This is a cast — write failures are logged but
do not propagate to the caller.
@spec put(GenServer.server(), LemonMemory.Document.t()) :: :ok
@spec search( binary(), keyword() ) :: [LemonMemory.Document.t()]
Full-text search over prompt_summary and answer_summary.
Options
:scope-:session(default),:agent,:workspace,:all:scope_key- session_key / agent_id / workspace_key (required if scope !=:all):limit- max results (default 5)
@spec search(GenServer.server(), binary(), keyword()) :: [LemonMemory.Document.t()]
@spec stats() :: map()
Returns aggregate stats: total count, oldest/newest ingestion timestamps.
@spec stats(GenServer.server()) :: map()