Spaces:
Running
Running
File size: 858 Bytes
0e38162 | 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 | from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional
class BaseMemory(ABC):
"""Abstract base for all memory backends."""
@abstractmethod
async def store(self, key: str, value: Any, metadata: Optional[Dict] = None) -> None:
"""Persist a value under a key."""
@abstractmethod
async def retrieve(self, key: str) -> Optional[Any]:
"""Fetch a value by exact key."""
@abstractmethod
async def search(self, query: str, k: int = 5) -> List[Dict[str, Any]]:
"""Semantic or keyword search; return top-k results with scores."""
@abstractmethod
async def delete(self, key: str) -> None:
"""Remove a key from memory."""
@abstractmethod
async def clear(self, scope: Optional[str] = None) -> None:
"""Clear memory, optionally scoped to a job/session."""
|