graphiti-core 0.17.4__py3-none-any.whl → 0.24.3__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.
- graphiti_core/cross_encoder/gemini_reranker_client.py +1 -1
- graphiti_core/cross_encoder/openai_reranker_client.py +1 -1
- graphiti_core/decorators.py +110 -0
- graphiti_core/driver/driver.py +62 -2
- graphiti_core/driver/falkordb_driver.py +215 -23
- graphiti_core/driver/graph_operations/graph_operations.py +191 -0
- graphiti_core/driver/kuzu_driver.py +182 -0
- graphiti_core/driver/neo4j_driver.py +61 -8
- graphiti_core/driver/neptune_driver.py +305 -0
- graphiti_core/driver/search_interface/search_interface.py +89 -0
- graphiti_core/edges.py +264 -132
- graphiti_core/embedder/azure_openai.py +10 -3
- graphiti_core/embedder/client.py +2 -1
- graphiti_core/graph_queries.py +114 -101
- graphiti_core/graphiti.py +582 -255
- graphiti_core/graphiti_types.py +2 -0
- graphiti_core/helpers.py +21 -14
- graphiti_core/llm_client/anthropic_client.py +142 -52
- graphiti_core/llm_client/azure_openai_client.py +57 -19
- graphiti_core/llm_client/client.py +83 -21
- graphiti_core/llm_client/config.py +1 -1
- graphiti_core/llm_client/gemini_client.py +75 -57
- graphiti_core/llm_client/openai_base_client.py +94 -50
- graphiti_core/llm_client/openai_client.py +28 -8
- graphiti_core/llm_client/openai_generic_client.py +91 -56
- graphiti_core/models/edges/edge_db_queries.py +259 -35
- graphiti_core/models/nodes/node_db_queries.py +311 -32
- graphiti_core/nodes.py +388 -164
- graphiti_core/prompts/dedupe_edges.py +42 -31
- graphiti_core/prompts/dedupe_nodes.py +56 -39
- graphiti_core/prompts/eval.py +4 -4
- graphiti_core/prompts/extract_edges.py +23 -14
- graphiti_core/prompts/extract_nodes.py +73 -32
- graphiti_core/prompts/prompt_helpers.py +39 -0
- graphiti_core/prompts/snippets.py +29 -0
- graphiti_core/prompts/summarize_nodes.py +23 -25
- graphiti_core/search/search.py +154 -74
- graphiti_core/search/search_config.py +39 -4
- graphiti_core/search/search_filters.py +109 -31
- graphiti_core/search/search_helpers.py +5 -6
- graphiti_core/search/search_utils.py +1360 -473
- graphiti_core/tracer.py +193 -0
- graphiti_core/utils/bulk_utils.py +216 -90
- graphiti_core/utils/datetime_utils.py +13 -0
- graphiti_core/utils/maintenance/community_operations.py +62 -38
- graphiti_core/utils/maintenance/dedup_helpers.py +262 -0
- graphiti_core/utils/maintenance/edge_operations.py +286 -126
- graphiti_core/utils/maintenance/graph_data_operations.py +44 -74
- graphiti_core/utils/maintenance/node_operations.py +320 -158
- graphiti_core/utils/maintenance/temporal_operations.py +11 -3
- graphiti_core/utils/ontology_utils/entity_types_utils.py +1 -1
- graphiti_core/utils/text_utils.py +53 -0
- {graphiti_core-0.17.4.dist-info → graphiti_core-0.24.3.dist-info}/METADATA +221 -87
- graphiti_core-0.24.3.dist-info/RECORD +86 -0
- {graphiti_core-0.17.4.dist-info → graphiti_core-0.24.3.dist-info}/WHEEL +1 -1
- graphiti_core-0.17.4.dist-info/RECORD +0 -77
- /graphiti_core/{utils/maintenance/utils.py → migrations/__init__.py} +0 -0
- {graphiti_core-0.17.4.dist-info → graphiti_core-0.24.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -14,39 +14,318 @@ See the License for the specific language governing permissions and
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from graphiti_core.driver.driver import GraphProvider
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_episode_node_save_query(provider: GraphProvider) -> str:
|
|
23
|
+
match provider:
|
|
24
|
+
case GraphProvider.NEPTUNE:
|
|
25
|
+
return """
|
|
26
|
+
MERGE (n:Episodic {uuid: $uuid})
|
|
27
|
+
SET n = {uuid: $uuid, name: $name, group_id: $group_id, source_description: $source_description, source: $source, content: $content,
|
|
28
|
+
entity_edges: join([x IN coalesce($entity_edges, []) | toString(x) ], '|'), created_at: $created_at, valid_at: $valid_at}
|
|
29
|
+
RETURN n.uuid AS uuid
|
|
30
|
+
"""
|
|
31
|
+
case GraphProvider.KUZU:
|
|
32
|
+
return """
|
|
33
|
+
MERGE (n:Episodic {uuid: $uuid})
|
|
34
|
+
SET
|
|
35
|
+
n.name = $name,
|
|
36
|
+
n.group_id = $group_id,
|
|
37
|
+
n.created_at = $created_at,
|
|
38
|
+
n.source = $source,
|
|
39
|
+
n.source_description = $source_description,
|
|
40
|
+
n.content = $content,
|
|
41
|
+
n.valid_at = $valid_at,
|
|
42
|
+
n.entity_edges = $entity_edges
|
|
43
|
+
RETURN n.uuid AS uuid
|
|
44
|
+
"""
|
|
45
|
+
case GraphProvider.FALKORDB:
|
|
46
|
+
return """
|
|
47
|
+
MERGE (n:Episodic {uuid: $uuid})
|
|
48
|
+
SET n = {uuid: $uuid, name: $name, group_id: $group_id, source_description: $source_description, source: $source, content: $content,
|
|
49
|
+
entity_edges: $entity_edges, created_at: $created_at, valid_at: $valid_at}
|
|
50
|
+
RETURN n.uuid AS uuid
|
|
51
|
+
"""
|
|
52
|
+
case _: # Neo4j
|
|
53
|
+
return """
|
|
54
|
+
MERGE (n:Episodic {uuid: $uuid})
|
|
55
|
+
SET n = {uuid: $uuid, name: $name, group_id: $group_id, source_description: $source_description, source: $source, content: $content,
|
|
56
|
+
entity_edges: $entity_edges, created_at: $created_at, valid_at: $valid_at}
|
|
57
|
+
RETURN n.uuid AS uuid
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_episode_node_save_bulk_query(provider: GraphProvider) -> str:
|
|
62
|
+
match provider:
|
|
63
|
+
case GraphProvider.NEPTUNE:
|
|
64
|
+
return """
|
|
65
|
+
UNWIND $episodes AS episode
|
|
66
|
+
MERGE (n:Episodic {uuid: episode.uuid})
|
|
67
|
+
SET n = {uuid: episode.uuid, name: episode.name, group_id: episode.group_id, source_description: episode.source_description,
|
|
68
|
+
source: episode.source, content: episode.content,
|
|
69
|
+
entity_edges: join([x IN coalesce(episode.entity_edges, []) | toString(x) ], '|'), created_at: episode.created_at, valid_at: episode.valid_at}
|
|
70
|
+
RETURN n.uuid AS uuid
|
|
71
|
+
"""
|
|
72
|
+
case GraphProvider.KUZU:
|
|
73
|
+
return """
|
|
74
|
+
MERGE (n:Episodic {uuid: $uuid})
|
|
75
|
+
SET
|
|
76
|
+
n.name = $name,
|
|
77
|
+
n.group_id = $group_id,
|
|
78
|
+
n.created_at = $created_at,
|
|
79
|
+
n.source = $source,
|
|
80
|
+
n.source_description = $source_description,
|
|
81
|
+
n.content = $content,
|
|
82
|
+
n.valid_at = $valid_at,
|
|
83
|
+
n.entity_edges = $entity_edges
|
|
84
|
+
RETURN n.uuid AS uuid
|
|
85
|
+
"""
|
|
86
|
+
case GraphProvider.FALKORDB:
|
|
87
|
+
return """
|
|
88
|
+
UNWIND $episodes AS episode
|
|
89
|
+
MERGE (n:Episodic {uuid: episode.uuid})
|
|
90
|
+
SET n = {uuid: episode.uuid, name: episode.name, group_id: episode.group_id, source_description: episode.source_description, source: episode.source, content: episode.content,
|
|
91
|
+
entity_edges: episode.entity_edges, created_at: episode.created_at, valid_at: episode.valid_at}
|
|
92
|
+
RETURN n.uuid AS uuid
|
|
93
|
+
"""
|
|
94
|
+
case _: # Neo4j
|
|
95
|
+
return """
|
|
96
|
+
UNWIND $episodes AS episode
|
|
97
|
+
MERGE (n:Episodic {uuid: episode.uuid})
|
|
98
|
+
SET n = {uuid: episode.uuid, name: episode.name, group_id: episode.group_id, source_description: episode.source_description, source: episode.source, content: episode.content,
|
|
99
|
+
entity_edges: episode.entity_edges, created_at: episode.created_at, valid_at: episode.valid_at}
|
|
100
|
+
RETURN n.uuid AS uuid
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
EPISODIC_NODE_RETURN = """
|
|
105
|
+
e.uuid AS uuid,
|
|
106
|
+
e.name AS name,
|
|
107
|
+
e.group_id AS group_id,
|
|
108
|
+
e.created_at AS created_at,
|
|
109
|
+
e.source AS source,
|
|
110
|
+
e.source_description AS source_description,
|
|
111
|
+
e.content AS content,
|
|
112
|
+
e.valid_at AS valid_at,
|
|
113
|
+
e.entity_edges AS entity_edges
|
|
30
114
|
"""
|
|
31
115
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
116
|
+
EPISODIC_NODE_RETURN_NEPTUNE = """
|
|
117
|
+
e.content AS content,
|
|
118
|
+
e.created_at AS created_at,
|
|
119
|
+
e.valid_at AS valid_at,
|
|
120
|
+
e.uuid AS uuid,
|
|
121
|
+
e.name AS name,
|
|
122
|
+
e.group_id AS group_id,
|
|
123
|
+
e.source_description AS source_description,
|
|
124
|
+
e.source AS source,
|
|
125
|
+
split(e.entity_edges, ",") AS entity_edges
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def get_entity_node_save_query(provider: GraphProvider, labels: str, has_aoss: bool = False) -> str:
|
|
130
|
+
match provider:
|
|
131
|
+
case GraphProvider.FALKORDB:
|
|
132
|
+
return f"""
|
|
133
|
+
MERGE (n:Entity {{uuid: $entity_data.uuid}})
|
|
134
|
+
SET n:{labels}
|
|
135
|
+
SET n = $entity_data
|
|
136
|
+
SET n.name_embedding = vecf32($entity_data.name_embedding)
|
|
137
|
+
RETURN n.uuid AS uuid
|
|
138
|
+
"""
|
|
139
|
+
case GraphProvider.KUZU:
|
|
140
|
+
return """
|
|
141
|
+
MERGE (n:Entity {uuid: $uuid})
|
|
142
|
+
SET
|
|
143
|
+
n.name = $name,
|
|
144
|
+
n.group_id = $group_id,
|
|
145
|
+
n.labels = $labels,
|
|
146
|
+
n.created_at = $created_at,
|
|
147
|
+
n.name_embedding = $name_embedding,
|
|
148
|
+
n.summary = $summary,
|
|
149
|
+
n.attributes = $attributes
|
|
150
|
+
WITH n
|
|
151
|
+
RETURN n.uuid AS uuid
|
|
152
|
+
"""
|
|
153
|
+
case GraphProvider.NEPTUNE:
|
|
154
|
+
label_subquery = ''
|
|
155
|
+
for label in labels.split(':'):
|
|
156
|
+
label_subquery += f' SET n:{label}\n'
|
|
157
|
+
return f"""
|
|
158
|
+
MERGE (n:Entity {{uuid: $entity_data.uuid}})
|
|
159
|
+
{label_subquery}
|
|
160
|
+
SET n = removeKeyFromMap(removeKeyFromMap($entity_data, "labels"), "name_embedding")
|
|
161
|
+
SET n.name_embedding = join([x IN coalesce($entity_data.name_embedding, []) | toString(x) ], ",")
|
|
162
|
+
RETURN n.uuid AS uuid
|
|
163
|
+
"""
|
|
164
|
+
case _:
|
|
165
|
+
save_embedding_query = (
|
|
166
|
+
'WITH n CALL db.create.setNodeVectorProperty(n, "name_embedding", $entity_data.name_embedding)'
|
|
167
|
+
if not has_aoss
|
|
168
|
+
else ''
|
|
169
|
+
)
|
|
170
|
+
return (
|
|
171
|
+
f"""
|
|
172
|
+
MERGE (n:Entity {{uuid: $entity_data.uuid}})
|
|
173
|
+
SET n:{labels}
|
|
174
|
+
SET n = $entity_data
|
|
175
|
+
"""
|
|
176
|
+
+ save_embedding_query
|
|
177
|
+
+ """
|
|
178
|
+
RETURN n.uuid AS uuid
|
|
179
|
+
"""
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def get_entity_node_save_bulk_query(
|
|
184
|
+
provider: GraphProvider, nodes: list[dict], has_aoss: bool = False
|
|
185
|
+
) -> str | Any:
|
|
186
|
+
match provider:
|
|
187
|
+
case GraphProvider.FALKORDB:
|
|
188
|
+
queries = []
|
|
189
|
+
for node in nodes:
|
|
190
|
+
for label in node['labels']:
|
|
191
|
+
queries.append(
|
|
192
|
+
(
|
|
193
|
+
f"""
|
|
194
|
+
UNWIND $nodes AS node
|
|
195
|
+
MERGE (n:Entity {{uuid: node.uuid}})
|
|
196
|
+
SET n:{label}
|
|
197
|
+
SET n = node
|
|
198
|
+
WITH n, node
|
|
199
|
+
SET n.name_embedding = vecf32(node.name_embedding)
|
|
200
|
+
RETURN n.uuid AS uuid
|
|
201
|
+
""",
|
|
202
|
+
{'nodes': [node]},
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
return queries
|
|
206
|
+
case GraphProvider.NEPTUNE:
|
|
207
|
+
queries = []
|
|
208
|
+
for node in nodes:
|
|
209
|
+
labels = ''
|
|
210
|
+
for label in node['labels']:
|
|
211
|
+
labels += f' SET n:{label}\n'
|
|
212
|
+
queries.append(
|
|
213
|
+
f"""
|
|
214
|
+
UNWIND $nodes AS node
|
|
215
|
+
MERGE (n:Entity {{uuid: node.uuid}})
|
|
216
|
+
{labels}
|
|
217
|
+
SET n = removeKeyFromMap(removeKeyFromMap(node, "labels"), "name_embedding")
|
|
218
|
+
SET n.name_embedding = join([x IN coalesce(node.name_embedding, []) | toString(x) ], ",")
|
|
219
|
+
RETURN n.uuid AS uuid
|
|
220
|
+
"""
|
|
221
|
+
)
|
|
222
|
+
return queries
|
|
223
|
+
case GraphProvider.KUZU:
|
|
224
|
+
return """
|
|
225
|
+
MERGE (n:Entity {uuid: $uuid})
|
|
226
|
+
SET
|
|
227
|
+
n.name = $name,
|
|
228
|
+
n.group_id = $group_id,
|
|
229
|
+
n.labels = $labels,
|
|
230
|
+
n.created_at = $created_at,
|
|
231
|
+
n.name_embedding = $name_embedding,
|
|
232
|
+
n.summary = $summary,
|
|
233
|
+
n.attributes = $attributes
|
|
234
|
+
RETURN n.uuid AS uuid
|
|
235
|
+
"""
|
|
236
|
+
case _: # Neo4j
|
|
237
|
+
save_embedding_query = (
|
|
238
|
+
'WITH n, node CALL db.create.setNodeVectorProperty(n, "name_embedding", node.name_embedding)'
|
|
239
|
+
if not has_aoss
|
|
240
|
+
else ''
|
|
241
|
+
)
|
|
242
|
+
return (
|
|
243
|
+
"""
|
|
244
|
+
UNWIND $nodes AS node
|
|
245
|
+
MERGE (n:Entity {uuid: node.uuid})
|
|
246
|
+
SET n:$(node.labels)
|
|
247
|
+
SET n = node
|
|
248
|
+
"""
|
|
249
|
+
+ save_embedding_query
|
|
250
|
+
+ """
|
|
251
|
+
RETURN n.uuid AS uuid
|
|
252
|
+
"""
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def get_entity_node_return_query(provider: GraphProvider) -> str:
|
|
257
|
+
# `name_embedding` is not returned by default and must be loaded manually using `load_name_embedding()`.
|
|
258
|
+
if provider == GraphProvider.KUZU:
|
|
259
|
+
return """
|
|
260
|
+
n.uuid AS uuid,
|
|
261
|
+
n.name AS name,
|
|
262
|
+
n.group_id AS group_id,
|
|
263
|
+
n.labels AS labels,
|
|
264
|
+
n.created_at AS created_at,
|
|
265
|
+
n.summary AS summary,
|
|
266
|
+
n.attributes AS attributes
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
return """
|
|
270
|
+
n.uuid AS uuid,
|
|
271
|
+
n.name AS name,
|
|
272
|
+
n.group_id AS group_id,
|
|
273
|
+
n.created_at AS created_at,
|
|
274
|
+
n.summary AS summary,
|
|
275
|
+
labels(n) AS labels,
|
|
276
|
+
properties(n) AS attributes
|
|
277
|
+
"""
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def get_community_node_save_query(provider: GraphProvider) -> str:
|
|
281
|
+
match provider:
|
|
282
|
+
case GraphProvider.FALKORDB:
|
|
283
|
+
return """
|
|
284
|
+
MERGE (n:Community {uuid: $uuid})
|
|
285
|
+
SET n = {uuid: $uuid, name: $name, group_id: $group_id, summary: $summary, created_at: $created_at, name_embedding: vecf32($name_embedding)}
|
|
286
|
+
RETURN n.uuid AS uuid
|
|
287
|
+
"""
|
|
288
|
+
case GraphProvider.NEPTUNE:
|
|
289
|
+
return """
|
|
290
|
+
MERGE (n:Community {uuid: $uuid})
|
|
291
|
+
SET n = {uuid: $uuid, name: $name, group_id: $group_id, summary: $summary, created_at: $created_at}
|
|
292
|
+
SET n.name_embedding = join([x IN coalesce($name_embedding, []) | toString(x) ], ",")
|
|
293
|
+
RETURN n.uuid AS uuid
|
|
294
|
+
"""
|
|
295
|
+
case GraphProvider.KUZU:
|
|
296
|
+
return """
|
|
297
|
+
MERGE (n:Community {uuid: $uuid})
|
|
298
|
+
SET
|
|
299
|
+
n.name = $name,
|
|
300
|
+
n.group_id = $group_id,
|
|
301
|
+
n.created_at = $created_at,
|
|
302
|
+
n.name_embedding = $name_embedding,
|
|
303
|
+
n.summary = $summary
|
|
304
|
+
RETURN n.uuid AS uuid
|
|
305
|
+
"""
|
|
306
|
+
case _: # Neo4j
|
|
307
|
+
return """
|
|
308
|
+
MERGE (n:Community {uuid: $uuid})
|
|
309
|
+
SET n = {uuid: $uuid, name: $name, group_id: $group_id, summary: $summary, created_at: $created_at}
|
|
310
|
+
WITH n CALL db.create.setNodeVectorProperty(n, "name_embedding", $name_embedding)
|
|
311
|
+
RETURN n.uuid AS uuid
|
|
312
|
+
"""
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
COMMUNITY_NODE_RETURN = """
|
|
316
|
+
c.uuid AS uuid,
|
|
317
|
+
c.name AS name,
|
|
318
|
+
c.group_id AS group_id,
|
|
319
|
+
c.created_at AS created_at,
|
|
320
|
+
c.name_embedding AS name_embedding,
|
|
321
|
+
c.summary AS summary
|
|
46
322
|
"""
|
|
47
323
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
324
|
+
COMMUNITY_NODE_RETURN_NEPTUNE = """
|
|
325
|
+
n.uuid AS uuid,
|
|
326
|
+
n.name AS name,
|
|
327
|
+
[x IN split(n.name_embedding, ",") | toFloat(x)] AS name_embedding,
|
|
328
|
+
n.group_id AS group_id,
|
|
329
|
+
n.summary AS summary,
|
|
330
|
+
n.created_at AS created_at
|
|
331
|
+
"""
|