mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix tests
This commit is contained in:
@@ -58,8 +58,6 @@ async def get_sync_service(db_type=DatabaseType.FILESYSTEM):
|
||||
file_change_scanner = FileChangeScanner(entity_repository)
|
||||
|
||||
# Initialize services
|
||||
entity_service = EntityService(entity_repository)
|
||||
|
||||
knowledge_sync_service = EntitySyncService(
|
||||
entity_repository, observation_repository, relation_repository
|
||||
)
|
||||
|
||||
@@ -150,10 +150,10 @@ RelationServiceDep = Annotated[RelationService, Depends(get_relation_service)]
|
||||
|
||||
|
||||
async def get_search_service(
|
||||
search_repository: SearchRepositoryDep, entity_service: EntityServiceDep
|
||||
search_repository: SearchRepositoryDep, entity_repository: EntityRepositoryDep
|
||||
) -> SearchService:
|
||||
"""Create SearchService with dependencies."""
|
||||
return SearchService(search_repository, entity_service)
|
||||
return SearchService(search_repository, entity_repository)
|
||||
|
||||
|
||||
SearchServiceDep = Annotated[SearchService, Depends(get_search_service)]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"""Service for search operations."""
|
||||
|
||||
from typing import List, Optional, Any
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import BackgroundTasks
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.models import Entity
|
||||
from basic_memory.repository import EntityRepository
|
||||
from basic_memory.repository.search_repository import SearchRepository
|
||||
from basic_memory.services.entity_service import EntityService
|
||||
from basic_memory.schemas.search import SearchQuery, SearchResult, SearchItemType
|
||||
|
||||
|
||||
@@ -17,45 +17,38 @@ class SearchService:
|
||||
def __init__(
|
||||
self,
|
||||
search_repository: SearchRepository,
|
||||
entity_service: EntityService,
|
||||
entity_repository: EntityRepository,
|
||||
):
|
||||
self.repository = search_repository
|
||||
self.entity_service = entity_service
|
||||
self.entity_repository = entity_repository
|
||||
|
||||
async def init_search_index(self):
|
||||
"""Create FTS5 virtual table if it doesn't exist."""
|
||||
await self.repository.init_search_index()
|
||||
|
||||
async def reindex_all(
|
||||
self,
|
||||
background_tasks: Optional[BackgroundTasks] = None
|
||||
) -> None:
|
||||
|
||||
async def reindex_all(self, background_tasks: Optional[BackgroundTasks] = None) -> None:
|
||||
"""Reindex all content from database."""
|
||||
logger.info("Starting full reindex")
|
||||
|
||||
|
||||
# Clear and recreate search index
|
||||
await self.init_search_index()
|
||||
|
||||
|
||||
# Reindex all entities
|
||||
logger.debug("Indexing entities")
|
||||
entities = await self.entity_service.get_all()
|
||||
entities = await self.entity_repository.find_all()
|
||||
for entity in entities:
|
||||
await self.index_entity(entity, background_tasks)
|
||||
|
||||
|
||||
logger.info("Reindex complete")
|
||||
|
||||
async def search(
|
||||
self,
|
||||
query: SearchQuery,
|
||||
context: Optional[List[str]] = None
|
||||
self, query: SearchQuery, context: Optional[List[str]] = None
|
||||
) -> List[SearchResult]:
|
||||
"""Search across all indexed content."""
|
||||
return await self.repository.search(query, context)
|
||||
|
||||
async def index_entity(
|
||||
self,
|
||||
entity: Entity,
|
||||
background_tasks: Optional[BackgroundTasks] = None
|
||||
self, entity: Entity, background_tasks: Optional[BackgroundTasks] = None
|
||||
) -> None:
|
||||
"""Index an entity and its components."""
|
||||
# Build searchable content
|
||||
@@ -99,22 +92,13 @@ class SearchService:
|
||||
)
|
||||
|
||||
async def _do_index(
|
||||
self,
|
||||
content: str,
|
||||
path_id: str,
|
||||
file_path: str,
|
||||
type: SearchItemType,
|
||||
metadata: dict
|
||||
self, content: str, path_id: str, file_path: str, type: SearchItemType, metadata: dict
|
||||
) -> None:
|
||||
"""Actually perform the indexing."""
|
||||
await self.repository.index_item(
|
||||
content=content,
|
||||
path_id=path_id,
|
||||
file_path=file_path,
|
||||
type=type,
|
||||
metadata=metadata
|
||||
content=content, path_id=path_id, file_path=file_path, type=type, metadata=metadata
|
||||
)
|
||||
|
||||
|
||||
async def delete_by_path_id(self, path_id: str):
|
||||
"""Delete an item from the search index."""
|
||||
await self.repository.delete_by_path_id(path_id)
|
||||
await self.repository.delete_by_path_id(path_id)
|
||||
|
||||
Reference in New Issue
Block a user