{"record":{"id":"d841e60c7be346ed","repo":"mastra-ai/mastra","slug":"node-id-not-found","errorCode":null,"errorMessage":"Node ${id} not found","messagePattern":"Node (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/graph-rag/index.ts","lineNumber":176,"sourceCode":"      }\n    }\n\n    // Assign directly rather than via addEdge: the serialized edge list already\n    // contains both directions, and addEdge would add the reverse edge again.\n    graph.edges = (snapshot.edges ?? []).map(edge => ({ ...edge }));\n\n    return graph;\n  }\n\n  clear(): void {\n    this.nodes.clear();\n    this.edges = [];\n  }\n\n  updateNodeContent(id: string, newContent: string): void {\n    const node = this.nodes.get(id);\n    if (!node) {\n      throw new Error(`Node ${id} not found`);\n    }\n    node.content = newContent;\n  }\n\n  // Get neighbors of a node\n  private getNeighbors(nodeId: string, edgeType?: string): { id: string; weight: number }[] {\n    return this.edges\n      .filter(edge => edge.source === nodeId && (!edgeType || edge.type === edgeType))\n      .map(edge => ({\n        id: edge.target,\n        weight: edge.weight,\n      }))\n      .filter(node => node !== undefined);\n  }\n\n  // Calculate cosine similarity between two vectors\n  private cosineSimilarity(vec1: number[], vec2: number[]): number {\n    if (!vec1 || !vec2) {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/graph-rag/index.ts#L158-L194","documentation":"updateNodeContent(id, newContent) looks up the node by id in the internal Map and throws if it does not exist. Only the node's content is mutated; the embedding and edges stay as-is, so the id must reference a node created via addNode()/createGraph().","triggerScenarios":"Calling graph.updateNodeContent('some-id', text) with an id that was never added, an id computed with the wrong scheme (createGraph uses numeric string indices '0','1',...), or after clear() was called.","commonSituations":"Assuming ids are document/chunk identifiers when createGraph actually assigns index-based ids; using ids from a different GraphRAG instance; stale ids kept from before the graph was rebuilt from new chunks.","solutions":["Use the ids returned by getNodes() (e.g. node.id) rather than external document ids.","If you need stable ids, build the graph with addNode() supplying your own GraphNode.id instead of createGraph().","Check the node exists first with getNodes().some(n => n.id === id) before updating.","If the graph was cleared or rebuilt, refresh your stored id references."],"exampleFix":"// before\ngraph.updateNodeContent(docId, newText);\n// after\nconst node = graph.getNodes().find(n => n.metadata?.docId === docId);\nif (!node) throw new Error(`No graph node for document ${docId}`);\ngraph.updateNodeContent(node.id, newText);","handlingStrategy":"validation","validationCode":"const exists = graph.getNodes().some(n => n.id === id);\nif (!exists) throw new Error(`Node ${id} not in graph; known ids: ${graph.getNodes().map(n => n.id).slice(0, 5).join(',')}...`);","typeGuard":"const nodeExists = (graph: GraphRAG, id: string): boolean =>\n  graph.getNodes().some(n => n.id === id);","tryCatchPattern":"try {\n  graph.updateNodeContent(id, newContent);\n} catch (e) {\n  if ((e as Error).message === `Node ${id} not found`) {\n    // look up the correct node id via getNodes()/metadata before retrying\n  } else throw e;\n}","preventionTips":["Remember createGraph assigns index-string ids ('0','1',...), not document ids","Store custom ids in node.metadata and look them up via getNodes()","Use addNode() with explicit ids if you need stable identifiers","Refresh id references after clear() or rebuilding the graph"],"tags":["rag","missing-key","graph","argument-error"],"backgroundTag":"key-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}