graphiti-core 0.12.0rc1__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.
Files changed (68) hide show
  1. graphiti_core/cross_encoder/bge_reranker_client.py +12 -2
  2. graphiti_core/cross_encoder/gemini_reranker_client.py +161 -0
  3. graphiti_core/cross_encoder/openai_reranker_client.py +7 -5
  4. graphiti_core/decorators.py +110 -0
  5. graphiti_core/driver/__init__.py +19 -0
  6. graphiti_core/driver/driver.py +124 -0
  7. graphiti_core/driver/falkordb_driver.py +362 -0
  8. graphiti_core/driver/graph_operations/graph_operations.py +191 -0
  9. graphiti_core/driver/kuzu_driver.py +182 -0
  10. graphiti_core/driver/neo4j_driver.py +117 -0
  11. graphiti_core/driver/neptune_driver.py +305 -0
  12. graphiti_core/driver/search_interface/search_interface.py +89 -0
  13. graphiti_core/edges.py +287 -172
  14. graphiti_core/embedder/azure_openai.py +71 -0
  15. graphiti_core/embedder/client.py +2 -1
  16. graphiti_core/embedder/gemini.py +116 -22
  17. graphiti_core/embedder/voyage.py +13 -2
  18. graphiti_core/errors.py +8 -0
  19. graphiti_core/graph_queries.py +162 -0
  20. graphiti_core/graphiti.py +705 -193
  21. graphiti_core/graphiti_types.py +4 -2
  22. graphiti_core/helpers.py +87 -10
  23. graphiti_core/llm_client/__init__.py +16 -0
  24. graphiti_core/llm_client/anthropic_client.py +159 -56
  25. graphiti_core/llm_client/azure_openai_client.py +115 -0
  26. graphiti_core/llm_client/client.py +98 -21
  27. graphiti_core/llm_client/config.py +1 -1
  28. graphiti_core/llm_client/gemini_client.py +290 -41
  29. graphiti_core/llm_client/groq_client.py +14 -3
  30. graphiti_core/llm_client/openai_base_client.py +261 -0
  31. graphiti_core/llm_client/openai_client.py +56 -132
  32. graphiti_core/llm_client/openai_generic_client.py +91 -56
  33. graphiti_core/models/edges/edge_db_queries.py +259 -35
  34. graphiti_core/models/nodes/node_db_queries.py +311 -32
  35. graphiti_core/nodes.py +420 -205
  36. graphiti_core/prompts/dedupe_edges.py +46 -32
  37. graphiti_core/prompts/dedupe_nodes.py +67 -42
  38. graphiti_core/prompts/eval.py +4 -4
  39. graphiti_core/prompts/extract_edges.py +27 -16
  40. graphiti_core/prompts/extract_nodes.py +74 -31
  41. graphiti_core/prompts/prompt_helpers.py +39 -0
  42. graphiti_core/prompts/snippets.py +29 -0
  43. graphiti_core/prompts/summarize_nodes.py +23 -25
  44. graphiti_core/search/search.py +158 -82
  45. graphiti_core/search/search_config.py +39 -4
  46. graphiti_core/search/search_filters.py +126 -35
  47. graphiti_core/search/search_helpers.py +5 -6
  48. graphiti_core/search/search_utils.py +1405 -485
  49. graphiti_core/telemetry/__init__.py +9 -0
  50. graphiti_core/telemetry/telemetry.py +117 -0
  51. graphiti_core/tracer.py +193 -0
  52. graphiti_core/utils/bulk_utils.py +364 -285
  53. graphiti_core/utils/datetime_utils.py +13 -0
  54. graphiti_core/utils/maintenance/community_operations.py +67 -49
  55. graphiti_core/utils/maintenance/dedup_helpers.py +262 -0
  56. graphiti_core/utils/maintenance/edge_operations.py +339 -197
  57. graphiti_core/utils/maintenance/graph_data_operations.py +50 -114
  58. graphiti_core/utils/maintenance/node_operations.py +319 -238
  59. graphiti_core/utils/maintenance/temporal_operations.py +11 -3
  60. graphiti_core/utils/ontology_utils/entity_types_utils.py +1 -1
  61. graphiti_core/utils/text_utils.py +53 -0
  62. graphiti_core-0.24.3.dist-info/METADATA +726 -0
  63. graphiti_core-0.24.3.dist-info/RECORD +86 -0
  64. {graphiti_core-0.12.0rc1.dist-info → graphiti_core-0.24.3.dist-info}/WHEEL +1 -1
  65. graphiti_core-0.12.0rc1.dist-info/METADATA +0 -350
  66. graphiti_core-0.12.0rc1.dist-info/RECORD +0 -66
  67. /graphiti_core/{utils/maintenance/utils.py → migrations/__init__.py} +0 -0
  68. {graphiti_core-0.12.0rc1.dist-info → graphiti_core-0.24.3.dist-info/licenses}/LICENSE +0 -0
@@ -43,7 +43,9 @@ async def extract_edge_dates(
43
43
  'reference_timestamp': current_episode.valid_at.isoformat(),
44
44
  }
45
45
  llm_response = await llm_client.generate_response(
46
- prompt_library.extract_edge_dates.v1(context), response_model=EdgeDates
46
+ prompt_library.extract_edge_dates.v1(context),
47
+ response_model=EdgeDates,
48
+ prompt_name='extract_edge_dates.v1',
47
49
  )
48
50
 
49
51
  valid_at = llm_response.get('valid_at')
@@ -70,7 +72,9 @@ async def extract_edge_dates(
70
72
 
71
73
 
72
74
  async def get_edge_contradictions(
73
- llm_client: LLMClient, new_edge: EntityEdge, existing_edges: list[EntityEdge]
75
+ llm_client: LLMClient,
76
+ new_edge: EntityEdge,
77
+ existing_edges: list[EntityEdge],
74
78
  ) -> list[EntityEdge]:
75
79
  start = time()
76
80
 
@@ -79,12 +83,16 @@ async def get_edge_contradictions(
79
83
  {'id': i, 'fact': existing_edge.fact} for i, existing_edge in enumerate(existing_edges)
80
84
  ]
81
85
 
82
- context = {'new_edge': new_edge_context, 'existing_edges': existing_edge_context}
86
+ context = {
87
+ 'new_edge': new_edge_context,
88
+ 'existing_edges': existing_edge_context,
89
+ }
83
90
 
84
91
  llm_response = await llm_client.generate_response(
85
92
  prompt_library.invalidate_edges.v2(context),
86
93
  response_model=InvalidatedEdges,
87
94
  model_size=ModelSize.small,
95
+ prompt_name='invalidate_edges.v2',
88
96
  )
89
97
 
90
98
  contradicted_facts: list[int] = llm_response.get('contradicted_facts', [])
@@ -21,7 +21,7 @@ from graphiti_core.nodes import EntityNode
21
21
 
22
22
 
23
23
  def validate_entity_types(
24
- entity_types: dict[str, BaseModel] | None,
24
+ entity_types: dict[str, type[BaseModel]] | None,
25
25
  ) -> bool:
26
26
  if entity_types is None:
27
27
  return True
@@ -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 = 500
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()