graphiti-core 0.9.4__py3-none-any.whl → 0.9.5__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/graphiti.py CHANGED
@@ -33,6 +33,7 @@ from graphiti_core.nodes import CommunityNode, EntityNode, EpisodeType, Episodic
33
33
  from graphiti_core.search.search import SearchConfig, search
34
34
  from graphiti_core.search.search_config import DEFAULT_SEARCH_LIMIT, SearchResults
35
35
  from graphiti_core.search.search_config_recipes import (
36
+ COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
36
37
  EDGE_HYBRID_SEARCH_NODE_DISTANCE,
37
38
  EDGE_HYBRID_SEARCH_RRF,
38
39
  )
@@ -647,7 +648,10 @@ class Graphiti:
647
648
  Perform a hybrid search on the knowledge graph.
648
649
 
649
650
  This method executes a search query on the graph, combining vector and
650
- text-based search techniques to retrieve relevant facts.
651
+ text-based search techniques to retrieve relevant facts, returning the edges as a string.
652
+
653
+ This is our basic out-of-the-box search, for more robust results we recommend using our more advanced
654
+ search method graphiti.search_().
651
655
 
652
656
  Parameters
653
657
  ----------
@@ -668,8 +672,7 @@ class Graphiti:
668
672
  Notes
669
673
  -----
670
674
  This method uses a SearchConfig with num_episodes set to 0 and
671
- num_results set to the provided num_results parameter. It then calls
672
- the hybrid_search function to perform the actual search operation.
675
+ num_results set to the provided num_results parameter.
673
676
 
674
677
  The search is performed using the current date and time as the reference
675
678
  point for temporal relevance.
@@ -703,6 +706,27 @@ class Graphiti:
703
706
  bfs_origin_node_uuids: list[str] | None = None,
704
707
  search_filter: SearchFilters | None = None,
705
708
  ) -> SearchResults:
709
+ """DEPRECATED"""
710
+ return await self.search_(
711
+ query, config, group_ids, center_node_uuid, bfs_origin_node_uuids, search_filter
712
+ )
713
+
714
+ async def search_(
715
+ self,
716
+ query: str,
717
+ config: SearchConfig = COMBINED_HYBRID_SEARCH_CROSS_ENCODER,
718
+ group_ids: list[str] | None = None,
719
+ center_node_uuid: str | None = None,
720
+ bfs_origin_node_uuids: list[str] | None = None,
721
+ search_filter: SearchFilters | None = None,
722
+ ) -> SearchResults:
723
+ """search_ (replaces _search) is our advanced search method that returns Graph objects (nodes and edges) rather
724
+ than a list of facts. This endpoint allows the end user to utilize more advanced features such as filters and
725
+ different search and reranker methodologies across different layers in the graph.
726
+
727
+ For different config recipes refer to search/search_config_recipes.
728
+ """
729
+
706
730
  return await search(
707
731
  self.driver,
708
732
  self.embedder,
@@ -26,7 +26,7 @@ from graphiti_core.search.search_utils import (
26
26
  MAX_SEARCH_DEPTH,
27
27
  )
28
28
 
29
- DEFAULT_SEARCH_LIMIT = 10
29
+ DEFAULT_SEARCH_LIMIT = 20
30
30
 
31
31
 
32
32
  class EdgeSearchMethod(Enum):
@@ -0,0 +1,47 @@
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 graphiti_core.edges import EntityEdge
18
+ from graphiti_core.search.search_config import SearchResults
19
+
20
+
21
+ def format_edge_date_range(edge: EntityEdge) -> str:
22
+ # return f"{datetime(edge.valid_at).strftime('%Y-%m-%d %H:%M:%S') if edge.valid_at else 'date unknown'} - {(edge.invalid_at.strftime('%Y-%m-%d %H:%M:%S') if edge.invalid_at else 'present')}"
23
+ return f'{edge.valid_at if edge.valid_at else "date unknown"} - {(edge.invalid_at if edge.invalid_at else "present")}'
24
+
25
+
26
+ def search_results_to_context_string(search_results: SearchResults) -> str:
27
+ """Reformats a set of SearchResults into a single string to pass directly to an LLM as context"""
28
+ context_string = """FACTS and ENTITIES represent relevant context to the current conversation.
29
+ COMMUNITIES represent a cluster of closely related entities.
30
+
31
+ # These are the most relevant facts and their valid date ranges
32
+ # format: FACT (Date range: from - to)
33
+ """
34
+ context_string += '<FACTS>\n'
35
+ for edge in search_results.edges:
36
+ context_string += f'- {edge.fact} ({format_edge_date_range(edge)})\n'
37
+ context_string += '</FACTS>\n'
38
+ context_string += '<ENTITIES>\n'
39
+ for node in search_results.nodes:
40
+ context_string += f'- {node.name}: {node.summary}\n'
41
+ context_string += '</ENTITIES>\n'
42
+ context_string += '<COMMUNITIES>\n'
43
+ for community in search_results.communities:
44
+ context_string += f'- {community.name}: {community.summary}\n'
45
+ context_string += '</COMMUNITIES>\n'
46
+
47
+ return context_string
@@ -229,8 +229,8 @@ async def edge_similarity_search(
229
229
 
230
230
  query: LiteralString = (
231
231
  """
232
- MATCH (n:Entity)-[r:RELATES_TO]->(m:Entity)
233
- """
232
+ MATCH (n:Entity)-[r:RELATES_TO]->(m:Entity)
233
+ """
234
234
  + group_filter_query
235
235
  + filter_query
236
236
  + """\nWITH DISTINCT r, vector.similarity.cosine(r.fact_embedding, $search_vector) AS score
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: graphiti-core
3
- Version: 0.9.4
3
+ Version: 0.9.5
4
4
  Summary: A temporal graph building library
5
5
  License: Apache-2.0
6
6
  Author: Paul Paliychuk
@@ -18,6 +18,7 @@ Provides-Extra: groq
18
18
  Requires-Dist: anthropic (>=0.49.0) ; extra == "anthropic"
19
19
  Requires-Dist: diskcache (>=5.6.3)
20
20
  Requires-Dist: google-genai (>=1.8.0) ; extra == "google-genai"
21
+ Requires-Dist: graph-service (>=1.0.0.7,<2.0.0.0)
21
22
  Requires-Dist: groq (>=0.2.0) ; extra == "groq"
22
23
  Requires-Dist: neo4j (>=5.23.0)
23
24
  Requires-Dist: numpy (>=1.0.0)
@@ -10,7 +10,7 @@ graphiti_core/embedder/gemini.py,sha256=nE0XH8wYVGcPSO7DaNQ7kdsQLFSoH4FQOu2HMQUy
10
10
  graphiti_core/embedder/openai.py,sha256=fcU63koSRI-OjDuEcBfUKgXu8XV_-8EF6HpVrYa1_8I,1880
11
11
  graphiti_core/embedder/voyage.py,sha256=DZsH1nSTfP1vqCinNIIwSyEzv7jsyur2tKxlBv-ZZ_E,1902
12
12
  graphiti_core/errors.py,sha256=Nib1uQx2cO_VOizupmRjpFfmuRg-hFAVqTtZAuBehR8,2405
13
- graphiti_core/graphiti.py,sha256=Jztk1PGsr15FkJhf-mFYgFGF40tTMQHPUq96kdWz6c8,29726
13
+ graphiti_core/graphiti.py,sha256=ykV9YARsGFHRYg6wxSHzqGKV8Gm7ZU8P5opJxYDAV8I,30794
14
14
  graphiti_core/helpers.py,sha256=7BQzUBFmoBDA2OIDdFtoN4W-vXOhPRIsF0uDb7PsNi0,2913
15
15
  graphiti_core/llm_client/__init__.py,sha256=PA80TSMeX-sUXITXEAxMDEt3gtfZgcJrGJUcyds1mSo,207
16
16
  graphiti_core/llm_client/anthropic_client.py,sha256=dTM8rKhk9TZAU4O-0jFMivOwJvWM-gHpp5gLmuJHiGQ,2723
@@ -43,10 +43,11 @@ graphiti_core/prompts/summarize_nodes.py,sha256=PeA1Taov5KBNNBKgrCPeF1tLg4_SMgT-
43
43
  graphiti_core/py.typed,sha256=vlmmzQOt7bmeQl9L3XJP4W6Ry0iiELepnOrinKz5KQg,79
44
44
  graphiti_core/search/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  graphiti_core/search/search.py,sha256=DX-tcIa0SiKI2HX-b_WdjGE74A8RLWQor4p90dJluUA,12643
46
- graphiti_core/search/search_config.py,sha256=UZN8jFA4pBlw2O5N1cuhVRBdTwMLR9N3Oyo6sQ4MDVw,3117
46
+ graphiti_core/search/search_config.py,sha256=Yn_p1cnMwtZAdIOga19iaCoS7FmA95-GLN7KmHd-7N0,3117
47
47
  graphiti_core/search/search_config_recipes.py,sha256=yUqiLnn9vFg39M8eVwjVKfBCL_ptGrfDMQ47m_Blb0g,6885
48
48
  graphiti_core/search/search_filters.py,sha256=JkP7NbM4Dor27dne5vAuxbJic12dIJDtWJxNqmVuRec,5884
49
- graphiti_core/search/search_utils.py,sha256=Bywp7trqP_gEwqH8I-JHuj3Mljw9P2K6_XooXI75jHI,25739
49
+ graphiti_core/search/search_helpers.py,sha256=Tt5rRUfblBlFqV7r8XuGZiT5P_wjlh01xS0feELZjXg,2173
50
+ graphiti_core/search/search_utils.py,sha256=4i5Uwp6iNz849njIf89jOgI2NDtSFHQ_grnZpLSNv0I,25771
50
51
  graphiti_core/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
52
  graphiti_core/utils/bulk_utils.py,sha256=P4LKO46Yle4tBdNcQ3hDHcSQFaR8UBLfoL-z1M2Wua0,14690
52
53
  graphiti_core/utils/datetime_utils.py,sha256=Ti-2tnrDFRzBsbfblzsHybsM3jaDLP4-VT2t0VhpIzU,1357
@@ -58,7 +59,7 @@ graphiti_core/utils/maintenance/node_operations.py,sha256=WhZQixx05dAFFQAd5KTXJ8
58
59
  graphiti_core/utils/maintenance/temporal_operations.py,sha256=RdNtubCyYhOVrvcOIq2WppHls1Q-BEjtsN8r38l-Rtc,3691
59
60
  graphiti_core/utils/maintenance/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
61
  graphiti_core/utils/ontology_utils/entity_types_utils.py,sha256=QJX5cG0GSSNF_Mm_yrldr69wjVAbN_MxLhOSznz85Hk,1279
61
- graphiti_core-0.9.4.dist-info/LICENSE,sha256=KCUwCyDXuVEgmDWkozHyniRyWjnWUWjkuDHfU6o3JlA,11325
62
- graphiti_core-0.9.4.dist-info/METADATA,sha256=wl7sIqZBszdCc_7go_qGyGTJCktv6xikxjlrWRedtn8,14344
63
- graphiti_core-0.9.4.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
64
- graphiti_core-0.9.4.dist-info/RECORD,,
62
+ graphiti_core-0.9.5.dist-info/LICENSE,sha256=KCUwCyDXuVEgmDWkozHyniRyWjnWUWjkuDHfU6o3JlA,11325
63
+ graphiti_core-0.9.5.dist-info/METADATA,sha256=ptj44vyxZwC9xQmIsnEeKGTpUniDD4fLz7gRKMAXqI4,14394
64
+ graphiti_core-0.9.5.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
65
+ graphiti_core-0.9.5.dist-info/RECORD,,