Skip to content

Commit b0d0f82

Browse files
79475432@qq.comclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 7eb3e1c commit b0d0f82

File tree

1 file changed

+7
-7
lines changed
  • backend/app/rag/retrievers/knowledge_graph

1 file changed

+7
-7
lines changed

backend/app/rag/retrievers/knowledge_graph/schema.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ def retrieve_knowledge_graph(self, query_str: str) -> KnowledgeGraphRetrievalRes
197197
{relationships_str}
198198
"""
199199
DEFAULT_ENTITY_TMPL = """
200-
- Name: {{ name }}
201-
Description: {{ description }}
200+
- Name: {name}
201+
Description: {description}
202202
"""
203203
DEFAULT_RELATIONSHIP_TMPL = """
204-
- Description: {{ rag_description }}
205-
Weight: {{ weight }}
206-
Last Modified At: {{ last_modified_at }}
207-
Meta: {{ meta }}
204+
- Description: {rag_description}
205+
Weight: {weight}
206+
Last Modified At: {last_modified_at}
207+
Meta: {meta}
208208
"""
209209

210210

@@ -283,7 +283,7 @@ def _get_relationships_str(self) -> str:
283283
strs = []
284284
for relationship in self.relationships:
285285
strs.append(
286-
self.entity_template.format(
286+
self.relationship_template.format(
287287
rag_description=relationship.rag_description,
288288
weight=relationship.weight,
289289
last_modified_at=relationship.last_modified_at,

0 commit comments

Comments
 (0)