Skip to content

service

diapason.memory.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.

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()

publish_completed_exchange(bus, user_text, assistant_text='', *, source='')

Publish a completed chat exchange for lifecycle subscribers.