This commit is contained in:
phernandez
2024-12-28 14:31:28 -06:00
parent aa61ed0d96
commit 0d86bfeb7a
5 changed files with 30 additions and 15 deletions
+2 -2
View File
@@ -2,7 +2,7 @@
from basic_memory.markdown.knowledge_parser import KnowledgeParser
from basic_memory.markdown.schemas import (
Entity,
EntityMarkdown,
EntityContent,
EntityFrontmatter,
EntityMetadata,
@@ -12,7 +12,7 @@ from basic_memory.markdown.schemas import (
from basic_memory.utils.file_utils import ParseError
__all__ = [
"Entity",
"EntityMarkdown",
"EntityContent",
"EntityFrontmatter",
"EntityMetadata",
@@ -8,7 +8,7 @@ from loguru import logger
from basic_memory.markdown.base_parser import MarkdownParser, ParseError
from basic_memory.markdown.schemas import (
Entity,
EntityMarkdown,
EntityFrontmatter,
EntityContent,
EntityMetadata,
@@ -17,7 +17,7 @@ from basic_memory.markdown.schemas import (
)
class KnowledgeParser(MarkdownParser[Entity]):
class KnowledgeParser(MarkdownParser[EntityMarkdown]):
"""Parser for entity markdown files.
Entity files must have:
@@ -277,6 +277,6 @@ class KnowledgeParser(MarkdownParser[Entity]):
async def create_document(
self, frontmatter: EntityFrontmatter, content: EntityContent, metadata: EntityMetadata
) -> Entity:
) -> EntityMarkdown:
"""Create entity from parsed sections."""
return Entity(frontmatter=frontmatter, content=content, entity_metadata=metadata)
return EntityMarkdown(frontmatter=frontmatter, content=content, entity_metadata=metadata)
+1 -1
View File
@@ -50,7 +50,7 @@ class EntityMetadata(BaseModel):
data: Dict[str, Any] = {}
class Entity(BaseModel):
class EntityMarkdown(BaseModel):
"""Complete entity combining frontmatter, content, and metadata."""
frontmatter: EntityFrontmatter
@@ -1,7 +1,8 @@
from pathlib import Path
from basic_memory.markdown import KnowledgeParser
from basic_memory.services import FileChangeScanner, KnowledgeService
from basic_memory.markdown import KnowledgeParser, EntityMarkdown
from basic_memory.models.knowledge import Entity as EntityModel
from basic_memory.services import FileChangeScanner, KnowledgeService, EntityService
from basic_memory.services.sync.utils import FileState, SyncReport
@@ -9,17 +10,31 @@ class KnowledgeSyncService:
def __init__(
self,
scanner: FileChangeScanner,
knowledge_service: KnowledgeService,
entity_service: EntityService,
knowledge_parser: KnowledgeParser,
):
self.scanner = scanner
self.knowledge_service = knowledge_service
self.entity_service = entity_service
self.knowledge_parser = knowledge_parser
# async def markdown_to_entity_model(self, markdown_entity: EntityMarkdown) -> EntityModel:
# return EntityModel(
# name=markdown_entity.frontmatter.id,
# entity_type=markdown_entity.frontmatter.entity_type,
# path_id=markdown_entity.frontmatter.id,
# file_path=
# description=markdown_entity.content.description,
# checksum=
# created_at=
# updated_at=
# observations=
#
# )
async def sync_new_entity(self, directory: Path, path: str) -> None:
"""Handle syncing a new entity file."""
entity = await self.knowledge_parser.parse_file(directory / path)
await self.knowledge_service.create_entity(entity)
await self.entity_service.add(entity)
async def sync_modified_entity(self, directory: Path, path: str) -> None:
"""Handle syncing a modified entity file."""