Skip to main content
Glama
AgentWong

Knowledge Graph Memory Server

by AgentWong

delete_entities

Remove 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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityNamesYesAn array of entity names to delete

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
        }
    ),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgentWong/optimized-memory-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server