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,89 @@
|
|
|
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
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SearchInterface(BaseModel):
|
|
23
|
+
"""
|
|
24
|
+
This is an interface for implementing custom search logic
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
async def edge_fulltext_search(
|
|
28
|
+
self,
|
|
29
|
+
driver: Any,
|
|
30
|
+
query: str,
|
|
31
|
+
search_filter: Any,
|
|
32
|
+
group_ids: list[str] | None = None,
|
|
33
|
+
limit: int = 100,
|
|
34
|
+
) -> list[Any]:
|
|
35
|
+
raise NotImplementedError
|
|
36
|
+
|
|
37
|
+
async def edge_similarity_search(
|
|
38
|
+
self,
|
|
39
|
+
driver: Any,
|
|
40
|
+
search_vector: list[float],
|
|
41
|
+
source_node_uuid: str | None,
|
|
42
|
+
target_node_uuid: str | None,
|
|
43
|
+
search_filter: Any,
|
|
44
|
+
group_ids: list[str] | None = None,
|
|
45
|
+
limit: int = 100,
|
|
46
|
+
min_score: float = 0.7,
|
|
47
|
+
) -> list[Any]:
|
|
48
|
+
raise NotImplementedError
|
|
49
|
+
|
|
50
|
+
async def node_fulltext_search(
|
|
51
|
+
self,
|
|
52
|
+
driver: Any,
|
|
53
|
+
query: str,
|
|
54
|
+
search_filter: Any,
|
|
55
|
+
group_ids: list[str] | None = None,
|
|
56
|
+
limit: int = 100,
|
|
57
|
+
) -> list[Any]:
|
|
58
|
+
raise NotImplementedError
|
|
59
|
+
|
|
60
|
+
async def node_similarity_search(
|
|
61
|
+
self,
|
|
62
|
+
driver: Any,
|
|
63
|
+
search_vector: list[float],
|
|
64
|
+
search_filter: Any,
|
|
65
|
+
group_ids: list[str] | None = None,
|
|
66
|
+
limit: int = 100,
|
|
67
|
+
min_score: float = 0.7,
|
|
68
|
+
) -> list[Any]:
|
|
69
|
+
raise NotImplementedError
|
|
70
|
+
|
|
71
|
+
async def episode_fulltext_search(
|
|
72
|
+
self,
|
|
73
|
+
driver: Any,
|
|
74
|
+
query: str,
|
|
75
|
+
search_filter: Any, # kept for parity even if unused in your impl
|
|
76
|
+
group_ids: list[str] | None = None,
|
|
77
|
+
limit: int = 100,
|
|
78
|
+
) -> list[Any]:
|
|
79
|
+
raise NotImplementedError
|
|
80
|
+
|
|
81
|
+
# ---------- SEARCH FILTERS (sync) ----------
|
|
82
|
+
def build_node_search_filters(self, search_filters: Any) -> Any:
|
|
83
|
+
raise NotImplementedError
|
|
84
|
+
|
|
85
|
+
def build_edge_search_filters(self, search_filters: Any) -> Any:
|
|
86
|
+
raise NotImplementedError
|
|
87
|
+
|
|
88
|
+
class Config:
|
|
89
|
+
arbitrary_types_allowed = True
|
graphiti_core/edges.py
CHANGED
|
@@ -25,7 +25,7 @@ from uuid import uuid4
|
|
|
25
25
|
from pydantic import BaseModel, Field
|
|
26
26
|
from typing_extensions import LiteralString
|
|
27
27
|
|
|
28
|
-
from graphiti_core.driver.driver import
|
|
28
|
+
from graphiti_core.driver.driver import GraphDriver, GraphProvider
|
|
29
29
|
from graphiti_core.embedder import EmbedderClient
|
|
30
30
|
from graphiti_core.errors import EdgeNotFoundError, GroupsEdgesNotFoundError
|
|
31
31
|
from graphiti_core.helpers import parse_db_date
|
|
@@ -53,6 +53,9 @@ class Edge(BaseModel, ABC):
|
|
|
53
53
|
async def save(self, driver: GraphDriver): ...
|
|
54
54
|
|
|
55
55
|
async def delete(self, driver: GraphDriver):
|
|
56
|
+
if driver.graph_operations_interface:
|
|
57
|
+
return await driver.graph_operations_interface.edge_delete(self, driver)
|
|
58
|
+
|
|
56
59
|
if driver.provider == GraphProvider.KUZU:
|
|
57
60
|
await driver.execute_query(
|
|
58
61
|
"""
|
|
@@ -77,17 +80,13 @@ class Edge(BaseModel, ABC):
|
|
|
77
80
|
uuid=self.uuid,
|
|
78
81
|
)
|
|
79
82
|
|
|
80
|
-
if driver.aoss_client:
|
|
81
|
-
await driver.aoss_client.delete(
|
|
82
|
-
index=ENTITY_EDGE_INDEX_NAME,
|
|
83
|
-
id=self.uuid,
|
|
84
|
-
params={'routing': self.group_id},
|
|
85
|
-
)
|
|
86
|
-
|
|
87
83
|
logger.debug(f'Deleted Edge: {self.uuid}')
|
|
88
84
|
|
|
89
85
|
@classmethod
|
|
90
86
|
async def delete_by_uuids(cls, driver: GraphDriver, uuids: list[str]):
|
|
87
|
+
if driver.graph_operations_interface:
|
|
88
|
+
return await driver.graph_operations_interface.edge_delete_by_uuids(cls, driver, uuids)
|
|
89
|
+
|
|
91
90
|
if driver.provider == GraphProvider.KUZU:
|
|
92
91
|
await driver.execute_query(
|
|
93
92
|
"""
|
|
@@ -115,12 +114,6 @@ class Edge(BaseModel, ABC):
|
|
|
115
114
|
uuids=uuids,
|
|
116
115
|
)
|
|
117
116
|
|
|
118
|
-
if driver.aoss_client:
|
|
119
|
-
await driver.aoss_client.delete_by_query(
|
|
120
|
-
index=ENTITY_EDGE_INDEX_NAME,
|
|
121
|
-
body={'query': {'terms': {'uuid': uuids}}},
|
|
122
|
-
)
|
|
123
|
-
|
|
124
117
|
logger.debug(f'Deleted Edges: {uuids}')
|
|
125
118
|
|
|
126
119
|
def __hash__(self):
|
|
@@ -258,6 +251,9 @@ class EntityEdge(Edge):
|
|
|
258
251
|
return self.fact_embedding
|
|
259
252
|
|
|
260
253
|
async def load_fact_embedding(self, driver: GraphDriver):
|
|
254
|
+
if driver.graph_operations_interface:
|
|
255
|
+
return await driver.graph_operations_interface.edge_load_embeddings(self, driver)
|
|
256
|
+
|
|
261
257
|
query = """
|
|
262
258
|
MATCH (n:Entity)-[e:RELATES_TO {uuid: $uuid}]->(m:Entity)
|
|
263
259
|
RETURN e.fact_embedding AS fact_embedding
|
|
@@ -268,21 +264,6 @@ class EntityEdge(Edge):
|
|
|
268
264
|
MATCH (n:Entity)-[e:RELATES_TO {uuid: $uuid}]->(m:Entity)
|
|
269
265
|
RETURN [x IN split(e.fact_embedding, ",") | toFloat(x)] as fact_embedding
|
|
270
266
|
"""
|
|
271
|
-
elif driver.aoss_client:
|
|
272
|
-
resp = await driver.aoss_client.search(
|
|
273
|
-
body={
|
|
274
|
-
'query': {'multi_match': {'query': self.uuid, 'fields': ['uuid']}},
|
|
275
|
-
'size': 1,
|
|
276
|
-
},
|
|
277
|
-
index=ENTITY_EDGE_INDEX_NAME,
|
|
278
|
-
params={'routing': self.group_id},
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
if resp['hits']['hits']:
|
|
282
|
-
self.fact_embedding = resp['hits']['hits'][0]['_source']['fact_embedding']
|
|
283
|
-
return
|
|
284
|
-
else:
|
|
285
|
-
raise EdgeNotFoundError(self.uuid)
|
|
286
267
|
|
|
287
268
|
if driver.provider == GraphProvider.KUZU:
|
|
288
269
|
query = """
|
|
@@ -320,15 +301,11 @@ class EntityEdge(Edge):
|
|
|
320
301
|
if driver.provider == GraphProvider.KUZU:
|
|
321
302
|
edge_data['attributes'] = json.dumps(self.attributes)
|
|
322
303
|
result = await driver.execute_query(
|
|
323
|
-
get_entity_edge_save_query(driver.provider
|
|
304
|
+
get_entity_edge_save_query(driver.provider),
|
|
324
305
|
**edge_data,
|
|
325
306
|
)
|
|
326
307
|
else:
|
|
327
308
|
edge_data.update(self.attributes or {})
|
|
328
|
-
|
|
329
|
-
if driver.aoss_client:
|
|
330
|
-
await driver.save_to_aoss(ENTITY_EDGE_INDEX_NAME, [edge_data]) # pyright: ignore reportAttributeAccessIssue
|
|
331
|
-
|
|
332
309
|
result = await driver.execute_query(
|
|
333
310
|
get_entity_edge_save_query(driver.provider),
|
|
334
311
|
edge_data=edge_data,
|