service
service
¶
Persistent memory service: async fact extraction integrated into core.
MemoryService runs fact extraction on a dedicated background thread so it
never blocks diapason serve request handling or the diapason chat REPL.
Callers hand off an exchange via :meth:submit, which enqueues the work and
returns immediately — the slow model call and disk write happen out of band.
Ollama admission defers memory while an interactive turn is running. A
background thread alone does not prevent competition for the same GPU.
The worker swallows every per-job error (including BrokenPipeError when a
client disconnects mid-extraction), so a flaky extraction model can never take
down the host process.
The service is started and stopped as part of the Diapason lifecycle (see
cli/serve.py and cli/chat_cmd.py) and is configured through the
[memory] section of config.toml.
Classes¶
MemoryService
¶
MemoryService(
store: FactStore,
extractor: FactExtractor,
*,
event_bus: EventBus | None = None,
max_queue: int = 256,
)
Background long-term-memory extraction and persistence service.
Source code in src/diapason/memory/service.py
Methods:¶
start
¶
Start the background worker thread (idempotent).
Source code in src/diapason/memory/service.py
stop
¶
Stop pending admission; finish an already sent call, then join.
Source code in src/diapason/memory/service.py
submit
¶
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).
Source code in src/diapason/memory/service.py
Functions:¶
build_memory_service
¶
build_memory_service(
config: Any,
engine: Any,
default_model: str = "",
*,
event_bus: EventBus | None = None,
memory_backend: Any = None,
) -> Optional[MemoryService]
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()
Source code in src/diapason/memory/service.py
publish_completed_exchange
¶
publish_completed_exchange(
bus: EventBus | None,
user_text: str,
assistant_text: str = "",
*,
source: str = "",
) -> bool
Publish a completed chat exchange for lifecycle subscribers.