graphiti-core 0.22.0rc2__py3-none-any.whl → 0.22.0rc3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of graphiti-core might be problematic. Click here for more details.
- graphiti_core/prompts/extract_nodes.py +13 -13
- graphiti_core/utils/maintenance/node_operations.py +3 -2
- graphiti_core/utils/text_utils.py +53 -0
- {graphiti_core-0.22.0rc2.dist-info → graphiti_core-0.22.0rc3.dist-info}/METADATA +1 -1
- {graphiti_core-0.22.0rc2.dist-info → graphiti_core-0.22.0rc3.dist-info}/RECORD +7 -6
- {graphiti_core-0.22.0rc2.dist-info → graphiti_core-0.22.0rc3.dist-info}/WHEEL +0 -0
- {graphiti_core-0.22.0rc2.dist-info → graphiti_core-0.22.0rc3.dist-info}/licenses/LICENSE +0 -0
|
@@ -18,6 +18,8 @@ from typing import Any, Protocol, TypedDict
|
|
|
18
18
|
|
|
19
19
|
from pydantic import BaseModel, Field
|
|
20
20
|
|
|
21
|
+
from graphiti_core.utils.text_utils import MAX_SUMMARY_CHARS
|
|
22
|
+
|
|
21
23
|
from .models import Message, PromptFunction, PromptVersion
|
|
22
24
|
from .prompt_helpers import to_prompt_json
|
|
23
25
|
from .snippets import summary_instructions
|
|
@@ -57,7 +59,7 @@ class EntityClassification(BaseModel):
|
|
|
57
59
|
class EntitySummary(BaseModel):
|
|
58
60
|
summary: str = Field(
|
|
59
61
|
...,
|
|
60
|
-
description='Summary containing the important information about the entity. Under
|
|
62
|
+
description=f'Summary containing the important information about the entity. Under {MAX_SUMMARY_CHARS} characters.',
|
|
61
63
|
)
|
|
62
64
|
|
|
63
65
|
|
|
@@ -259,18 +261,17 @@ def extract_attributes(context: dict[str, Any]) -> list[Message]:
|
|
|
259
261
|
Message(
|
|
260
262
|
role='user',
|
|
261
263
|
content=f"""
|
|
262
|
-
|
|
263
|
-
<MESSAGES>
|
|
264
|
-
{to_prompt_json(context['previous_episodes'], indent=2)}
|
|
265
|
-
{to_prompt_json(context['episode_content'], indent=2)}
|
|
266
|
-
</MESSAGES>
|
|
267
|
-
|
|
268
|
-
Given the above MESSAGES and the following ENTITY, update any of its attributes based on the information provided
|
|
264
|
+
Given the MESSAGES and the following ENTITY, update any of its attributes based on the information provided
|
|
269
265
|
in MESSAGES. Use the provided attribute descriptions to better understand how each attribute should be determined.
|
|
270
266
|
|
|
271
267
|
Guidelines:
|
|
272
268
|
1. Do not hallucinate entity property values if they cannot be found in the current context.
|
|
273
269
|
2. Only use the provided MESSAGES and ENTITY to set attribute values.
|
|
270
|
+
|
|
271
|
+
<MESSAGES>
|
|
272
|
+
{to_prompt_json(context['previous_episodes'], indent=2)}
|
|
273
|
+
{to_prompt_json(context['episode_content'], indent=2)}
|
|
274
|
+
</MESSAGES>
|
|
274
275
|
|
|
275
276
|
<ENTITY>
|
|
276
277
|
{context['node']}
|
|
@@ -289,17 +290,16 @@ def extract_summary(context: dict[str, Any]) -> list[Message]:
|
|
|
289
290
|
Message(
|
|
290
291
|
role='user',
|
|
291
292
|
content=f"""
|
|
293
|
+
Given the MESSAGES and the ENTITY, update the summary that combines relevant information about the entity
|
|
294
|
+
from the messages and relevant information from the existing summary.
|
|
295
|
+
|
|
296
|
+
{summary_instructions}
|
|
292
297
|
|
|
293
298
|
<MESSAGES>
|
|
294
299
|
{to_prompt_json(context['previous_episodes'], indent=2)}
|
|
295
300
|
{to_prompt_json(context['episode_content'], indent=2)}
|
|
296
301
|
</MESSAGES>
|
|
297
302
|
|
|
298
|
-
Given the above MESSAGES and the following ENTITY, update the summary that combines relevant information about the entity
|
|
299
|
-
from the messages and relevant information from the existing summary.
|
|
300
|
-
|
|
301
|
-
{summary_instructions}
|
|
302
|
-
|
|
303
303
|
<ENTITY>
|
|
304
304
|
{context['node']}
|
|
305
305
|
</ENTITY>
|
|
@@ -53,6 +53,7 @@ from graphiti_core.utils.maintenance.dedup_helpers import (
|
|
|
53
53
|
from graphiti_core.utils.maintenance.edge_operations import (
|
|
54
54
|
filter_existing_duplicate_of_edges,
|
|
55
55
|
)
|
|
56
|
+
from graphiti_core.utils.text_utils import MAX_SUMMARY_CHARS, truncate_at_sentence
|
|
56
57
|
|
|
57
58
|
logger = logging.getLogger(__name__)
|
|
58
59
|
|
|
@@ -547,7 +548,7 @@ async def _extract_entity_summary(
|
|
|
547
548
|
summary_context = _build_episode_context(
|
|
548
549
|
node_data={
|
|
549
550
|
'name': node.name,
|
|
550
|
-
'summary': node.summary,
|
|
551
|
+
'summary': truncate_at_sentence(node.summary, MAX_SUMMARY_CHARS),
|
|
551
552
|
'entity_types': node.labels,
|
|
552
553
|
'attributes': node.attributes,
|
|
553
554
|
},
|
|
@@ -562,7 +563,7 @@ async def _extract_entity_summary(
|
|
|
562
563
|
group_id=node.group_id,
|
|
563
564
|
)
|
|
564
565
|
|
|
565
|
-
node.summary = summary_response.get('summary', '')
|
|
566
|
+
node.summary = truncate_at_sentence(summary_response.get('summary', ''), MAX_SUMMARY_CHARS)
|
|
566
567
|
|
|
567
568
|
|
|
568
569
|
def _build_episode_context(
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright 2024, Zep Software, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
|
|
19
|
+
# Maximum length for entity/node summaries
|
|
20
|
+
MAX_SUMMARY_CHARS = 250
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def truncate_at_sentence(text: str, max_chars: int) -> str:
|
|
24
|
+
"""
|
|
25
|
+
Truncate text at or about max_chars while respecting sentence boundaries.
|
|
26
|
+
|
|
27
|
+
Attempts to truncate at the last complete sentence before max_chars.
|
|
28
|
+
If no sentence boundary is found before max_chars, truncates at max_chars.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
text: The text to truncate
|
|
32
|
+
max_chars: Maximum number of characters
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Truncated text
|
|
36
|
+
"""
|
|
37
|
+
if not text or len(text) <= max_chars:
|
|
38
|
+
return text
|
|
39
|
+
|
|
40
|
+
# Find all sentence boundaries (., !, ?) up to max_chars
|
|
41
|
+
truncated = text[:max_chars]
|
|
42
|
+
|
|
43
|
+
# Look for sentence boundaries: period, exclamation, or question mark followed by space or end
|
|
44
|
+
sentence_pattern = r'[.!?](?:\s|$)'
|
|
45
|
+
matches = list(re.finditer(sentence_pattern, truncated))
|
|
46
|
+
|
|
47
|
+
if matches:
|
|
48
|
+
# Truncate at the last sentence boundary found
|
|
49
|
+
last_match = matches[-1]
|
|
50
|
+
return text[: last_match.end()].rstrip()
|
|
51
|
+
|
|
52
|
+
# No sentence boundary found, truncate at max_chars
|
|
53
|
+
return truncated.rstrip()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphiti-core
|
|
3
|
-
Version: 0.22.
|
|
3
|
+
Version: 0.22.0rc3
|
|
4
4
|
Summary: A temporal graph building library
|
|
5
5
|
Project-URL: Homepage, https://help.getzep.com/graphiti/graphiti/overview
|
|
6
6
|
Project-URL: Repository, https://github.com/getzep/graphiti
|
|
@@ -48,7 +48,7 @@ graphiti_core/prompts/dedupe_nodes.py,sha256=YNNo19Cq8koLVoLCafpjYJOy5nmRZ-tEWhv
|
|
|
48
48
|
graphiti_core/prompts/eval.py,sha256=GWFkfZoPfY8U7mV8Ngd_5a2S2fHS7KjajChntxv1UEY,5360
|
|
49
49
|
graphiti_core/prompts/extract_edge_dates.py,sha256=3Drs3CmvP0gJN5BidWSxrNvLet3HPoTybU3BUIAoc0Y,4218
|
|
50
50
|
graphiti_core/prompts/extract_edges.py,sha256=-yOIvCPwxIAXeqYpNCzouE6i3WfdsexzRXFmcXpQpAg,7113
|
|
51
|
-
graphiti_core/prompts/extract_nodes.py,sha256=
|
|
51
|
+
graphiti_core/prompts/extract_nodes.py,sha256=13aHEC26yUUcbR_xWgpvMSE8CT6HZK28AO8G0j2i8mU,11017
|
|
52
52
|
graphiti_core/prompts/invalidate_edges.py,sha256=yfpcs_pyctnoM77ULPZXEtKW0oHr1MeLsJzC5yrE-o4,3547
|
|
53
53
|
graphiti_core/prompts/lib.py,sha256=DCyHePM4_q-CptTpEXGO_dBv9k7xDtclEaB1dGu7EcI,4092
|
|
54
54
|
graphiti_core/prompts/models.py,sha256=NgxdbPHJpBEcpbXovKyScgpBc73Q-GIW-CBDlBtDjto,894
|
|
@@ -67,16 +67,17 @@ graphiti_core/telemetry/telemetry.py,sha256=47LrzOVBCcZxsYPsnSxWFiztHoxYKKxPwyRX
|
|
|
67
67
|
graphiti_core/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
68
68
|
graphiti_core/utils/bulk_utils.py,sha256=YpVs5olzrAWVd8pIQ8xi1Ql_IsPdbVSahV1JPuwmG4o,20308
|
|
69
69
|
graphiti_core/utils/datetime_utils.py,sha256=J-zYSq7-H-2n9hYOXNIun12kM10vNX9mMATGR_egTmY,1806
|
|
70
|
+
graphiti_core/utils/text_utils.py,sha256=Pth1vkrcHLfBnsPLmoc_F3BtOC73nrDwOIno4g_AF8M,1687
|
|
70
71
|
graphiti_core/utils/maintenance/__init__.py,sha256=vW4H1KyapTl-OOz578uZABYcpND4wPx3Vt6aAPaXh78,301
|
|
71
72
|
graphiti_core/utils/maintenance/community_operations.py,sha256=3IMxfOacZAYtZKebyYtWJYNZPLOPlS8Il-lzitEkoos,10681
|
|
72
73
|
graphiti_core/utils/maintenance/dedup_helpers.py,sha256=B7k6KkB6Sii8PZCWNNTvsNiy4BNTNWpoLeGgrPLq6BE,9220
|
|
73
74
|
graphiti_core/utils/maintenance/edge_operations.py,sha256=1hlcJRFnxthGkSr07QyDcOVug7N8dQj5aIENJ17JrpA,26564
|
|
74
75
|
graphiti_core/utils/maintenance/graph_data_operations.py,sha256=42icj3S_ELAJ-NK3jVS_rg_243dmnaZOyUitJj_uJ-M,6085
|
|
75
|
-
graphiti_core/utils/maintenance/node_operations.py,sha256=
|
|
76
|
+
graphiti_core/utils/maintenance/node_operations.py,sha256=R_vf68kwyutUjD919Mmay4liZdrqJdWoAKm-Ci_2eco,19768
|
|
76
77
|
graphiti_core/utils/maintenance/temporal_operations.py,sha256=wq1I4kqeIoswit6sPohug91FEwrGaVnJ06g1vkJjSLY,3442
|
|
77
78
|
graphiti_core/utils/maintenance/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
79
|
graphiti_core/utils/ontology_utils/entity_types_utils.py,sha256=4eVgxLWY6Q8k9cRJ5pW59IYF--U4nXZsZIGOVb_yHfQ,1285
|
|
79
|
-
graphiti_core-0.22.
|
|
80
|
-
graphiti_core-0.22.
|
|
81
|
-
graphiti_core-0.22.
|
|
82
|
-
graphiti_core-0.22.
|
|
80
|
+
graphiti_core-0.22.0rc3.dist-info/METADATA,sha256=WjL-foq_wxjcF75gBbEssSsEFNQT-3zA-GihbhtU8pk,27084
|
|
81
|
+
graphiti_core-0.22.0rc3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
82
|
+
graphiti_core-0.22.0rc3.dist-info/licenses/LICENSE,sha256=KCUwCyDXuVEgmDWkozHyniRyWjnWUWjkuDHfU6o3JlA,11325
|
|
83
|
+
graphiti_core-0.22.0rc3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|