Skip to content

Commit 5274970

Browse files
authoredApr 16, 2025··
reduce entity type attribute hallucinations (#365)
* reduce entity type attribute hallucinations * reduce entity type attribute hallucinations * reduce entity type attribute hallucinations * mypy fix * mypy fix * mypy fix
1 parent d951f4f commit 5274970

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed
 

‎graphiti_core/prompts/summarize_nodes.py

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def summarize_context(context: dict[str, Any]) -> list[Message]:
8989
9090
Guidelines:
9191
1. Do not hallucinate entity property values if they cannot be found in the current context.
92+
2. Only use the provided messages, entity, and entity context to set attribute values.
9293
9394
<ENTITY>
9495
{context['node_name']}

‎graphiti_core/utils/maintenance/node_operations.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import logging
1818
from contextlib import suppress
1919
from time import time
20+
from typing import Any
2021

2122
import pydantic
2223
from pydantic import BaseModel
@@ -324,16 +325,17 @@ async def resolve_extracted_node(
324325
else [],
325326
}
326327

327-
summary_context = {
328+
summary_context: dict[str, Any] = {
328329
'node_name': extracted_node.name,
329330
'node_summary': extracted_node.summary,
330331
'episode_content': episode.content if episode is not None else '',
331332
'previous_episodes': [ep.content for ep in previous_episodes]
332333
if previous_episodes is not None
333334
else [],
334-
'attributes': [],
335335
}
336336

337+
attributes: list[dict[str, str]] = []
338+
337339
entity_type_classes: tuple[BaseModel, ...] = tuple()
338340
if entity_types is not None: # type: ignore
339341
entity_type_classes = entity_type_classes + tuple(
@@ -344,8 +346,15 @@ async def resolve_extracted_node(
344346
)
345347

346348
for entity_type in entity_type_classes:
347-
for field_name in entity_type.model_fields:
348-
summary_context.get('attributes', []).append(field_name) # type: ignore
349+
for field_name, field_info in entity_type.model_fields.items():
350+
attributes.append(
351+
{
352+
'attribute_name': field_name,
353+
'attribute_description': field_info.description or '',
354+
}
355+
)
356+
357+
summary_context['attributes'] = attributes
349358

350359
entity_attributes_model = pydantic.create_model( # type: ignore
351360
'EntityAttributes',

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "graphiti-core"
33
description = "A temporal graph building library"
4-
version = "0.10.1"
4+
version = "0.10.2"
55
authors = [
66
{ "name" = "Paul Paliychuk", "email" = "paul@getzep.com" },
77
{ "name" = "Preston Rasmussen", "email" = "preston@getzep.com" },

0 commit comments

Comments
 (0)
Please sign in to comment.