feat: adds base class level methods

This commit is contained in:
hajdul88 2025-10-15 17:46:51 +02:00
parent e7fe66470a
commit 2b23455431
2 changed files with 39 additions and 2 deletions

View file

@ -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

View file

@ -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.
"""