Index
diapason.memory
¶
Native persistent long-term memory for Diapason.
This package provides the automatic memory service that extracts durable facts
from conversations in the background and persists them across sessions. It is
started and stopped as part of the diapason serve / diapason chat lifecycle
and configured via the [memory] section of config.toml.
Fact
dataclass
¶
A single durable memory entry.
FactExtractor
¶
Extract memory-worthy facts from a conversation turn via an engine.
extract(user_text, assistant_text='')
¶
Return durable facts from the exchange. Never raises.
FactStore
¶
Bases: ABC
Abstract persistent store for extracted memory facts.
add(text, source='')
abstractmethod
¶
Store text as a fact. Returns True if a new fact was stored.
add_many(texts, source='')
¶
Store several facts, returning the count of newly stored ones.
clear()
abstractmethod
¶
Remove all stored facts, returning the number removed.
count()
abstractmethod
¶
Return the number of stored facts.
list()
abstractmethod
¶
Return all stored facts, oldest first.
LocalFactStore
¶
Bases: FactStore
Append-only JSONL fact store on the local filesystem.
Facts are kept human-readable (one JSON object per line) so they can be
inspected or edited by hand. Writes are atomic (temp file + rename) and
guarded by a lock, so concurrent add calls from the extraction worker
and list/clear from the CLI never corrupt the file.
path
property
¶
Filesystem location of the JSONL store.
MemoryService
¶
Background long-term-memory extraction and persistence service.
start()
¶
Start the background worker thread (idempotent).
stop(timeout=2.0)
¶
Stop pending admission; finish an already sent call, then join.
submit(user_text, assistant_text='')
¶
Queue an exchange for extraction. Non-blocking; never raises.
Returns True if the job was enqueued, False if the service is not running or the queue is full (in which case the exchange is dropped rather than blocking the caller — extraction is best-effort).
build_memory_service(config, engine, default_model='', *, event_bus=None, memory_backend=None)
¶
Build a :class:MemoryService from config, or None if disabled.
Reads the [memory] section (config.memory / config.tools.storage)
for enabled, backend, extraction_model, max_facts and
facts_path. Returns None when memory is disabled or no engine /
extraction model is available, so callers can simply do::
svc = build_memory_service(config, engine, model)
if svc is not None:
svc.start()
create_fact_store(backend='local', *, path=None, max_facts=1000)
¶
Construct a fact store for the configured backend.
Only the "local" (on-disk JSONL) backend is supported today; the
registry-backed constructor exists so additional backends can be added
without changing the service or CLI wiring.
publish_completed_exchange(bus, user_text, assistant_text='', *, source='')
¶
Publish a completed chat exchange for lifecycle subscribers.