File size: 1,452 Bytes
85b19cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Abstract memory adapter API for eval baselines."""

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any

from eval_framework.datasets.schemas import (
    MemoryDeltaRecord,
    MemorySnapshotRecord,
    NormalizedTurn,
    RetrievalRecord,
)


class MemoryAdapter(ABC):
    """Baseline-agnostic adapter surface used by the eval pipeline."""

    @abstractmethod
    def reset(self) -> None:
        """Clear backend state and any adapter-side bookkeeping."""

    @abstractmethod
    def ingest_turn(self, turn: NormalizedTurn) -> None:
        """Feed one conversation turn into the memory system."""

    @abstractmethod
    def end_session(self, session_id: str) -> None:
        """Notify the adapter that a session boundary was reached (optional for many backends)."""

    @abstractmethod
    def snapshot_memories(self) -> list[MemorySnapshotRecord]:
        """Return a normalized view of memories observable in the backend."""

    @abstractmethod
    def export_memory_delta(self, session_id: str) -> list[MemoryDeltaRecord]:
        """Export memory changes for the given session since the last call."""

    @abstractmethod
    def retrieve(self, query: str, top_k: int) -> RetrievalRecord:
        """Run retrieval and normalize results."""

    @abstractmethod
    def get_capabilities(self) -> dict[str, Any]:
        """Describe adapter behavior limits (deltas, snapshots, backend id)."""