From 41984839932cca485350c0d4161507c29ac3d77d Mon Sep 17 00:00:00 2001 From: Preston Rasmussen <109292228+prasmussen15@users.noreply.github.com> Date: Mon, 12 May 2025 16:32:27 -0400 Subject: [PATCH] improve memory leak (#478) --- graphiti_core/search/search.py | 10 +++------- graphiti_core/utils/maintenance/node_operations.py | 6 +++--- pyproject.toml | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/graphiti_core/search/search.py b/graphiti_core/search/search.py index 7f8fc2d1..7460f1bb 100644 --- a/graphiti_core/search/search.py +++ b/graphiti_core/search/search.py @@ -458,14 +458,10 @@ async def community_search( config.mmr_lambda, ) elif config.reranker == CommunityReranker.cross_encoder: - summary_to_uuid_map = { - node.summary: node.uuid for result in search_results for node in result - } - reranked_summaries = await cross_encoder.rank(query, list(summary_to_uuid_map.keys())) + name_to_uuid_map = {node.name: node.uuid for result in search_results for node in result} + reranked_nodes = await cross_encoder.rank(query, list(name_to_uuid_map.keys())) reranked_uuids = [ - summary_to_uuid_map[fact] - for fact, score in reranked_summaries - if score >= reranker_min_score + name_to_uuid_map[name] for name, score in reranked_nodes if score >= reranker_min_score ] reranked_communities = [community_uuid_map[uuid] for uuid in reranked_uuids] diff --git a/graphiti_core/utils/maintenance/node_operations.py b/graphiti_core/utils/maintenance/node_operations.py index c1c378e7..f25746bb 100644 --- a/graphiti_core/utils/maintenance/node_operations.py +++ b/graphiti_core/utils/maintenance/node_operations.py @@ -18,6 +18,7 @@ import logging from contextlib import suppress from time import time from typing import Any +from uuid import uuid4 import pydantic from pydantic import BaseModel, Field @@ -395,7 +396,8 @@ async def extract_attributes_from_node( Field(description=field_info.description), ) - entity_attributes_model = pydantic.create_model('EntityAttributes', **attributes_definitions) + unique_model_name = f'EntityAttributes_{uuid4().hex}' + entity_attributes_model = pydantic.create_model(unique_model_name, **attributes_definitions) summary_context: dict[str, Any] = { 'node': node_context, @@ -411,12 +413,10 @@ async def extract_attributes_from_node( ) node.summary = llm_response.get('summary', node.summary) - node.name = llm_response.get('name', node.name) node_attributes = {key: value for key, value in llm_response.items()} with suppress(KeyError): del node_attributes['summary'] - del node_attributes['name'] node.attributes.update(node_attributes) diff --git a/pyproject.toml b/pyproject.toml index 4eca4a45..788f9631 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "graphiti-core" description = "A temporal graph building library" -version = "0.11.6pre6" +version = "0.11.6pre7" authors = [ { "name" = "Paul Paliychuk", "email" = "paul@getzep.com" }, { "name" = "Preston Rasmussen", "email" = "preston@getzep.com" },