refactor entity.entity_type to be freeform, add summary and content_type

This commit is contained in:
phernandez
2025-01-07 19:00:08 -06:00
parent 5229641c61
commit 6686c331a5
12 changed files with 46 additions and 56 deletions
@@ -25,8 +25,8 @@ class KnowledgeWriter:
"", # Empty line after name
]
if entity.description:
sections.extend([entity.description, ""])
if entity.summary:
sections.extend([entity.summary, ""])
if entity.observations:
sections.extend(
+2 -2
View File
@@ -11,8 +11,8 @@ from basic_memory.config import config
from basic_memory.mcp.server import mcp
# Import tools to register them
from basic_memory.mcp.tools import knowledge, search, documents, discovery, help
__all__ = ["mcp", "knowledge", "search", "documents", "discovery", "help"]
from basic_memory.mcp.tools import knowledge, search, discovery, help
__all__ = ["mcp", "knowledge", "search", "discovery", "help"]
def setup_logging(home_dir: str = config.home, log_file: str = "basic-memory.log"):
+4 -14
View File
@@ -21,13 +21,6 @@ from basic_memory.models.base import Base
from enum import Enum
class EntityType(str, Enum):
"""Types of knowledge nodes."""
KNOWLEDGE = "knowledge"
NOTE = "note"
class Entity(Base):
"""
Core entity in the knowledge graph.
@@ -45,17 +38,14 @@ class Entity(Base):
Index("ix_entity_type", "entity_type"),
Index("ix_entity_created_at", "created_at"), # For timeline queries
Index("ix_entity_updated_at", "updated_at"), # For timeline queries
CheckConstraint(
f"entity_type IN {tuple(t.value for t in EntityType)}", name="check_entity_type"
),
)
# Core identity
id: Mapped[int] = mapped_column(Integer, primary_key=True)
name: Mapped[str] = mapped_column(String)
entity_type: Mapped[EntityType] = mapped_column(String, default=EntityType.KNOWLEDGE)
entity_type: Mapped[str] = mapped_column(String)
entity_metadata: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
content_type: Mapped[str] = mapped_column(String)
# Normalized path for URIs
path_id: Mapped[str] = mapped_column(String, unique=True, index=True)
@@ -64,8 +54,8 @@ class Entity(Base):
# checksum of file
checksum: Mapped[Optional[str]] = mapped_column(String, nullable=True)
# Content for knowledge entity_type
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
# Content summary
summary: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
# Metadata and tracking
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=text("CURRENT_TIMESTAMP"))
@@ -83,7 +83,7 @@ class EntityRepository(Repository[Entity]):
or_(
Entity.name.ilike(search_term),
Entity.entity_type.ilike(search_term),
Entity.description.ilike(search_term),
Entity.summary.ilike(search_term),
Entity.observations.any(Observation.content.ilike(search_term)),
)
)
@@ -97,7 +97,7 @@ class ActivityService:
timestamp=updated_at,
path_id=entity.path_id,
summary=f"{change_type.value.title()} entity: {entity.name}",
content=entity.description
content=entity.summary
)
)
@@ -60,7 +60,7 @@ class FileOperations:
frontmatter = await writer.format_frontmatter(entity)
file_content = await writer.format_content(
entity=entity,
content=content or entity.description or "",
content=content or entity.summary or "",
)
# Add frontmatter and write
+1 -1
View File
@@ -62,7 +62,7 @@ class SearchService:
content = "\n".join(
[
entity.name,
entity.description or "",
entity.summary or "",
# Add observations
*[f"{obs.category}: {obs.content}" for obs in entity.observations],
# Add relations
@@ -83,7 +83,7 @@ class KnowledgeSyncService:
# Update fields from markdown
db_entity.name = markdown.content.title
db_entity.entity_type = markdown.frontmatter.type
db_entity.description = markdown.content.description
db_entity.summary = markdown.content.description
# Clear and update observations
await self.observation_service.delete_by_entity(db_entity.id)
@@ -102,7 +102,7 @@ class KnowledgeSyncService:
{
"name": db_entity.name,
"entity_type": db_entity.entity_type,
"description": db_entity.description,
"description": db_entity.summary,
# Mark as incomplete
"checksum": None,
},