delete_relations
Remove specified relationships between entities from the knowledge graph to maintain accurate semantic connections in code indexing systems.
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
- The primary handler for the 'delete_relations' tool. Validates the input arguments and calls the knowledge graph manager to delete the specified relations.export const deleteRelationsHandler: ToolHandler = async (args) => { if (!args.relations || !Array.isArray(args.relations)) { throw new Error("The 'relations' parameter is required and must be an array"); } // Valider chaque relation for (const relation of args.relations) { if (!relation.from || typeof relation.from !== 'string') { throw new Error("Each relation must have a 'from' string property"); } if (!relation.to || typeof relation.to !== 'string') { throw new Error("Each relation must have a 'to' string property"); } if (!relation.relationType || typeof relation.relationType !== 'string') { throw new Error("Each relation must have a 'relationType' string property"); } } try { await knowledgeGraphManager.deleteRelations(args.relations); return { content: [{ type: "text", text: "Relations deleted successfully" }] }; } catch (error) { console.error("Error in delete_relations tool:", error); throw error; } };
- Input schema definition for the 'delete_relations' tool, specifying the structure of the 'relations' array parameter.export const deleteRelationsTool: ToolDefinition = { name: "delete_relations", description: "Delete multiple relations from the knowledge graph", inputSchema: { type: "object", properties: { relations: { type: "array", items: { type: "object", properties: { from: { type: "string", description: "The name of the entity where the relation starts" }, to: { type: "string", description: "The name of the entity where the relation ends" }, relationType: { type: "string", description: "The type of the relation" }, }, required: ["from", "to", "relationType"], }, description: "An array of relations to delete" }, }, required: ["relations"], }, };
- Core helper method in KnowledgeGraphManager that performs the actual deletion of relations from the in-memory graph and persists to file.async deleteRelations(relations: RelationInput[]): Promise<void> { const graph = await this.loadGraph(); graph.relations = graph.relations.filter(r => !relations.some(delRelation => r.from === delRelation.from && r.to === delRelation.to && r.relationType === delRelation.relationType )); await this.saveGraph(graph); }
- src/core/registry.ts:262-282 (registration)The getExpectedTools function lists 'delete_relations' among the expected tools for verification after auto-registration.export function getExpectedTools(): string[] { return [ // Outils Graph (9 outils) 'create_entities', 'create_relations', 'add_observations', 'delete_entities', 'delete_observations', 'delete_relations', 'read_graph', 'search_nodes', 'open_nodes', // Outils RAG (5 outils - avec injection_rag comme outil principal) 'injection_rag', // Nouvel outil principal 'index_project', // Alias déprécié (rétrocompatibilité) 'search_code', 'manage_projects', 'update_project' ]; }
- build/tools/graph-tools.js:190-192 (handler)Alternative inline handler logic for 'delete_relations' in the combined graph tools executor switch statement.case "delete_relations": await knowledgeGraphManager.deleteRelations(args.relations); return { content: [{ type: "text", text: "Relations deleted successfully" }] };