Skip to content

BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.

feat: add CRUD support for entities and relationships

marcorasera540183480bc580
diff --git a/src/adapters/graph.py b/src/adapters/graph.py
index d6e94d1..0690328 100644
--- a/src/adapters/graph.py
+++ b/src/adapters/graph.py
@@ -3,7 +3,7 @@ File: /graph.py
Created Date: Sunday October 19th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Sunday October 19th 2025 8:59:28 am
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -132,12 +132,6 @@ class GraphAdapter:
"""
return self.graph.get_graph_relationships(brain_id)
- def get_graph_property_keys(self, brain_id: str = "default") -> list[str]:
- """
- Get the property keys of the graph.
- """
- return self.graph.get_graph_property_keys(brain_id)
-
def get_by_uuid(self, uuid: str, brain_id: str = "default") -> Node:
"""
Get a node by its UUID.
@@ -273,6 +267,69 @@ class GraphAdapter:
return self.graph.update_properties(
uuid, updating, brain_id, new_properties, properties_to_remove
)
+
+ def get_graph_relationship_types(self, brain_id: str = "default") -> list[str]:
+ """
+ Get all unique relationship types from the graph.
+ """
+ return self.graph.get_graph_relationship_types(brain_id)
+ def get_graph_node_types(self, brain_id: str = "default") -> list[str]:
+ """
+ Get all unique node types from the graph.
+ """
+ return self.graph.get_graph_node_types(brain_id)
+
+ def get_graph_node_properties(self, brain_id: str = "default") -> list[str]:
+ """
+ Get all unique property keys from nodes in the graph.
+ """
+ return self.graph.get_graph_node_properties(brain_id)
+
+ def add_entity(
+ self,
+ name: str,
+ brain_id: str = "default",
+ labels: list[str] = [],
+ description: Optional[str] = None,
+ properties: Optional[dict] = None,
+ identification_params: Optional[dict] = None,
+ metadata: Optional[dict] = None,
+ ) -> Node | None:
+ """
+ Add a single entity (node) to the graph.
+ """
+ return self.graph.add_entity(
+ name,
+ brain_id,
+ labels,
+ description,
+ properties,
+ identification_params,
+ metadata,
+ )
+
+ def update_entity(
+ self,
+ uuid: str,
+ brain_id: str = "default",
+ new_name: Optional[str] = None,
+ new_description: Optional[str] = None,
+ new_labels: Optional[list[str]] = None,
+ new_properties: Optional[dict] = None,
+ properties_to_remove: Optional[list[str]] = None,
+ ) -> Node | None:
+ """
+ Update an entity (node) in the graph.
+ """
+ return self.graph.update_entity(
+ uuid,
+ brain_id,
+ new_name,
+ new_description,
+ new_labels,
+ new_properties,
+ properties_to_remove,
+ )
_graph_adapter = GraphAdapter()
diff --git a/src/adapters/interfaces/graph.py b/src/adapters/interfaces/graph.py
index a4f514a..1eeed11 100644
--- a/src/adapters/interfaces/graph.py
+++ b/src/adapters/interfaces/graph.py
@@ -3,7 +3,7 @@ File: /graph.py
Created Date: Sunday October 19th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Sunday October 19th 2025 9:01:05 am
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -121,13 +121,6 @@ class GraphClient(ABC):
"""
raise NotImplementedError("get_graph_relationships method not implemented")
- @abstractmethod
- def get_graph_property_keys(self, brain_id: str) -> list[str]:
- """
- Get the property keys of the graph.
- """
- raise NotImplementedError("get_graph_property_keys method not implemented")
-
@abstractmethod
def get_by_uuid(
self,
@@ -272,3 +265,56 @@ class GraphClient(ABC):
Update the properties of a node or relationship in the graph.
"""
raise NotImplementedError("update_properties method not implemented")
+
+ @abstractmethod
+ def get_graph_relationship_types(self, brain_id: str) -> list[str]:
+ """
+ Get all unique relationship types from the graph.
+ """
+ raise NotImplementedError("get_graph_relationship_types method not implemented")
+
+ @abstractmethod
+ def get_graph_node_types(self, brain_id: str) -> list[str]:
+ """
+ Get all unique node types from the graph.
+ """
+ raise NotImplementedError("get_graph_node_types method not implemented")
+
+ @abstractmethod
+ def get_graph_node_properties(self, brain_id: str) -> list[str]:
+ """
+ Get all unique property keys from nodes in the graph.
+ """
+ raise NotImplementedError("get_graph_node_properties method not implemented")
+
+ @abstractmethod
+ def add_entity(
+ self,
+ name: str,
+ brain_id: str,
+ labels: list[str],
+ description: Optional[str] = None,
+ properties: Optional[dict] = None,
+ identification_params: Optional[dict] = None,
+ metadata: Optional[dict] = None,
+ ) -> Node | None:
+ """
+ Add a single entity (node) to the graph.
+ """
+ raise NotImplementedError("add_entity method not implemented")
+
+ @abstractmethod
+ def update_entity(
+ self,
+ uuid: str,
+ brain_id: str,
+ new_name: Optional[str] = None,
+ new_description: Optional[str] = None,
+ new_labels: Optional[list[str]] = None,
+ new_properties: Optional[dict] = None,
+ properties_to_remove: Optional[list[str]] = None,
+ ) -> Node | None:
+ """
+ Update an entity (node) in the graph.
+ """
+ raise NotImplementedError("update_entity method not implemented")
\ No newline at end of file
diff --git a/src/core/search/entities.py b/src/core/search/entities.py
index a4fcff0..e97f063 100644
--- a/src/core/search/entities.py
+++ b/src/core/search/entities.py
@@ -26,4 +26,4 @@ def search_entities(
result = graph_adapter.search_entities(
brain_id, limit, skip, node_labels, query_text
)
- return result
+ return result
\ No newline at end of file
diff --git a/src/core/search/relationships.py b/src/core/search/relationships.py
index eb9b2cd..f0bc70a 100644
--- a/src/core/search/relationships.py
+++ b/src/core/search/relationships.py
@@ -36,4 +36,4 @@ def search_relationships(
query_text,
query_search_target,
)
- return result
+ return result
\ No newline at end of file
diff --git a/src/lib/neo4j/client.py b/src/lib/neo4j/client.py
index cbf0ee6..8c052b0 100644
--- a/src/lib/neo4j/client.py
+++ b/src/lib/neo4j/client.py
@@ -3,7 +3,7 @@ File: /client.py
Created Date: Sunday October 19th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Sunday October 19th 2025 12:58:06 pm
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -463,18 +463,6 @@ class Neo4jClient(GraphClient):
properties=result.records[0].get("properties", {}) or {},
)
- def get_graph_property_keys(self, brain_id: str) -> list[str]:
- """
- Get the property keys of the graph.
- """
- cypher_query = """
- CALL db.propertyKeys() YIELD propertyKey
- RETURN propertyKey
- """
- self.ensure_database(brain_id)
- result = self.driver.execute_query(cypher_query, database_=brain_id)
- return [record["propertyKey"] for record in result.records]
-
def get_neighbors(
self, node: Node, limit: int, brain_id: str
) -> list[Tuple[Node, Predicate, Node]]:
@@ -1021,6 +1009,173 @@ class Neo4jClient(GraphClient):
direction=result.records[0].get("direction", "neutral"),
)
return None
+
+ def get_graph_relationship_types(self, brain_id: str) -> list[str]:
+ """
+ Get all unique relationship types from the graph.
+ """
+ cypher_query = """
+ CALL db.relationshipTypes() YIELD relationshipType
+ RETURN relationshipType
+ """
+ self.ensure_database(brain_id)
+ result = self.driver.execute_query(cypher_query, database_=brain_id)
+ return [record["relationshipType"] for record in result.records]
+
+ def get_graph_node_types(self, brain_id: str) -> list[str]:
+ """
+ Get all unique node types from the graph.
+ """
+ cypher_query = """
+ CALL db.labels() YIELD label
+ RETURN label
+ """
+ self.ensure_database(brain_id)
+ result = self.driver.execute_query(cypher_query, database_=brain_id)
+ return [record["label"] for record in result.records]
+
+ def get_graph_node_properties(self, brain_id: str) -> list[str]:
+ """
+ Get all unique property keys from nodes in the graph.
+ """
+ cypher_query = """
+ MATCH (n)
+ UNWIND keys(n) AS property
+ RETURN DISTINCT property
+ ORDER BY property
+ """
+ self.ensure_database(brain_id)
+ result = self.driver.execute_query(cypher_query, database_=brain_id)
+ return [record["property"] for record in result.records]
+
+ def add_entity(
+ self,
+ name: str,
+ brain_id: str,
+ labels: list[str],
+ description: Optional[str] = None,
+ properties: Optional[dict] = None,
+ identification_params: Optional[dict] = None,
+ metadata: Optional[dict] = None,
+ ) -> Node | None:
+ """
+ Add a single entity (node) to the graph.
+ """
+ import uuid as uuid_lib
+
+ node = Node(
+ uuid=str(uuid_lib.uuid4()),
+ name=name,
+ labels=labels,
+ description=description,
+ properties=properties or {},
+ )
+
+ result = self.add_nodes(
+ nodes=[node],
+ brain_id=brain_id,
+ identification_params=identification_params,
+ metadata=metadata,
+ )
+
+ if isinstance(result, list) and len(result) > 0:
+ return result[0]
+ return None
+
+ def update_entity(
+ self,
+ uuid: str,
+ brain_id: str,
+ new_name: Optional[str] = None,
+ new_description: Optional[str] = None,
+ new_labels: Optional[list[str]] = None,
+ new_properties: Optional[dict] = None,
+ properties_to_remove: Optional[list[str]] = None,
+ ) -> Node | None:
+ """
+ Update an entity (node) in the graph.
+ When new_properties is passed, it compares with existing properties:
+ - Adds new properties that don't exist
+ - Updates properties that have changed
+ - Keeps existing properties that aren't in new_properties
+ """
+ operations = []
+
+ existing_node = None
+ if new_properties:
+ existing_node = self.get_by_uuid(uuid, brain_id)
+ if not existing_node:
+ return None
+
+ if new_name:
+ operations.append(f"n.name = {self._format_value(new_name)}")
+
+ if new_description:
+ operations.append(f"n.description = {self._format_value(new_description)}")
+
+ if new_properties and existing_node:
+ existing_properties = existing_node.properties or {}
+
+ for property_key, new_value in new_properties.items():
+ existing_value = existing_properties.get(property_key)
+
+ if property_key not in existing_properties or existing_value != new_value:
+ cypher_key = self._format_property_key(property_key)
+ formatted_value = self._format_value(new_value)
+ operations.append(f"n.{cypher_key} = {formatted_value}")
+ elif new_properties:
+ for property_key, value in new_properties.items():
+ cypher_key = self._format_property_key(property_key)
+ formatted_value = self._format_value(value)
+ operations.append(f"n.{cypher_key} = {formatted_value}")
+
+ set_clause = f"SET {', '.join(operations)}" if operations else ""
+
+ remove_clause = ""
+ if properties_to_remove:
+ remove_operations = [
+ f"n.{self._format_property_key(prop)}"
+ for prop in properties_to_remove
+ ]
+ remove_clause = f"REMOVE {', '.join(remove_operations)}"
+
+ labels_clause = ""
+ if new_labels:
+ cleaned_labels = self._clean_labels(new_labels)
+ if existing_node:
+ current_labels = existing_node.labels or []
+ if current_labels:
+ cleaned_current = self._clean_labels(current_labels)
+ remove_labels = ", ".join([f"n:{label}" for label in cleaned_current])
+ labels_clause = f"REMOVE {remove_labels}\n"
+ labels_clause += f"SET n:{':'.join(cleaned_labels)}"
+
+ if not set_clause and not remove_clause and not labels_clause:
+ return existing_node if existing_node else self.get_by_uuid(uuid, brain_id)
+
+ cypher_query = f"""
+ MATCH (n)
+ WHERE n.uuid = '{uuid}'
+ {set_clause}
+ {remove_clause}
+ {labels_clause}
+ RETURN n.uuid as uuid, n.name as name, labels(n) as labels,
+ n.description as description, properties(n) as properties
+ """
+
+ self.ensure_database(brain_id)
+ result = self.driver.execute_query(cypher_query, database_=brain_id)
+
+ if result.records:
+ return Node(
+ uuid=result.records[0].get("uuid", "") or "",
+ name=result.records[0].get("name", "") or "",
+ labels=result.records[0].get("labels", []) or [],
+ description=result.records[0].get("description", "") or "",
+ properties=result.records[0].get("properties", {}) or {},
+ )
+
+ return None
_neo4j_client = Neo4jClient()
diff --git a/src/services/api/app.py b/src/services/api/app.py
index 7cf6e9a..b1520ae 100644
--- a/src/services/api/app.py
+++ b/src/services/api/app.py
@@ -3,7 +3,7 @@ File: /app.py
Created Date: Sunday October 19th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Sunday October 19th 2025 9:17:44 am
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -19,6 +19,7 @@ from src.services.api.middlewares.brains import BrainMiddleware
from src.services.api.routes.ingest import ingest_router
from src.services.api.routes.retrieve import retrieve_router
from src.services.api.routes.meta import meta_router
+from src.services.api.routes.model import model_router
from src.services.api.routes.system import system_router
from src.services.api.routes.tasks import tasks_router
@@ -38,6 +39,7 @@ app.add_middleware(
app.include_router(ingest_router)
app.include_router(retrieve_router)
app.include_router(meta_router)
+app.include_router(model_router)
app.include_router(system_router)
app.include_router(tasks_router)
diff --git a/src/services/api/constants/requests.py b/src/services/api/constants/requests.py
index 285703d..5309b27 100644
--- a/src/services/api/constants/requests.py
+++ b/src/services/api/constants/requests.py
@@ -3,7 +3,7 @@ File: /requests.py
Created Date: Monday October 20th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Monday October 20th 2025 7:29:39 pm
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -181,3 +181,41 @@ class CreateBrainRequest(BaseModel):
"""
brain_id: str
+
+class AddEntityRequest(BaseModel):
+ """Request model for adding a new entity to the graph."""
+ name: str
+ brain_id: str = "default"
+ labels: list[str] = []
+ description: Optional[str] = None
+ properties: Optional[dict] = None
+ identification_params: Optional[dict] = None
+ metadata: Optional[dict] = None
+
+
+class UpdateEntityRequest(BaseModel):
+ """Request model for updating an existing entity in the graph."""
+ uuid: str
+ brain_id: str = "default"
+ new_name: Optional[str] = None
+ new_description: Optional[str] = None
+ new_labels: Optional[list[str]] = None
+ new_properties: Optional[dict] = None
+ properties_to_remove: Optional[list[str]] = None
+
+
+class AddRelationshipRequest(BaseModel):
+ """Request model for adding a new relationship between two entities."""
+ subject_uuid: str
+ predicate_name: str
+ predicate_description: str
+ object_uuid: str
+ brain_id: str = "default"
+
+
+class UpdateRelationshipRequest(BaseModel):
+ """Request model for updating an existing relationship's properties."""
+ uuid: str
+ brain_id: str = "default"
+ new_properties: Optional[dict] = None
+ properties_to_remove: Optional[list[str]] = None
\ No newline at end of file
diff --git a/src/services/api/controllers/meta.py b/src/services/api/controllers/meta.py
index a64bc5e..00986b5 100644
--- a/src/services/api/controllers/meta.py
+++ b/src/services/api/controllers/meta.py
@@ -3,7 +3,7 @@ File: /meta.py
Created Date: Friday November 7th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Friday November 7th 2025 9:59:06 pm
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -12,9 +12,23 @@ import asyncio
from src.services.kg_agent.main import graph_adapter
-async def get_entity_properties():
+async def get_entities_labels(brain_id: str):
"""
Get the entity properties of the graph.
"""
- result = await asyncio.to_thread(graph_adapter.get_graph_property_keys, brain_id)
+ result = await asyncio.to_thread(graph_adapter.get_graph_node_types, brain_id)
return result
+
+async def get_relationships_properties(brain_id: str):
+ """
+ Get the entity properties of the graph.
+ """
+ result = await asyncio.to_thread(graph_adapter.get_graph_relationship_types, brain_id)
+ return result
+
+async def get_entity_properties(brain_id: str):
+ """
+ Get all unique property keys from entities in the graph.
+ """
+ result = await asyncio.to_thread(graph_adapter.get_graph_node_properties, brain_id)
+ return result
\ No newline at end of file
diff --git a/src/services/api/controllers/model.py b/src/services/api/controllers/model.py
new file mode 100644
index 0000000..8f61da0
--- /dev/null
+++ b/src/services/api/controllers/model.py
@@ -0,0 +1,129 @@
+"""
+File: /model.py
+Created Date: Saturday December 27th 2025
+Author: Christian Nonis <[email protected]>
+-----
+Last Modified: Saturday December 27th 2025
+Modified By: the developer formerly known as Christian Nonis at <[email protected]>
+-----
+"""
+
+import asyncio
+from typing import Optional
+from src.services.kg_agent.main import graph_adapter
+from src.constants.kg import Node, Predicate
+
+async def add_entity(
+ name: str,
+ brain_id: str,
+ labels: list[str],
+ description: Optional[str] = None,
+ properties: Optional[dict] = None,
+ identification_params: Optional[dict] = None,
+ metadata: Optional[dict] = None,
+) -> Node | None:
+ """
+ Add a single entity (node) to the graph.
+ """
+ result = await asyncio.to_thread(
+ graph_adapter.add_entity,
+ name=name,
+ brain_id=brain_id,
+ labels=labels,
+ description=description,
+ properties=properties,
+ identification_params=identification_params,
+ metadata=metadata,
+ )
+ return result
+
+
+async def update_entity(
+ uuid: str,
+ brain_id: str,
+ new_name: Optional[str] = None,
+ new_description: Optional[str] = None,
+ new_labels: Optional[list[str]] = None,
+ new_properties: Optional[dict] = None,
+ properties_to_remove: Optional[list[str]] = None,
+) -> Node | None:
+ """
+ Update an entity (node) in the graph.
+ """
+ result = await asyncio.to_thread(
+ graph_adapter.update_entity,
+ uuid=uuid,
+ brain_id=brain_id,
+ new_name=new_name,
+ new_description=new_description,
+ new_labels=new_labels,
+ new_properties=new_properties,
+ properties_to_remove=properties_to_remove,
+ )
+ return result
+
+
+async def add_relationship(
+ subject_uuid: str,
+ predicate_name: str,
+ predicate_description: str,
+ object_uuid: str,
+ brain_id: str,
+) -> str:
+ """
+ Add a relationship between two nodes in the graph.
+ """
+ subject_node = await asyncio.to_thread(
+ graph_adapter.get_by_uuid,
+ uuid=subject_uuid,
+ brain_id=brain_id,
+ )
+
+ object_node = await asyncio.to_thread(
+ graph_adapter.get_by_uuid,
+ uuid=object_uuid,
+ brain_id=brain_id,
+ )
+
+ if not subject_node:
+ raise ValueError(f"Subject node with UUID {subject_uuid} not found")
+
+ if not object_node:
+ raise ValueError(f"Object node with UUID {object_uuid} not found")
+
+ import uuid as uuid_lib
+ predicate = Predicate(
+ uuid=str(uuid_lib.uuid4()),
+ name=predicate_name,
+ description=predicate_description,
+ )
+
+ result = await asyncio.to_thread(
+ graph_adapter.add_relationship,
+ subject=subject_node,
+ predicate=predicate,
+ to_object=object_node,
+ brain_id=brain_id,
+ )
+
+ return result
+
+
+async def update_relationship(
+ uuid: str,
+ brain_id: str,
+ new_properties: dict,
+ properties_to_remove: list[str],
+) -> Predicate | None:
+ """
+ Update a relationship's properties in the graph.
+ """
+ result = await asyncio.to_thread(
+ graph_adapter.update_properties,
+ uuid=uuid,
+ updating="relationship",
+ brain_id=brain_id,
+ new_properties=new_properties,
+ properties_to_remove=properties_to_remove,
+ )
+ return result
\ No newline at end of file
diff --git a/src/services/api/controllers/retrieve.py b/src/services/api/controllers/retrieve.py
index 0dd7b24..b6f2325 100644
--- a/src/services/api/controllers/retrieve.py
+++ b/src/services/api/controllers/retrieve.py
@@ -3,7 +3,7 @@ File: /retrieve.py
Created Date: Sunday October 26th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Sunday October 26th 2025 4:03:07 pm
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -359,7 +359,6 @@ async def get_relationships(
}
)
-
async def get_entities(
limit: int = 10,
skip: int = 0,
@@ -380,4 +379,4 @@ async def get_entities(
"entities": [e.model_dump(mode="json") for e in entities.results],
"total": entities.total,
}
- )
+ )
\ No newline at end of file
diff --git a/src/services/api/routes/meta.py b/src/services/api/routes/meta.py
index e493df3..2051f35 100644
--- a/src/services/api/routes/meta.py
+++ b/src/services/api/routes/meta.py
@@ -3,7 +3,7 @@ File: /meta.py
Created Date: Friday November 7th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Friday November 7th 2025 9:58:46 pm
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -11,15 +11,36 @@ Modified By: the developer formerly known as Christian Nonis at <alch.infoemail@
from fastapi import APIRouter
from src.services.api.controllers.meta import (
+ get_entities_labels as get_entities_labels_controller,
+ get_relationships_properties as get_relationships_properties_controller,
get_entity_properties as get_entity_properties_controller,
)
meta_router = APIRouter(prefix="/meta", tags=["meta"])
+@meta_router.get(path="/relationships-properties")
+async def get_relationships_properties(
+ brain_id: str = "default",
+):
+ """
+ Get all unique relationship types from the graph.
+ """
+ return await get_relationships_properties_controller(brain_id)
+
+@meta_router.get(path="/entity-labels")
+async def get_entities_labels(
+ brain_id: str = "default",
+):
+ """
+ Get all unique node labels from the graph.
+ """
+ return await get_entities_labels_controller(brain_id)
@meta_router.get(path="/entity-properties")
-async def get_entity_properties():
+async def get_entity_properties(
+ brain_id: str = "default",
+):
"""
- Get the entity properties of the graph.
+ Get all unique property keys from entities in the graph.
"""
- return await get_entity_properties_controller()
+ return await get_entity_properties_controller(brain_id)
\ No newline at end of file
diff --git a/src/services/api/routes/model.py b/src/services/api/routes/model.py
new file mode 100644
index 0000000..42aab78
--- /dev/null
+++ b/src/services/api/routes/model.py
@@ -0,0 +1,79 @@
+"""
+File: /model.py
+Created Date: Saturday December 27th 2025
+Author: Christian Nonis <[email protected]>
+-----
+Last Modified: Saturday December 27th 2025
+Modified By: the developer formerly known as Christian Nonis at <[email protected]>
+-----
+"""
+
+from fastapi import APIRouter
+
+from src.services.api.constants.requests import AddEntityRequest, UpdateEntityRequest, AddRelationshipRequest, UpdateRelationshipRequest
+from src.services.api.controllers.model import (
+ add_entity as add_entity_controller,
+ update_entity as update_entity_controller,
+ add_relationship as add_relationship_controller,
+ update_relationship as update_relationship_controller,
+)
+
+model_router = APIRouter(prefix="/model", tags=["model"])
+
+
+@model_router.post(path="/entity")
+async def add_entity(request: AddEntityRequest):
+ """
+ Add a single entity (node) to the graph.
+ """
+ return await add_entity_controller(
+ name=request.name,
+ brain_id=request.brain_id,
+ labels=request.labels,
+ description=request.description,
+ properties=request.properties,
+ identification_params=request.identification_params,
+ metadata=request.metadata,
+ )
+
+
+@model_router.put(path="/entity")
+async def update_entity(request: UpdateEntityRequest):
+ """
+ Update an entity (node) in the graph.
+ """
+ return await update_entity_controller(
+ uuid=request.uuid,
+ brain_id=request.brain_id,
+ new_name=request.new_name,
+ new_description=request.new_description,
+ new_labels=request.new_labels,
+ new_properties=request.new_properties,
+ properties_to_remove=request.properties_to_remove,
+ )
+
+
+@model_router.post(path="/relationship")
+async def add_relationship(request: AddRelationshipRequest):
+ """
+ Add a relationship between two nodes in the graph.
+ """
+ return await add_relationship_controller(
+ subject_uuid=request.subject_uuid,
+ predicate_name=request.predicate_name,
+ predicate_description=request.predicate_description,
+ object_uuid=request.object_uuid,
+ brain_id=request.brain_id,
+ )
+
+@model_router.put(path="/relationship")
+async def update_relationship(request: UpdateRelationshipRequest):
+ """
+ Update a relationship's properties in the graph.
+ """
+ return await update_relationship_controller(
+ uuid=request.uuid,
+ brain_id=request.brain_id,
+ new_properties=request.new_properties or {},
+ properties_to_remove=request.properties_to_remove or [],
+ )
\ No newline at end of file
diff --git a/src/services/api/routes/retrieve.py b/src/services/api/routes/retrieve.py
index f60c427..7ea39cd 100644
--- a/src/services/api/routes/retrieve.py
+++ b/src/services/api/routes/retrieve.py
@@ -3,7 +3,7 @@ File: /retrieve.py
Created Date: Saturday October 25th 2025
Author: Christian Nonis <[email protected]>
-----
-Last Modified: Saturday December 13th 2025
+Last Modified: Saturday December 27th 2025
Modified By: the developer formerly known as Christian Nonis at <[email protected]>
-----
"""
@@ -23,7 +23,7 @@ from src.services.api.controllers.retrieve import (
get_entities as retrieve_get_entities_controller,
)
from src.services.api.controllers.retrieve import (
- retrieve_data as retrieve_data_controller,
+ retrieve_data as retrieve_data_controller
)
from src.services.api.controllers.structured_data import (
get_structured_data_by_id as get_structured_data_by_id_controller,
@@ -139,7 +139,6 @@ async def get_relationships(
query_search_target,
)
-
@retrieve_router.get(path="/entities")
async def get_entities(
limit: int = 10,