From b0d0f82cf3ecaacb7d5514763d02aeeebd33b331 Mon Sep 17 00:00:00 2001 From: "79475432@qq.com" Date: Fri, 27 Mar 2026 16:59:34 +0800 Subject: [PATCH] fix: resolve KnowledgeGraphNode hash collision due to template rendering bugs Two bugs in KnowledgeGraphNode caused hash/get_content to ignore actual entity and relationship data, producing identical outputs for completely different knowledge graph nodes. Bug 1: Templates used Jinja2 double-brace syntax ({{ name }}) but were rendered with Python str.format(), which treats {{ as literal {. All format kwargs were silently ignored. Bug 2: _get_relationships_str() used self.entity_template instead of self.relationship_template, so relationship data never reached the output. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../app/rag/retrievers/knowledge_graph/schema.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/app/rag/retrievers/knowledge_graph/schema.py b/backend/app/rag/retrievers/knowledge_graph/schema.py index a11638bc6..5cf0cf362 100644 --- a/backend/app/rag/retrievers/knowledge_graph/schema.py +++ b/backend/app/rag/retrievers/knowledge_graph/schema.py @@ -197,14 +197,14 @@ def retrieve_knowledge_graph(self, query_str: str) -> KnowledgeGraphRetrievalRes {relationships_str} """ DEFAULT_ENTITY_TMPL = """ -- Name: {{ name }} - Description: {{ description }} +- Name: {name} + Description: {description} """ DEFAULT_RELATIONSHIP_TMPL = """ -- Description: {{ rag_description }} - Weight: {{ weight }} - Last Modified At: {{ last_modified_at }} - Meta: {{ meta }} +- Description: {rag_description} + Weight: {weight} + Last Modified At: {last_modified_at} + Meta: {meta} """ @@ -283,7 +283,7 @@ def _get_relationships_str(self) -> str: strs = [] for relationship in self.relationships: strs.append( - self.entity_template.format( + self.relationship_template.format( rag_description=relationship.rag_description, weight=relationship.weight, last_modified_at=relationship.last_modified_at,