mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
refactor entity.entity_type to be freeform, add summary and content_type
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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"):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user