-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathclient.py
More file actions
2024 lines (1609 loc) · 62.2 KB
/
client.py
File metadata and controls
2024 lines (1609 loc) · 62.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was auto-generated by Fern from our API Definition.
import typing
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.add_triple_response import AddTripleResponse
from ..types.clone_graph_response import CloneGraphResponse
from ..types.custom_instruction import CustomInstruction
from ..types.detect_config import DetectConfig
from ..types.detect_patterns_response import DetectPatternsResponse
from ..types.edge_type import EdgeType
from ..types.entity_type import EntityType
from ..types.entity_type_response import EntityTypeResponse
from ..types.episode import Episode
from ..types.episode_data import EpisodeData
from ..types.graph import Graph
from ..types.graph_data_type import GraphDataType
from ..types.graph_list_response import GraphListResponse
from ..types.graph_search_results import GraphSearchResults
from ..types.graph_search_scope import GraphSearchScope
from ..types.list_custom_instructions_response import ListCustomInstructionsResponse
from ..types.pattern_seeds import PatternSeeds
from ..types.recency_weight import RecencyWeight
from ..types.reranker import Reranker
from ..types.search_filters import SearchFilters
from ..types.success_response import SuccessResponse
from .edge.client import AsyncEdgeClient, EdgeClient
from .episode.client import AsyncEpisodeClient, EpisodeClient
from .node.client import AsyncNodeClient, NodeClient
from .raw_client import AsyncRawGraphClient, RawGraphClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class GraphClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawGraphClient(client_wrapper=client_wrapper)
self.edge = EdgeClient(client_wrapper=client_wrapper)
self.episode = EpisodeClient(client_wrapper=client_wrapper)
self.node = NodeClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> RawGraphClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawGraphClient
"""
return self._raw_client
def list_custom_instructions(
self,
*,
user_id: typing.Optional[str] = None,
graph_id: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ListCustomInstructionsResponse:
"""
Lists all custom instructions for a project, user, or graph.
Parameters
----------
user_id : typing.Optional[str]
User ID to get user-specific instructions
graph_id : typing.Optional[str]
Graph ID to get graph-specific instructions
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ListCustomInstructionsResponse
The list of instructions.
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.list_custom_instructions(
user_id="user_id",
graph_id="graph_id",
)
"""
_response = self._raw_client.list_custom_instructions(
user_id=user_id, graph_id=graph_id, request_options=request_options
)
return _response.data
def add_custom_instructions(
self,
*,
instructions: typing.Sequence[CustomInstruction],
graph_ids: typing.Optional[typing.Sequence[str]] = OMIT,
user_ids: typing.Optional[typing.Sequence[str]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SuccessResponse:
"""
Adds new custom instructions for graphs without removing existing ones. If user_ids or graph_ids is empty, adds to project-wide default instructions.
Parameters
----------
instructions : typing.Sequence[CustomInstruction]
Instructions to add to the graph.
graph_ids : typing.Optional[typing.Sequence[str]]
Graph IDs to add the instructions to. If empty, the instructions are added to the project-wide default.
user_ids : typing.Optional[typing.Sequence[str]]
User IDs to add the instructions to. If empty, the instructions are added to the project-wide default.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SuccessResponse
Instructions added successfully
Examples
--------
from zep_cloud import CustomInstruction, Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.add_custom_instructions(
instructions=[
CustomInstruction(
name="name",
text="text",
)
],
)
"""
_response = self._raw_client.add_custom_instructions(
instructions=instructions, graph_ids=graph_ids, user_ids=user_ids, request_options=request_options
)
return _response.data
def delete_custom_instructions(
self,
*,
graph_ids: typing.Optional[typing.Sequence[str]] = OMIT,
instruction_names: typing.Optional[typing.Sequence[str]] = OMIT,
user_ids: typing.Optional[typing.Sequence[str]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SuccessResponse:
"""
Deletes custom instructions for graphs or project wide defaults.
Parameters
----------
graph_ids : typing.Optional[typing.Sequence[str]]
Determines which group graphs will have their custom instructions deleted. If no graphs are provided, the project-wide custom instructions will be affected.
instruction_names : typing.Optional[typing.Sequence[str]]
Unique identifier for the instructions to be deleted. If empty deletes all instructions.
user_ids : typing.Optional[typing.Sequence[str]]
Determines which user graphs will have their custom instructions deleted. If no users are provided, the project-wide custom instructions will be affected.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SuccessResponse
Instructions deleted successfully
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.delete_custom_instructions()
"""
_response = self._raw_client.delete_custom_instructions(
graph_ids=graph_ids, instruction_names=instruction_names, user_ids=user_ids, request_options=request_options
)
return _response.data
def list_entity_types(
self,
*,
user_id: typing.Optional[str] = None,
graph_id: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> EntityTypeResponse:
"""
Returns all entity types for a project, user, or graph.
Parameters
----------
user_id : typing.Optional[str]
User ID to get user-specific entity types
graph_id : typing.Optional[str]
Graph ID to get graph-specific entity types
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
EntityTypeResponse
The list of entity types.
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.list_entity_types(
user_id="user_id",
graph_id="graph_id",
)
"""
_response = self._raw_client.list_entity_types(
user_id=user_id, graph_id=graph_id, request_options=request_options
)
return _response.data
def set_entity_types_internal(
self,
*,
edge_types: typing.Optional[typing.Sequence[EdgeType]] = OMIT,
entity_types: typing.Optional[typing.Sequence[EntityType]] = OMIT,
graph_ids: typing.Optional[typing.Sequence[str]] = OMIT,
user_ids: typing.Optional[typing.Sequence[str]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SuccessResponse:
"""
Sets the entity types for multiple users and graphs, replacing any existing ones.
Parameters
----------
edge_types : typing.Optional[typing.Sequence[EdgeType]]
entity_types : typing.Optional[typing.Sequence[EntityType]]
graph_ids : typing.Optional[typing.Sequence[str]]
user_ids : typing.Optional[typing.Sequence[str]]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SuccessResponse
Entity types set successfully
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.set_entity_types_internal()
"""
_response = self._raw_client.set_entity_types_internal(
edge_types=edge_types,
entity_types=entity_types,
graph_ids=graph_ids,
user_ids=user_ids,
request_options=request_options,
)
return _response.data
def add(
self,
*,
data: str,
type: GraphDataType,
created_at: typing.Optional[str] = OMIT,
graph_id: typing.Optional[str] = OMIT,
source_description: typing.Optional[str] = OMIT,
user_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> Episode:
"""
Add data to the graph.
Parameters
----------
data : str
type : GraphDataType
created_at : typing.Optional[str]
graph_id : typing.Optional[str]
graph_id is the ID of the graph to which the data will be added. If adding to the user graph, please use user_id field instead.
source_description : typing.Optional[str]
user_id : typing.Optional[str]
User ID is the ID of the user to which the data will be added. If not adding to a user graph, please use graph_id field instead.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
Episode
Added episode
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.add(
data="data",
type="text",
)
"""
_response = self._raw_client.add(
data=data,
type=type,
created_at=created_at,
graph_id=graph_id,
source_description=source_description,
user_id=user_id,
request_options=request_options,
)
return _response.data
def add_batch(
self,
*,
episodes: typing.Sequence[EpisodeData],
graph_id: typing.Optional[str] = OMIT,
user_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.List[Episode]:
"""
Add data to the graph in batch mode. Episodes are processed sequentially in the order provided.
Parameters
----------
episodes : typing.Sequence[EpisodeData]
graph_id : typing.Optional[str]
graph_id is the ID of the graph to which the data will be added. If adding to the user graph, please use user_id field instead.
user_id : typing.Optional[str]
User ID is the ID of the user to which the data will be added. If not adding to a user graph, please use graph_id field instead.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.List[Episode]
Added episodes
Examples
--------
from zep_cloud import EpisodeData, Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.add_batch(
episodes=[
EpisodeData(
data="data",
type="text",
)
],
)
"""
_response = self._raw_client.add_batch(
episodes=episodes, graph_id=graph_id, user_id=user_id, request_options=request_options
)
return _response.data
def add_fact_triple(
self,
*,
fact: str,
fact_name: str,
created_at: typing.Optional[str] = OMIT,
edge_attributes: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
expired_at: typing.Optional[str] = OMIT,
fact_uuid: typing.Optional[str] = OMIT,
graph_id: typing.Optional[str] = OMIT,
invalid_at: typing.Optional[str] = OMIT,
source_node_attributes: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
source_node_labels: typing.Optional[typing.Sequence[str]] = OMIT,
source_node_name: typing.Optional[str] = OMIT,
source_node_summary: typing.Optional[str] = OMIT,
source_node_uuid: typing.Optional[str] = OMIT,
target_node_attributes: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
target_node_labels: typing.Optional[typing.Sequence[str]] = OMIT,
target_node_name: typing.Optional[str] = OMIT,
target_node_summary: typing.Optional[str] = OMIT,
target_node_uuid: typing.Optional[str] = OMIT,
user_id: typing.Optional[str] = OMIT,
valid_at: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddTripleResponse:
"""
Add a fact triple for a user or group
Parameters
----------
fact : str
The fact relating the two nodes that this edge represents
fact_name : str
The name of the edge to add. Should be all caps using snake case (eg RELATES_TO)
created_at : typing.Optional[str]
The timestamp of the message
edge_attributes : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Additional attributes of the edge. Values must be scalar types (string, number, boolean, or null).
Nested objects and arrays are not allowed.
expired_at : typing.Optional[str]
The time (if any) at which the edge expires
fact_uuid : typing.Optional[str]
The uuid of the edge to add
graph_id : typing.Optional[str]
invalid_at : typing.Optional[str]
The time (if any) at which the fact stops being true
source_node_attributes : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Additional attributes of the source node. Values must be scalar types (string, number, boolean, or null).
Nested objects and arrays are not allowed.
source_node_labels : typing.Optional[typing.Sequence[str]]
The labels for the source node
source_node_name : typing.Optional[str]
The name of the source node to add
source_node_summary : typing.Optional[str]
The summary of the source node to add
source_node_uuid : typing.Optional[str]
The source node uuid
target_node_attributes : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
Additional attributes of the target node. Values must be scalar types (string, number, boolean, or null).
Nested objects and arrays are not allowed.
target_node_labels : typing.Optional[typing.Sequence[str]]
The labels for the target node
target_node_name : typing.Optional[str]
The name of the target node to add
target_node_summary : typing.Optional[str]
The summary of the target node to add
target_node_uuid : typing.Optional[str]
The target node uuid
user_id : typing.Optional[str]
valid_at : typing.Optional[str]
The time at which the fact becomes true
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddTripleResponse
Resulting triple
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.add_fact_triple(
fact="fact",
fact_name="fact_name",
)
"""
_response = self._raw_client.add_fact_triple(
fact=fact,
fact_name=fact_name,
created_at=created_at,
edge_attributes=edge_attributes,
expired_at=expired_at,
fact_uuid=fact_uuid,
graph_id=graph_id,
invalid_at=invalid_at,
source_node_attributes=source_node_attributes,
source_node_labels=source_node_labels,
source_node_name=source_node_name,
source_node_summary=source_node_summary,
source_node_uuid=source_node_uuid,
target_node_attributes=target_node_attributes,
target_node_labels=target_node_labels,
target_node_name=target_node_name,
target_node_summary=target_node_summary,
target_node_uuid=target_node_uuid,
user_id=user_id,
valid_at=valid_at,
request_options=request_options,
)
return _response.data
def clone(
self,
*,
source_graph_id: typing.Optional[str] = OMIT,
source_user_id: typing.Optional[str] = OMIT,
target_graph_id: typing.Optional[str] = OMIT,
target_user_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CloneGraphResponse:
"""
Clone a user or group graph.
Parameters
----------
source_graph_id : typing.Optional[str]
source_graph_id is the ID of the graph to be cloned. Required if source_user_id is not provided
source_user_id : typing.Optional[str]
user_id of the user whose graph is being cloned. Required if source_graph_id is not provided
target_graph_id : typing.Optional[str]
target_graph_id is the ID to be set on the cloned graph. Must not point to an existing graph. Required if target_user_id is not provided.
target_user_id : typing.Optional[str]
user_id to be set on the cloned user. Must not point to an existing user. Required if target_graph_id is not provided.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CloneGraphResponse
Response object containing graph_id or user_id pointing to the new graph
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.clone()
"""
_response = self._raw_client.clone(
source_graph_id=source_graph_id,
source_user_id=source_user_id,
target_graph_id=target_graph_id,
target_user_id=target_user_id,
request_options=request_options,
)
return _response.data
def create(
self,
*,
graph_id: str,
description: typing.Optional[str] = OMIT,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> Graph:
"""
Creates a new graph.
Parameters
----------
graph_id : str
description : typing.Optional[str]
name : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
Graph
The added graph
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.create(
graph_id="graph_id",
)
"""
_response = self._raw_client.create(
graph_id=graph_id, description=description, name=name, request_options=request_options
)
return _response.data
def list_all(
self,
*,
page_number: typing.Optional[int] = None,
page_size: typing.Optional[int] = None,
order_by: typing.Optional[str] = None,
asc: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GraphListResponse:
"""
Returns all graphs. In order to list users, use user.list_ordered instead
Parameters
----------
page_number : typing.Optional[int]
Page number for pagination, starting from 1.
page_size : typing.Optional[int]
Number of graphs to retrieve per page.
order_by : typing.Optional[str]
Column to sort by (created_at, group_id, name).
asc : typing.Optional[bool]
Sort in ascending order.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GraphListResponse
Successfully retrieved list of graphs.
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.list_all(
page_number=1,
page_size=1,
order_by="order_by",
asc=True,
)
"""
_response = self._raw_client.list_all(
page_number=page_number, page_size=page_size, order_by=order_by, asc=asc, request_options=request_options
)
return _response.data
def detect_patterns(
self,
*,
detect: typing.Optional[DetectConfig] = OMIT,
edge_limit: typing.Optional[int] = OMIT,
graph_id: typing.Optional[str] = OMIT,
limit: typing.Optional[int] = OMIT,
min_occurrences: typing.Optional[int] = OMIT,
query: typing.Optional[str] = OMIT,
query_limit: typing.Optional[int] = OMIT,
recency_weight: typing.Optional[RecencyWeight] = OMIT,
search_filters: typing.Optional[SearchFilters] = OMIT,
seeds: typing.Optional[PatternSeeds] = OMIT,
user_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> DetectPatternsResponse:
"""
Detects structural patterns in a knowledge graph including relationship frequencies,
multi-hop paths, co-occurrences, hubs, and clusters.
When a query is provided, uses hybrid search to discover seed nodes,
detects triple-frequency patterns, and returns resolved edges ranked by relevance.
Parameters
----------
detect : typing.Optional[DetectConfig]
Which pattern types to detect with type-specific configuration.
Omit to detect all types with defaults. Ignored when query is set.
edge_limit : typing.Optional[int]
Max resolved edges per pattern. Default: 10, Max: 100. Only used with query.
graph_id : typing.Optional[str]
Graph ID when detecting patterns on a named graph
limit : typing.Optional[int]
Max patterns to return. Default: 50, Max: 200
min_occurrences : typing.Optional[int]
Minimum occurrence count to report a pattern. Default: 2
query : typing.Optional[str]
Search query for discovering seed nodes via hybrid search.
When set, forces triple-frequency detection only and enables edge resolution
with cross-encoder reranking. Mutually exclusive with seeds.
query_limit : typing.Optional[int]
Max seed nodes from search. Default: 10, Max: 50. Only used with query.
recency_weight : typing.Optional[RecencyWeight]
Exponential half-life decay applied to edge created_at timestamps.
Valid values: none, 7_days, 30_days, 90_days. Default: none
search_filters : typing.Optional[SearchFilters]
Filters which edges/nodes participate in pattern detection.
Reuses the same filter format as /graph/search.
seeds : typing.Optional[PatternSeeds]
Seed selection. If omitted, analyzes the entire graph. Mutually exclusive with query.
user_id : typing.Optional[str]
User ID when detecting patterns on a user graph
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
DetectPatternsResponse
Detected patterns
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.detect_patterns()
"""
_response = self._raw_client.detect_patterns(
detect=detect,
edge_limit=edge_limit,
graph_id=graph_id,
limit=limit,
min_occurrences=min_occurrences,
query=query,
query_limit=query_limit,
recency_weight=recency_weight,
search_filters=search_filters,
seeds=seeds,
user_id=user_id,
request_options=request_options,
)
return _response.data
def search(
self,
*,
query: str,
bfs_origin_node_uuids: typing.Optional[typing.Sequence[str]] = OMIT,
center_node_uuid: typing.Optional[str] = OMIT,
graph_id: typing.Optional[str] = OMIT,
limit: typing.Optional[int] = OMIT,
mmr_lambda: typing.Optional[float] = OMIT,
reranker: typing.Optional[Reranker] = OMIT,
scope: typing.Optional[GraphSearchScope] = OMIT,
search_filters: typing.Optional[SearchFilters] = OMIT,
user_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> GraphSearchResults:
"""
Perform a graph search query.
Parameters
----------
query : str
The string to search for (required)
bfs_origin_node_uuids : typing.Optional[typing.Sequence[str]]
Nodes that are the origins of the BFS searches
center_node_uuid : typing.Optional[str]
Node to rerank around for node distance reranking
graph_id : typing.Optional[str]
The graph_id to search in. When searching user graph, please use user_id instead.
limit : typing.Optional[int]
The maximum number of facts to retrieve. Defaults to 10. Limited to 50.
mmr_lambda : typing.Optional[float]
weighting for maximal marginal relevance
reranker : typing.Optional[Reranker]
Defaults to RRF
scope : typing.Optional[GraphSearchScope]
Defaults to Edges. Communities will be added in the future.
search_filters : typing.Optional[SearchFilters]
Search filters to apply to the search
user_id : typing.Optional[str]
The user_id when searching user graph. If not searching user graph, please use graph_id instead.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GraphSearchResults
Graph search results
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.search(
query="query",
)
"""
_response = self._raw_client.search(
query=query,
bfs_origin_node_uuids=bfs_origin_node_uuids,
center_node_uuid=center_node_uuid,
graph_id=graph_id,
limit=limit,
mmr_lambda=mmr_lambda,
reranker=reranker,
scope=scope,
search_filters=search_filters,
user_id=user_id,
request_options=request_options,
)
return _response.data
def get(self, graph_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Graph:
"""
Returns a graph.
Parameters
----------
graph_id : str
The graph_id of the graph to get.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
Graph
The graph that was retrieved.
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.get(
graph_id="graphId",
)
"""
_response = self._raw_client.get(graph_id, request_options=request_options)
return _response.data
def delete(self, graph_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> SuccessResponse:
"""
Deletes a graph. If you would like to delete a user graph, make sure to use user.delete instead.
Parameters
----------
graph_id : str
Graph ID
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SuccessResponse
Deleted
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.delete(
graph_id="graphId",
)
"""
_response = self._raw_client.delete(graph_id, request_options=request_options)
return _response.data
def update(
self,
graph_id: str,
*,
description: typing.Optional[str] = OMIT,
name: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> Graph:
"""
Updates information about a graph.
Parameters
----------
graph_id : str
Graph ID
description : typing.Optional[str]
name : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
Graph
The updated graph object
Examples
--------
from zep_cloud import Zep
client = Zep(
api_key="YOUR_API_KEY",
)
client.graph.update(
graph_id="graphId",
)
"""
_response = self._raw_client.update(
graph_id, description=description, name=name, request_options=request_options
)
return _response.data
class AsyncGraphClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawGraphClient(client_wrapper=client_wrapper)
self.edge = AsyncEdgeClient(client_wrapper=client_wrapper)
self.episode = AsyncEpisodeClient(client_wrapper=client_wrapper)
self.node = AsyncNodeClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> AsyncRawGraphClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawGraphClient
"""
return self._raw_client
async def list_custom_instructions(
self,
*,
user_id: typing.Optional[str] = None,
graph_id: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> ListCustomInstructionsResponse:
"""
Lists all custom instructions for a project, user, or graph.
Parameters
----------
user_id : typing.Optional[str]
User ID to get user-specific instructions