mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
add index_document to search_service.py
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from basic_memory.repository.search_repository import SearchRepository
|
||||
from basic_memory.schemas.search import SearchQuery, SearchResult
|
||||
from basic_memory.schemas.search import SearchQuery, SearchResult, SearchItemType
|
||||
|
||||
|
||||
class SearchService:
|
||||
@@ -52,7 +52,7 @@ class SearchService:
|
||||
content=content,
|
||||
path_id=entity.path_id,
|
||||
file_path=entity.file_path,
|
||||
type="entity",
|
||||
type=SearchItemType.ENTITY,
|
||||
metadata=metadata,
|
||||
)
|
||||
else:
|
||||
@@ -60,10 +60,37 @@ class SearchService:
|
||||
content=content,
|
||||
path_id=entity.path_id,
|
||||
file_path=entity.file_path,
|
||||
type="entity",
|
||||
type=SearchItemType.ENTITY,
|
||||
metadata=metadata,
|
||||
)
|
||||
|
||||
async def index_document(self, document, content: str, background_tasks=None):
|
||||
"""Index a document and its content."""
|
||||
metadata = {
|
||||
**document.doc_metadata,
|
||||
"created_at": document.created_at.isoformat(),
|
||||
"updated_at": document.updated_at.isoformat(),
|
||||
}
|
||||
|
||||
# Queue indexing if background_tasks provided
|
||||
if background_tasks:
|
||||
background_tasks.add_task(
|
||||
self._do_index,
|
||||
content=content,
|
||||
path_id=document.path_id,
|
||||
file_path=document.file_path,
|
||||
type=SearchItemType.DOCUMENT,
|
||||
metadata=metadata,
|
||||
)
|
||||
else:
|
||||
await self._do_index(
|
||||
content=content,
|
||||
path_id=document.path_id,
|
||||
file_path=document.file_path,
|
||||
type=SearchItemType.DOCUMENT,
|
||||
metadata=metadata,
|
||||
)
|
||||
|
||||
async def _do_index(self, **kwargs):
|
||||
"""Actually perform the indexing."""
|
||||
await self.repository.index_item(**kwargs)
|
||||
await self.repository.index_item(**kwargs)
|
||||
Reference in New Issue
Block a user