Skip to content

[Feature] Pluggable persistent memory backend — self-hosted decay-weighted recall via Dakera #2974

Description

@ferhimedamine

Problem

Chainlit stores conversation messages in a database (via chainlit.data abstraction), but there's no semantic memory layer that persists what matters across conversations. Each new chat thread with the same user starts cold — the assistant has no recollection of prior interactions or user preferences unless the developer manually implements retrieval.

Two distinct needs:

  1. Within a session: Chainlit handles this well with message history
  2. Cross-session persistence: Storing semantic context so future conversations can recall relevant past interactions

Proposed: Dakera as a pluggable memory backend

Dakera is a self-hosted vector memory server with decay weighting — recent memories rank higher, stale ones fade naturally. It would plug into Chainlit's lifecycle hooks:

import chainlit as cl
from dakera import DakeraClient

memory = DakeraClient(base_url="http://localhost:3300", api_key="demo")

@cl.on_chat_start
async def on_start():
    user_id = cl.user_session.get("user").identifier
    # Inject up to 5 relevant memories from prior sessions
    history = memory.recall(agent_id=user_id, query="user preferences and context", top_k=5)
    if history.memories:
        context = "\n".join(f"- {m.content}" for m in history.memories)
        await cl.Message(content=f"**Recalled from prior sessions:**\n{context}").send()

@cl.on_message
async def on_message(message: cl.Message):
    user_id = cl.user_session.get("user").identifier
    
    # ... run your LLM logic ...
    response = run_llm(message.content)
    
    # Store the exchange in Dakera for future sessions
    memory.store_memory(
        agent_id=user_id,
        content=f"User: {message.content}\nAssistant: {response}",
        session_id=cl.context.session.id,
    )
    await cl.Message(content=response).send()

Why not just use Chainlit's data layer?

Chainlit's SQLAlchemyDataLayer stores raw conversation threads — great for audit/history. Dakera adds semantic recall: instead of replaying the last N messages, it surfaces the 5 most relevant past exchanges based on the current query, with temporal decay so stale context doesn't pollute new conversations.

Broader pattern

This could be exposed as a DakeraMemoryStore that implements Chainlit's BaseStorageClient or BaseDataLayer interface, allowing users to configure it via config.toml:

[project]
enable_telemetry = false

[memory]
backend = "dakera"
url = "http://localhost:3300"
api_key = "demo"

Setup

docker run -d -p 3300:3300 -e DAKERA_API_KEY=demo ghcr.io/dakera-ai/dakera:latest
pip install dakera

Fully self-hosted — no data leaves your infrastructure. Happy to prototype as a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendPertains to the Python backend.enhancementNew feature or request

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions