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
This commit is contained in:
Preston Rasmussen 2025-04-16 19:09:25 -04:00 committed by GitHub
parent d951f4fc14
commit 5274970be3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 5 deletions

View file

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

View file

@ -17,6 +17,7 @@ limitations under the License.
import logging
from contextlib import suppress
from time import time
from typing import Any
import pydantic
from pydantic import BaseModel
@ -324,16 +325,17 @@ async def resolve_extracted_node(
else [],
}
summary_context = {
summary_context: dict[str, Any] = {
'node_name': extracted_node.name,
'node_summary': extracted_node.summary,
'episode_content': episode.content if episode is not None else '',
'previous_episodes': [ep.content for ep in previous_episodes]
if previous_episodes is not None
else [],
'attributes': [],
}
attributes: list[dict[str, str]] = []
entity_type_classes: tuple[BaseModel, ...] = tuple()
if entity_types is not None: # type: ignore
entity_type_classes = entity_type_classes + tuple(
@ -344,8 +346,15 @@ async def resolve_extracted_node(
)
for entity_type in entity_type_classes:
for field_name in entity_type.model_fields:
summary_context.get('attributes', []).append(field_name) # type: ignore
for field_name, field_info in entity_type.model_fields.items():
attributes.append(
{
'attribute_name': field_name,
'attribute_description': field_info.description or '',
}
)
summary_context['attributes'] = attributes
entity_attributes_model = pydantic.create_model( # type: ignore
'EntityAttributes',

View file

@ -1,7 +1,7 @@
[project]
name = "graphiti-core"
description = "A temporal graph building library"
version = "0.10.1"
version = "0.10.2"
authors = [
{ "name" = "Paul Paliychuk", "email" = "paul@getzep.com" },
{ "name" = "Preston Rasmussen", "email" = "preston@getzep.com" },