Delete Entities
delete_entitiesRemove entities and their relationships from a knowledge graph to maintain accurate memory storage by specifying which items to delete.
Instructions
Delete multiple entities and their associated relations from the knowledge graph
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"entityNames": "<entityNames>"
},
"name": "delete_entities"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityNames | Yes | An array of entity names to delete |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | ||
| success | Yes |
Implementation Reference
- The handler function that executes the logic to delete entities and their associated relations from the SQLite database.
async def delete_entities( self, entity_names: List[str], batch_size: int = 1000 ) -> None: """Remove entities and their relations.""" async with self.pool.get_connection() as conn: async with self.pool.transaction(conn): for i in range(0, len(entity_names), batch_size): batch = entity_names[i:i + batch_size] sanitized_names = [sanitize_input(name) for name in batch] placeholders = ','.join(['?' for _ in sanitized_names]) await conn.execute( f""" DELETE FROM relations WHERE from_entity IN ({placeholders}) OR to_entity IN ({placeholders}) """, sanitized_names * 2 ) await conn.execute( f"DELETE FROM entities WHERE name IN ({placeholders})", sanitized_names ) - The schema definition for the 'delete_entities' tool, specifying its expected input format.
name="delete_entities", description="Remove entities and their relations", inputSchema={ "type": "object", "properties": { "entityNames": { "type": "array", "items": {"type": "string"} } }, "required": ["entityNames"], "additionalProperties": False } ),