Skip to content

Commit 8a78633

Browse files
danielchalefclaudeclaude[bot]
authored
Enforce shorter summaries with 8 sentence limit (#978)
* Enforce shorter summaries with 8 sentence limit Replace 250-word limit with 8 sentence limit for node summaries to improve conciseness. Also update prompt system message for summarize_context to better reflect its dual purpose of generating summaries and attributes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update graphiti_core/prompts/summarize_nodes.py Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> * Bump version to 0.22.0pre1 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update graphiti_core/prompts/summarize_nodes.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
1 parent 2864786 commit 8a78633

File tree

4 files changed

+61
-53
lines changed

4 files changed

+61
-53
lines changed

graphiti_core/prompts/extract_nodes.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,44 @@
2323

2424

2525
class ExtractedEntity(BaseModel):
26-
name: str = Field(..., description='Name of the extracted entity')
26+
name: str = Field(..., description="Name of the extracted entity")
2727
entity_type_id: int = Field(
28-
description='ID of the classified entity type. '
29-
'Must be one of the provided entity_type_id integers.',
28+
description="ID of the classified entity type. "
29+
"Must be one of the provided entity_type_id integers.",
3030
)
3131

3232

3333
class ExtractedEntities(BaseModel):
34-
extracted_entities: list[ExtractedEntity] = Field(..., description='List of extracted entities')
34+
extracted_entities: list[ExtractedEntity] = Field(
35+
..., description="List of extracted entities"
36+
)
3537

3638

3739
class MissedEntities(BaseModel):
38-
missed_entities: list[str] = Field(..., description="Names of entities that weren't extracted")
40+
missed_entities: list[str] = Field(
41+
..., description="Names of entities that weren't extracted"
42+
)
3943

4044

4145
class EntityClassificationTriple(BaseModel):
42-
uuid: str = Field(description='UUID of the entity')
43-
name: str = Field(description='Name of the entity')
46+
uuid: str = Field(description="UUID of the entity")
47+
name: str = Field(description="Name of the entity")
4448
entity_type: str | None = Field(
45-
default=None, description='Type of the entity. Must be one of the provided types or None'
49+
default=None,
50+
description="Type of the entity. Must be one of the provided types or None",
4651
)
4752

4853

4954
class EntityClassification(BaseModel):
5055
entity_classifications: list[EntityClassificationTriple] = Field(
51-
..., description='List of entities classification triples.'
56+
..., description="List of entities classification triples."
5257
)
5358

5459

5560
class EntitySummary(BaseModel):
5661
summary: str = Field(
5762
...,
58-
description='Summary containing the important information about the entity. Under 250 words',
63+
description="Summary containing the important information about the entity. Under 8 sentences.",
5964
)
6065

6166

@@ -123,8 +128,8 @@ def extract_message(context: dict[str, Any]) -> list[Message]:
123128
{context['custom_prompt']}
124129
"""
125130
return [
126-
Message(role='system', content=sys_prompt),
127-
Message(role='user', content=user_prompt),
131+
Message(role="system", content=sys_prompt),
132+
Message(role="user", content=user_prompt),
128133
]
129134

130135

@@ -156,8 +161,8 @@ def extract_json(context: dict[str, Any]) -> list[Message]:
156161
3. Do NOT extract any properties that contain dates
157162
"""
158163
return [
159-
Message(role='system', content=sys_prompt),
160-
Message(role='user', content=user_prompt),
164+
Message(role="system", content=sys_prompt),
165+
Message(role="user", content=user_prompt),
161166
]
162167

163168

@@ -187,8 +192,8 @@ def extract_text(context: dict[str, Any]) -> list[Message]:
187192
4. Be as explicit as possible in your node names, using full names and avoiding abbreviations.
188193
"""
189194
return [
190-
Message(role='system', content=sys_prompt),
191-
Message(role='user', content=user_prompt),
195+
Message(role="system", content=sys_prompt),
196+
Message(role="user", content=user_prompt),
192197
]
193198

194199

@@ -211,8 +216,8 @@ def reflexion(context: dict[str, Any]) -> list[Message]:
211216
extracted.
212217
"""
213218
return [
214-
Message(role='system', content=sys_prompt),
215-
Message(role='user', content=user_prompt),
219+
Message(role="system", content=sys_prompt),
220+
Message(role="user", content=user_prompt),
216221
]
217222

218223

@@ -243,19 +248,19 @@ def classify_nodes(context: dict[str, Any]) -> list[Message]:
243248
3. If none of the provided entity types accurately classify an extracted node, the type should be set to None
244249
"""
245250
return [
246-
Message(role='system', content=sys_prompt),
247-
Message(role='user', content=user_prompt),
251+
Message(role="system", content=sys_prompt),
252+
Message(role="user", content=user_prompt),
248253
]
249254

250255

251256
def extract_attributes(context: dict[str, Any]) -> list[Message]:
252257
return [
253258
Message(
254-
role='system',
255-
content='You are a helpful assistant that extracts entity properties from the provided text.',
259+
role="system",
260+
content="You are a helpful assistant that extracts entity properties from the provided text.",
256261
),
257262
Message(
258-
role='user',
263+
role="user",
259264
content=f"""
260265
261266
<MESSAGES>
@@ -281,11 +286,11 @@ def extract_attributes(context: dict[str, Any]) -> list[Message]:
281286
def extract_summary(context: dict[str, Any]) -> list[Message]:
282287
return [
283288
Message(
284-
role='system',
285-
content='You are a helpful assistant that extracts entity summaries from the provided text.',
289+
role="system",
290+
content="You are a helpful assistant that extracts entity summaries from the provided text.",
286291
),
287292
Message(
288-
role='user',
293+
role="user",
289294
content=f"""
290295
291296
<MESSAGES>
@@ -300,7 +305,7 @@ def extract_summary(context: dict[str, Any]) -> list[Message]:
300305
1. Do not hallucinate entity summary information if they cannot be found in the current context.
301306
2. Only use the provided MESSAGES and ENTITY to set attribute values.
302307
3. The summary attribute represents a summary of the ENTITY, and should be updated with new information about the Entity from the MESSAGES.
303-
Summaries must be no longer than 250 words.
308+
4. Keep the summary concise and to the point. SUMMARIES MUST BE LESS THAN 8 SENTENCES.
304309
305310
<ENTITY>
306311
{context['node']}
@@ -311,11 +316,11 @@ def extract_summary(context: dict[str, Any]) -> list[Message]:
311316

312317

313318
versions: Versions = {
314-
'extract_message': extract_message,
315-
'extract_json': extract_json,
316-
'extract_text': extract_text,
317-
'reflexion': reflexion,
318-
'extract_summary': extract_summary,
319-
'classify_nodes': classify_nodes,
320-
'extract_attributes': extract_attributes,
319+
"extract_message": extract_message,
320+
"extract_json": extract_json,
321+
"extract_text": extract_text,
322+
"reflexion": reflexion,
323+
"extract_summary": extract_summary,
324+
"classify_nodes": classify_nodes,
325+
"extract_attributes": extract_attributes,
321326
}

graphiti_core/prompts/summarize_nodes.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
class Summary(BaseModel):
2626
summary: str = Field(
2727
...,
28-
description='Summary containing the important information about the entity. Under 250 words',
28+
description="Summary containing the important information about the entity. Under 8 sentences",
2929
)
3030

3131

3232
class SummaryDescription(BaseModel):
33-
description: str = Field(..., description='One sentence description of the provided summary')
33+
description: str = Field(
34+
..., description="One sentence description of the provided summary"
35+
)
3436

3537

3638
class Prompt(Protocol):
@@ -48,15 +50,15 @@ class Versions(TypedDict):
4850
def summarize_pair(context: dict[str, Any]) -> list[Message]:
4951
return [
5052
Message(
51-
role='system',
52-
content='You are a helpful assistant that combines summaries.',
53+
role="system",
54+
content="You are a helpful assistant that combines summaries.",
5355
),
5456
Message(
55-
role='user',
57+
role="user",
5658
content=f"""
5759
Synthesize the information from the following two summaries into a single succinct summary.
5860
59-
Summaries must be under 250 words.
61+
IMPORTANT: Keep the summary concise and to the point. SUMMARIES MUST BE LESS THAN 8 SENTENCES.
6062
6163
Summaries:
6264
{to_prompt_json(context['node_summaries'], indent=2)}
@@ -68,11 +70,11 @@ def summarize_pair(context: dict[str, Any]) -> list[Message]:
6870
def summarize_context(context: dict[str, Any]) -> list[Message]:
6971
return [
7072
Message(
71-
role='system',
72-
content='You are a helpful assistant that extracts entity properties from the provided text.',
73+
role="system",
74+
content="You are a helpful assistant that generates a summary and attributes from provided text.",
7375
),
7476
Message(
75-
role='user',
77+
role="user",
7678
content=f"""
7779
7880
<MESSAGES>
@@ -82,14 +84,15 @@ def summarize_context(context: dict[str, Any]) -> list[Message]:
8284
8385
Given the above MESSAGES and the following ENTITY name, create a summary for the ENTITY. Your summary must only use
8486
information from the provided MESSAGES. Your summary should also only contain information relevant to the
85-
provided ENTITY. Summaries must be under 250 words.
87+
provided ENTITY.
8688
8789
In addition, extract any values for the provided entity properties based on their descriptions.
8890
If the value of the entity property cannot be found in the current context, set the value of the property to the Python value None.
8991
9092
Guidelines:
9193
1. Do not hallucinate entity property values if they cannot be found in the current context.
9294
2. Only use the provided messages, entity, and entity context to set attribute values.
95+
3. Keep the summary concise and to the point. SUMMARIES MUST BE LESS THAN 8 SENTENCES.
9396
9497
<ENTITY>
9598
{context['node_name']}
@@ -110,14 +113,14 @@ def summarize_context(context: dict[str, Any]) -> list[Message]:
110113
def summary_description(context: dict[str, Any]) -> list[Message]:
111114
return [
112115
Message(
113-
role='system',
114-
content='You are a helpful assistant that describes provided contents in a single sentence.',
116+
role="system",
117+
content="You are a helpful assistant that describes provided contents in a single sentence.",
115118
),
116119
Message(
117-
role='user',
120+
role="user",
118121
content=f"""
119122
Create a short one sentence description of the summary that explains what kind of information is summarized.
120-
Summaries must be under 250 words.
123+
Summaries must be under 8 sentences.
121124
122125
Summary:
123126
{to_prompt_json(context['summary'], indent=2)}
@@ -127,7 +130,7 @@ def summary_description(context: dict[str, Any]) -> list[Message]:
127130

128131

129132
versions: Versions = {
130-
'summarize_pair': summarize_pair,
131-
'summarize_context': summarize_context,
132-
'summary_description': summary_description,
133+
"summarize_pair": summarize_pair,
134+
"summarize_context": summarize_context,
135+
"summary_description": summary_description,
133136
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
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.22.0pre0"
4+
version = "0.22.0pre1"
55
authors = [
66
{ name = "Paul Paliychuk", email = "paul@getzep.com" },
77
{ name = "Preston Rasmussen", email = "preston@getzep.com" },

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)