mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
delete observation repository
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Service for managing observations in both filesystem and database."""
|
||||
from pathlib import Path
|
||||
from typing import List, Sequence
|
||||
from typing import List, Sequence, Dict, Any
|
||||
from sqlalchemy import select
|
||||
|
||||
from basic_memory.models import Observation as ObservationModel
|
||||
@@ -9,8 +9,6 @@ from . import DatabaseSyncError
|
||||
from basic_memory.schemas import Observation
|
||||
|
||||
|
||||
#from basic_memory.schemas import Observation
|
||||
|
||||
class ObservationService:
|
||||
"""
|
||||
Service for managing observations in the database.
|
||||
@@ -37,6 +35,45 @@ class ObservationService:
|
||||
except Exception as e:
|
||||
raise DatabaseSyncError(f"Failed to add observations to database: {str(e)}") from e
|
||||
|
||||
async def delete_observations(self, entity_id: str, contents: List[str]) -> int:
|
||||
"""
|
||||
Delete specific observations from an entity.
|
||||
|
||||
Args:
|
||||
entity_id: ID of the entity
|
||||
contents: List of observation contents to delete
|
||||
|
||||
Returns:
|
||||
Number of observations deleted
|
||||
"""
|
||||
try:
|
||||
deleted = False
|
||||
for content in contents:
|
||||
result = await self.observation_repo.delete_by_fields(
|
||||
entity_id=entity_id,
|
||||
content=content
|
||||
)
|
||||
if result:
|
||||
deleted = True
|
||||
return deleted
|
||||
except Exception as e:
|
||||
raise DatabaseSyncError(f"Failed to delete observations from database: {str(e)}") from e
|
||||
|
||||
async def delete_by_entity(self, entity_id: str) -> bool:
|
||||
"""
|
||||
Delete all observations for an entity.
|
||||
|
||||
Args:
|
||||
entity_id: ID of the entity
|
||||
|
||||
Returns:
|
||||
True if any observations were deleted
|
||||
"""
|
||||
try:
|
||||
return await self.observation_repo.delete_by_fields(entity_id=entity_id)
|
||||
except Exception as e:
|
||||
raise DatabaseSyncError(f"Failed to delete observations from database: {str(e)}") from e
|
||||
|
||||
async def search_observations(self, query: str) -> List[ObservationModel]:
|
||||
"""
|
||||
Search for observations across all entities.
|
||||
|
||||
Reference in New Issue
Block a user