diff --git a/cognee/infrastructure/databases/cache/cache_db_interface.py b/cognee/infrastructure/databases/cache/cache_db_interface.py index a70b3fc9c..f98103ea4 100644 --- a/cognee/infrastructure/databases/cache/cache_db_interface.py +++ b/cognee/infrastructure/databases/cache/cache_db_interface.py @@ -40,3 +40,40 @@ class CacheDBInterface(ABC): yield finally: self.release() + + @abstractmethod + async def add_qa( + self, + user_id: str, + session_id: str, + question: str, + context: str, + answer: str, + ttl: int | None = 86400, + ): + """ + Add a Q/A/context triplet to a cache session. + """ + + pass + + @abstractmethod + async def get_latest_qa(self, user_id: str, session_id: str, last_n: int = 10): + """ + Retrieve the most recent Q/A/context triplets for a session. + """ + pass + + @abstractmethod + async def get_all_qas(self, user_id: str, session_id: str): + """ + Retrieve all Q/A/context triplets for the given session. + """ + pass + + @abstractmethod + async def close(self): + """ + Gracefully close any async connections. + """ + pass diff --git a/cognee/infrastructure/databases/cache/get_cache_engine.py b/cognee/infrastructure/databases/cache/get_cache_engine.py index 1d22b3e30..c1fa3311c 100644 --- a/cognee/infrastructure/databases/cache/get_cache_engine.py +++ b/cognee/infrastructure/databases/cache/get_cache_engine.py @@ -1,8 +1,8 @@ """Factory to get the appropriate cache coordination engine (e.g., Redis).""" from functools import lru_cache +from typing import Optional from cognee.infrastructure.databases.cache.config import get_cache_config - from cognee.infrastructure.databases.cache.cache_db_interface import CacheDBInterface config = get_cache_config() @@ -51,7 +51,7 @@ def create_cache_engine( return None -def get_cache_engine(lock_key: str) -> CacheDBInterface: +def get_cache_engine(lock_key: Optional[str] = None) -> CacheDBInterface: """ Returns a cache adapter instance using current context configuration. """