graphiti-core 0.21.0rc13__py3-none-any.whl → 0.22.0__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/driver/driver.py +4 -211
- graphiti_core/driver/falkordb_driver.py +31 -3
- graphiti_core/driver/graph_operations/graph_operations.py +195 -0
- graphiti_core/driver/neo4j_driver.py +0 -49
- graphiti_core/driver/neptune_driver.py +43 -26
- graphiti_core/driver/search_interface/__init__.py +0 -0
- graphiti_core/driver/search_interface/search_interface.py +89 -0
- graphiti_core/edges.py +11 -34
- graphiti_core/graphiti.py +459 -326
- graphiti_core/graphiti_types.py +2 -0
- graphiti_core/llm_client/anthropic_client.py +64 -45
- graphiti_core/llm_client/client.py +67 -19
- graphiti_core/llm_client/gemini_client.py +73 -54
- graphiti_core/llm_client/openai_base_client.py +65 -43
- graphiti_core/llm_client/openai_generic_client.py +65 -43
- graphiti_core/models/edges/edge_db_queries.py +1 -0
- graphiti_core/models/nodes/node_db_queries.py +1 -0
- graphiti_core/nodes.py +26 -99
- graphiti_core/prompts/dedupe_edges.py +4 -4
- graphiti_core/prompts/dedupe_nodes.py +10 -10
- graphiti_core/prompts/extract_edges.py +4 -4
- graphiti_core/prompts/extract_nodes.py +26 -28
- graphiti_core/prompts/prompt_helpers.py +18 -2
- graphiti_core/prompts/snippets.py +29 -0
- graphiti_core/prompts/summarize_nodes.py +22 -24
- graphiti_core/search/search_filters.py +0 -38
- graphiti_core/search/search_helpers.py +4 -4
- graphiti_core/search/search_utils.py +84 -220
- graphiti_core/tracer.py +193 -0
- graphiti_core/utils/bulk_utils.py +16 -28
- graphiti_core/utils/maintenance/community_operations.py +4 -1
- graphiti_core/utils/maintenance/edge_operations.py +26 -15
- graphiti_core/utils/maintenance/graph_data_operations.py +6 -25
- graphiti_core/utils/maintenance/node_operations.py +98 -51
- graphiti_core/utils/maintenance/temporal_operations.py +4 -1
- graphiti_core/utils/text_utils.py +53 -0
- {graphiti_core-0.21.0rc13.dist-info → graphiti_core-0.22.0.dist-info}/METADATA +7 -3
- {graphiti_core-0.21.0rc13.dist-info → graphiti_core-0.22.0.dist-info}/RECORD +41 -35
- /graphiti_core/{utils/maintenance/utils.py → driver/graph_operations/__init__.py} +0 -0
- {graphiti_core-0.21.0rc13.dist-info → graphiti_core-0.22.0.dist-info}/WHEEL +0 -0
- {graphiti_core-0.21.0rc13.dist-info → graphiti_core-0.22.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
summary_instructions = """Guidelines:
|
|
18
|
+
1. Output only factual content. Never explain what you're doing, why, or mention limitations/constraints.
|
|
19
|
+
2. Only use the provided messages, entity, and entity context to set attribute values.
|
|
20
|
+
3. Keep the summary concise and to the point. STATE FACTS DIRECTLY IN UNDER 250 CHARACTERS.
|
|
21
|
+
|
|
22
|
+
Example summaries:
|
|
23
|
+
BAD: "This is the only activity in the context. The user listened to this song. No other details were provided to include in this summary."
|
|
24
|
+
GOOD: "User played 'Blue Monday' by New Order (electronic genre) on 2024-12-03 at 14:22 UTC."
|
|
25
|
+
BAD: "Based on the messages provided, the user attended a meeting. This summary focuses on that event as it was the main topic discussed."
|
|
26
|
+
GOOD: "User attended Q3 planning meeting with sales team on March 15."
|
|
27
|
+
BAD: "The context shows John ordered pizza. Due to length constraints, other details are omitted from this summary."
|
|
28
|
+
GOOD: "John ordered pepperoni pizza from Mario's at 7:30 PM, delivered to office."
|
|
29
|
+
"""
|
|
@@ -20,12 +20,13 @@ from pydantic import BaseModel, Field
|
|
|
20
20
|
|
|
21
21
|
from .models import Message, PromptFunction, PromptVersion
|
|
22
22
|
from .prompt_helpers import to_prompt_json
|
|
23
|
+
from .snippets import summary_instructions
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
class Summary(BaseModel):
|
|
26
27
|
summary: str = Field(
|
|
27
28
|
...,
|
|
28
|
-
description='Summary containing the important information about the entity. Under 250
|
|
29
|
+
description='Summary containing the important information about the entity. Under 250 characters',
|
|
29
30
|
)
|
|
30
31
|
|
|
31
32
|
|
|
@@ -55,11 +56,11 @@ def summarize_pair(context: dict[str, Any]) -> list[Message]:
|
|
|
55
56
|
role='user',
|
|
56
57
|
content=f"""
|
|
57
58
|
Synthesize the information from the following two summaries into a single succinct summary.
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
IMPORTANT: Keep the summary concise and to the point. SUMMARIES MUST BE LESS THAN 250 CHARACTERS.
|
|
60
61
|
|
|
61
62
|
Summaries:
|
|
62
|
-
{to_prompt_json(context['node_summaries']
|
|
63
|
+
{to_prompt_json(context['node_summaries'])}
|
|
63
64
|
""",
|
|
64
65
|
),
|
|
65
66
|
]
|
|
@@ -69,38 +70,35 @@ def summarize_context(context: dict[str, Any]) -> list[Message]:
|
|
|
69
70
|
return [
|
|
70
71
|
Message(
|
|
71
72
|
role='system',
|
|
72
|
-
content='You are a helpful assistant that
|
|
73
|
+
content='You are a helpful assistant that generates a summary and attributes from provided text.',
|
|
73
74
|
),
|
|
74
75
|
Message(
|
|
75
76
|
role='user',
|
|
76
77
|
content=f"""
|
|
77
|
-
|
|
78
|
-
<MESSAGES>
|
|
79
|
-
{to_prompt_json(context['previous_episodes'], indent=2)}
|
|
80
|
-
{to_prompt_json(context['episode_content'], indent=2)}
|
|
81
|
-
</MESSAGES>
|
|
82
|
-
|
|
83
|
-
Given the above MESSAGES and the following ENTITY name, create a summary for the ENTITY. Your summary must only use
|
|
78
|
+
Given the MESSAGES and the ENTITY name, create a summary for the ENTITY. Your summary must only use
|
|
84
79
|
information from the provided MESSAGES. Your summary should also only contain information relevant to the
|
|
85
|
-
provided ENTITY.
|
|
86
|
-
|
|
80
|
+
provided ENTITY.
|
|
81
|
+
|
|
87
82
|
In addition, extract any values for the provided entity properties based on their descriptions.
|
|
88
83
|
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.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
|
|
85
|
+
{summary_instructions}
|
|
86
|
+
|
|
87
|
+
<MESSAGES>
|
|
88
|
+
{to_prompt_json(context['previous_episodes'])}
|
|
89
|
+
{to_prompt_json(context['episode_content'])}
|
|
90
|
+
</MESSAGES>
|
|
91
|
+
|
|
94
92
|
<ENTITY>
|
|
95
93
|
{context['node_name']}
|
|
96
94
|
</ENTITY>
|
|
97
|
-
|
|
95
|
+
|
|
98
96
|
<ENTITY CONTEXT>
|
|
99
97
|
{context['node_summary']}
|
|
100
98
|
</ENTITY CONTEXT>
|
|
101
|
-
|
|
99
|
+
|
|
102
100
|
<ATTRIBUTES>
|
|
103
|
-
{to_prompt_json(context['attributes']
|
|
101
|
+
{to_prompt_json(context['attributes'])}
|
|
104
102
|
</ATTRIBUTES>
|
|
105
103
|
""",
|
|
106
104
|
),
|
|
@@ -117,10 +115,10 @@ def summary_description(context: dict[str, Any]) -> list[Message]:
|
|
|
117
115
|
role='user',
|
|
118
116
|
content=f"""
|
|
119
117
|
Create a short one sentence description of the summary that explains what kind of information is summarized.
|
|
120
|
-
Summaries must be under 250
|
|
118
|
+
Summaries must be under 250 characters.
|
|
121
119
|
|
|
122
120
|
Summary:
|
|
123
|
-
{to_prompt_json(context['summary']
|
|
121
|
+
{to_prompt_json(context['summary'])}
|
|
124
122
|
""",
|
|
125
123
|
),
|
|
126
124
|
]
|
|
@@ -249,41 +249,3 @@ def edge_search_filter_query_constructor(
|
|
|
249
249
|
filter_queries.append(expired_at_filter)
|
|
250
250
|
|
|
251
251
|
return filter_queries, filter_params
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
def build_aoss_node_filters(group_ids: list[str], search_filters: SearchFilters) -> list[dict]:
|
|
255
|
-
filters = [{'terms': {'group_id': group_ids}}]
|
|
256
|
-
|
|
257
|
-
if search_filters.node_labels:
|
|
258
|
-
filters.append({'terms': {'node_labels': search_filters.node_labels}})
|
|
259
|
-
|
|
260
|
-
return filters
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
def build_aoss_edge_filters(group_ids: list[str], search_filters: SearchFilters) -> list[dict]:
|
|
264
|
-
filters: list[dict] = [{'terms': {'group_id': group_ids}}]
|
|
265
|
-
|
|
266
|
-
if search_filters.edge_types:
|
|
267
|
-
filters.append({'terms': {'edge_types': search_filters.edge_types}})
|
|
268
|
-
|
|
269
|
-
if search_filters.edge_uuids:
|
|
270
|
-
filters.append({'terms': {'uuid': search_filters.edge_uuids}})
|
|
271
|
-
|
|
272
|
-
for field in ['valid_at', 'invalid_at', 'created_at', 'expired_at']:
|
|
273
|
-
ranges = getattr(search_filters, field)
|
|
274
|
-
if ranges:
|
|
275
|
-
# OR of ANDs
|
|
276
|
-
should_clauses = []
|
|
277
|
-
for and_group in ranges:
|
|
278
|
-
and_filters = []
|
|
279
|
-
for df in and_group: # df is a DateFilter
|
|
280
|
-
range_query = {
|
|
281
|
-
'range': {
|
|
282
|
-
field: {cypher_to_opensearch_operator(df.comparison_operator): df.date}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
and_filters.append(range_query)
|
|
286
|
-
should_clauses.append({'bool': {'filter': and_filters}})
|
|
287
|
-
filters.append({'bool': {'should': should_clauses, 'minimum_should_match': 1}})
|
|
288
|
-
|
|
289
|
-
return filters
|
|
@@ -56,16 +56,16 @@ def search_results_to_context_string(search_results: SearchResults) -> str:
|
|
|
56
56
|
These are the most relevant facts and their valid and invalid dates. Facts are considered valid
|
|
57
57
|
between their valid_at and invalid_at dates. Facts with an invalid_at date of "Present" are considered valid.
|
|
58
58
|
<FACTS>
|
|
59
|
-
{to_prompt_json(fact_json
|
|
59
|
+
{to_prompt_json(fact_json)}
|
|
60
60
|
</FACTS>
|
|
61
61
|
<ENTITIES>
|
|
62
|
-
{to_prompt_json(entity_json
|
|
62
|
+
{to_prompt_json(entity_json)}
|
|
63
63
|
</ENTITIES>
|
|
64
64
|
<EPISODES>
|
|
65
|
-
{to_prompt_json(episode_json
|
|
65
|
+
{to_prompt_json(episode_json)}
|
|
66
66
|
</EPISODES>
|
|
67
67
|
<COMMUNITIES>
|
|
68
|
-
{to_prompt_json(community_json
|
|
68
|
+
{to_prompt_json(community_json)}
|
|
69
69
|
</COMMUNITIES>
|
|
70
70
|
"""
|
|
71
71
|
|