mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
use path_id instead of entity_id everywhere
This commit is contained in:
@@ -56,9 +56,9 @@ async def add_observations(
|
||||
data: AddObservationsRequest, knowledge_service: KnowledgeServiceDep
|
||||
) -> EntityResponse:
|
||||
"""Add observations to an entity."""
|
||||
logger.debug(f"Adding observations to entity: {data.entity_id}")
|
||||
logger.debug(f"Adding observations to entity: {data.path_id}")
|
||||
updated_entity = await knowledge_service.add_observations(
|
||||
data.entity_id, data.observations, data.context
|
||||
data.path_id, data.observations, data.context
|
||||
)
|
||||
return EntityResponse.model_validate(updated_entity)
|
||||
|
||||
@@ -93,7 +93,7 @@ async def search_nodes(
|
||||
@router.post("/nodes", response_model=EntityListResponse)
|
||||
async def open_nodes(data: OpenNodesRequest, entity_service: EntityServiceDep) -> EntityListResponse:
|
||||
"""Open specific nodes by their names."""
|
||||
entities = await entity_service.open_nodes(data.entity_ids)
|
||||
entities = await entity_service.open_nodes(data.path_ids)
|
||||
return EntityListResponse(
|
||||
entities=[EntityResponse.model_validate(entity) for entity in entities]
|
||||
)
|
||||
@@ -107,7 +107,7 @@ async def delete_entity(
|
||||
data: DeleteEntitiesRequest, knowledge_service: KnowledgeServiceDep
|
||||
) -> DeleteEntitiesResponse:
|
||||
"""Delete a specific entity by PathId."""
|
||||
deleted = await knowledge_service.delete_entities(data.entity_ids)
|
||||
deleted = await knowledge_service.delete_entities(data.path_ids)
|
||||
return DeleteEntitiesResponse(deleted=deleted)
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ async def delete_observations(
|
||||
data: DeleteObservationsRequest, knowledge_service: KnowledgeServiceDep
|
||||
) -> EntityResponse:
|
||||
"""Delete observations from an entity."""
|
||||
path_id = data.entity_id
|
||||
path_id = data.path_id
|
||||
updated_entity = await knowledge_service.delete_observations(path_id, data.deletions)
|
||||
return EntityResponse.model_validate(updated_entity)
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def init_db(
|
||||
db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
try:
|
||||
async with engine_session_factory(path, db_type=DatabaseType.FILESYSTEM, init=True):
|
||||
async with engine_session_factory(db_path, db_type=DatabaseType.FILESYSTEM, init=True):
|
||||
typer.echo(f"Initialized database at {db_path}")
|
||||
except Exception as e:
|
||||
typer.echo(f"Error initializing database: {e}")
|
||||
|
||||
@@ -65,14 +65,6 @@ def validate_path_format(path: str) -> str:
|
||||
if not path or not isinstance(path, str):
|
||||
raise ValueError("Path must be a non-empty string")
|
||||
|
||||
parts = path.split('/')
|
||||
if len(parts) != 2:
|
||||
raise ValueError("Path must be in format: type/name")
|
||||
|
||||
type_part, name_part = parts
|
||||
if not type_part or not name_part:
|
||||
raise ValueError("Both type and name must be non-empty")
|
||||
|
||||
return path
|
||||
|
||||
PathId = Annotated[str, BeforeValidator(to_snake_case), BeforeValidator(validate_path_format)]
|
||||
|
||||
@@ -35,7 +35,7 @@ class DeleteEntitiesRequest(BaseModel):
|
||||
|
||||
Example Request:
|
||||
{
|
||||
"entity_ids": [
|
||||
"path_ids": [
|
||||
"component/deprecated_service",
|
||||
"document/outdated_spec"
|
||||
]
|
||||
@@ -56,7 +56,7 @@ class DeleteEntitiesRequest(BaseModel):
|
||||
5. Create relations to replacement entities if applicable
|
||||
"""
|
||||
|
||||
entity_ids: Annotated[List[PathId], MinLen(1)]
|
||||
path_ids: Annotated[List[PathId], MinLen(1)]
|
||||
|
||||
|
||||
class DeleteRelationsRequest(BaseModel):
|
||||
@@ -104,7 +104,7 @@ class DeleteObservationsRequest(BaseModel):
|
||||
|
||||
Example Request:
|
||||
{
|
||||
"entity_id": "component/memory_service",
|
||||
"path_id": "component/memory_service",
|
||||
"deletions": [
|
||||
"Old implementation uses Python 3.8",
|
||||
"Depends on deprecated module"
|
||||
@@ -132,5 +132,5 @@ class DeleteObservationsRequest(BaseModel):
|
||||
5. Updating implementation details
|
||||
"""
|
||||
|
||||
entity_id: PathId
|
||||
path_id: PathId
|
||||
deletions: Annotated[List[Observation], MinLen(1)]
|
||||
|
||||
@@ -19,7 +19,7 @@ class AddObservationsRequest(BaseModel):
|
||||
|
||||
1. Adding implementation details:
|
||||
{
|
||||
"entity_id": "component/memory_service",
|
||||
"path_id": "component/memory_service",
|
||||
"observations": [
|
||||
"Added support for async operations",
|
||||
"Improved error handling with custom exceptions",
|
||||
@@ -29,7 +29,7 @@ class AddObservationsRequest(BaseModel):
|
||||
|
||||
2. Documenting a decision:
|
||||
{
|
||||
"entity_id": "decision/db_schema_design",
|
||||
"path_id": "decision/db_schema_design",
|
||||
"observations": [
|
||||
"Chose SQLite for local-first storage",
|
||||
"Added support for full-text search via FTS5",
|
||||
@@ -45,7 +45,7 @@ class AddObservationsRequest(BaseModel):
|
||||
4. Add observations in logical groups for better history tracking
|
||||
"""
|
||||
|
||||
entity_id: PathId
|
||||
path_id: PathId
|
||||
context: Optional[str] = None
|
||||
observations: List[Observation]
|
||||
|
||||
@@ -135,7 +135,7 @@ class OpenNodesRequest(BaseModel):
|
||||
|
||||
Example Request:
|
||||
{
|
||||
"entity_ids": [
|
||||
"path_ids": [
|
||||
"component/memory_service",
|
||||
"document/api_spec",
|
||||
"test/memory_service_test"
|
||||
@@ -152,7 +152,7 @@ class OpenNodesRequest(BaseModel):
|
||||
relations between entities that interest you.
|
||||
"""
|
||||
|
||||
entity_ids: Annotated[List[PathId], MinLen(1)]
|
||||
path_ids: Annotated[List[PathId], MinLen(1)]
|
||||
|
||||
|
||||
class CreateRelationsRequest(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user