delete_relations
Remove specific relations between entities in the DuckDB-based knowledge graph, ensuring accurate and up-to-date data for enhanced conversational memory and query performance.
Instructions
Delete multiple relations from the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes | An array of relations to delete |
Implementation Reference
- src/server.ts:150-155 (handler)The handler function for the 'delete_relations' MCP tool. It calls the knowledge graph manager to perform the deletion and returns a success message.async ({ relations }) => { await knowledgeGraphManager.deleteRelations(relations); return { content: [{ type: "text", text: "Relations deleted successfully" }], }; }
- src/server.ts:136-148 (schema)Zod input schema validating the 'relations' parameter as an array of objects with 'from', 'to', and 'relationType' fields.relations: z .array( z.object({ from: z .string() .describe("The name of the entity where the relation starts"), to: z .string() .describe("The name of the entity where the relation ends"), relationType: z.string().describe("The type of the relation"), }) ) .describe("An array of relations to delete"),
- src/server.ts:132-156 (registration)Registration of the 'delete_relations' tool using server.tool(), including name, description, schema, and handler function.server.tool( "delete_relations", "Delete multiple relations from the knowledge graph", { relations: z .array( z.object({ from: z .string() .describe("The name of the entity where the relation starts"), to: z .string() .describe("The name of the entity where the relation ends"), relationType: z.string().describe("The type of the relation"), }) ) .describe("An array of relations to delete"), }, async ({ relations }) => { await knowledgeGraphManager.deleteRelations(relations); return { content: [{ type: "text", text: "Relations deleted successfully" }], }; } );
- src/manager.ts:501-524 (helper)Core helper function in KnowledgeGraphManager that implements the deletion logic by executing SQL DELETE statements within a database transaction for each relation.async deleteRelations(relations: Relation[]): Promise<void> { using conn = await this.getConn(); try { // Begin transaction await conn.execute("BEGIN TRANSACTION"); // Delete each relation for (const relation of relations) { await conn.execute( "DELETE FROM relations WHERE from_entity = ? AND to_entity = ? AND relationType = ?", [relation.from, relation.to, relation.relationType] ); } // Commit transaction await conn.execute("COMMIT"); } catch (error: unknown) { // Rollback in case of error await conn.execute("ROLLBACK"); this.logger.error("Error deleting relations", extractError(error)); throw error; } }
- src/types.ts:20-29 (schema)TypeScript type definition and corresponding Zod schema for a 'Relation' object, used throughout the codebase for relation handling.export const RelationObject = z.object({ from: z.string().describe("The name of the entity where the relation starts"), to: z.string().describe("The name of the entity where the relation ends"), relationType: z.string().describe("The type of the relation"), }); export type Relation = { from: string; to: string; relationType: string; };