orca-sdk 0.1.4__py3-none-any.whl → 0.1.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.
- orca_sdk/_shared/metrics.py +179 -40
- orca_sdk/_shared/metrics_test.py +99 -6
- orca_sdk/_utils/data_parsing_test.py +1 -1
- orca_sdk/async_client.py +14 -0
- orca_sdk/classification_model.py +105 -26
- orca_sdk/classification_model_test.py +327 -8
- orca_sdk/client.py +14 -0
- orca_sdk/conftest.py +140 -21
- orca_sdk/memoryset.py +141 -26
- orca_sdk/memoryset_test.py +253 -4
- orca_sdk/regression_model.py +73 -16
- orca_sdk/regression_model_test.py +213 -0
- {orca_sdk-0.1.4.dist-info → orca_sdk-0.1.5.dist-info}/METADATA +1 -1
- {orca_sdk-0.1.4.dist-info → orca_sdk-0.1.5.dist-info}/RECORD +15 -15
- {orca_sdk-0.1.4.dist-info → orca_sdk-0.1.5.dist-info}/WHEEL +0 -0
orca_sdk/memoryset.py
CHANGED
|
@@ -114,7 +114,7 @@ Examples:
|
|
|
114
114
|
|
|
115
115
|
IndexType = Literal["FLAT", "IVF_FLAT", "IVF_SQ8", "IVF_PQ", "HNSW", "DISKANN"]
|
|
116
116
|
|
|
117
|
-
DEFAULT_COLUMN_NAMES = {"value", "source_id"}
|
|
117
|
+
DEFAULT_COLUMN_NAMES = {"value", "source_id", "partition_id"}
|
|
118
118
|
TYPE_SPECIFIC_COLUMN_NAMES = {"label", "score"}
|
|
119
119
|
FORBIDDEN_METADATA_COLUMN_NAMES = {
|
|
120
120
|
"memory_id",
|
|
@@ -194,8 +194,11 @@ def _parse_memory_insert(memory: dict[str, Any], type: MemoryType) -> LabeledMem
|
|
|
194
194
|
if not isinstance(value, str):
|
|
195
195
|
raise ValueError("Memory value must be a string")
|
|
196
196
|
source_id = memory.get("source_id")
|
|
197
|
-
if source_id and not isinstance(source_id, str):
|
|
197
|
+
if source_id is not None and not isinstance(source_id, str):
|
|
198
198
|
raise ValueError("Memory source_id must be a string")
|
|
199
|
+
partition_id = memory.get("partition_id")
|
|
200
|
+
if partition_id is not None and not isinstance(partition_id, str):
|
|
201
|
+
raise ValueError("Memory partition_id must be a string")
|
|
199
202
|
match type:
|
|
200
203
|
case "LABELED":
|
|
201
204
|
label = memory.get("label")
|
|
@@ -206,7 +209,13 @@ def _parse_memory_insert(memory: dict[str, Any], type: MemoryType) -> LabeledMem
|
|
|
206
209
|
raise ValueError(
|
|
207
210
|
f"The following column names are reserved: {', '.join(FORBIDDEN_METADATA_COLUMN_NAMES)}"
|
|
208
211
|
)
|
|
209
|
-
return {
|
|
212
|
+
return {
|
|
213
|
+
"value": value,
|
|
214
|
+
"label": label,
|
|
215
|
+
"source_id": source_id,
|
|
216
|
+
"partition_id": partition_id,
|
|
217
|
+
"metadata": metadata,
|
|
218
|
+
}
|
|
210
219
|
case "SCORED":
|
|
211
220
|
score = memory.get("score")
|
|
212
221
|
if score is not None and not isinstance(score, (int, float)):
|
|
@@ -216,7 +225,13 @@ def _parse_memory_insert(memory: dict[str, Any], type: MemoryType) -> LabeledMem
|
|
|
216
225
|
raise ValueError(
|
|
217
226
|
f"The following column names are reserved: {', '.join(FORBIDDEN_METADATA_COLUMN_NAMES)}"
|
|
218
227
|
)
|
|
219
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
"value": value,
|
|
230
|
+
"score": score,
|
|
231
|
+
"source_id": source_id,
|
|
232
|
+
"partition_id": partition_id,
|
|
233
|
+
"metadata": metadata,
|
|
234
|
+
}
|
|
220
235
|
|
|
221
236
|
|
|
222
237
|
def _parse_memory_update(update: dict[str, Any], type: MemoryType) -> LabeledMemoryUpdate | ScoredMemoryUpdate:
|
|
@@ -231,9 +246,15 @@ def _parse_memory_update(update: dict[str, Any], type: MemoryType) -> LabeledMem
|
|
|
231
246
|
raise ValueError("value must be a string or unset")
|
|
232
247
|
payload["value"] = update["value"]
|
|
233
248
|
if "source_id" in update:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
249
|
+
source_id = update["source_id"]
|
|
250
|
+
if source_id is not None and not isinstance(source_id, str):
|
|
251
|
+
raise ValueError("source_id must be a string or None")
|
|
252
|
+
payload["source_id"] = source_id
|
|
253
|
+
if "partition_id" in update:
|
|
254
|
+
partition_id = update["partition_id"]
|
|
255
|
+
if partition_id is not None and not isinstance(partition_id, str):
|
|
256
|
+
raise ValueError("partition_id must be a string or None")
|
|
257
|
+
payload["partition_id"] = partition_id
|
|
237
258
|
match type:
|
|
238
259
|
case "LABELED":
|
|
239
260
|
payload = cast(LabeledMemoryUpdate, payload)
|
|
@@ -267,6 +288,7 @@ class MemoryBase(ABC):
|
|
|
267
288
|
value: str
|
|
268
289
|
embedding: list[float]
|
|
269
290
|
source_id: str | None
|
|
291
|
+
partition_id: str | None
|
|
270
292
|
created_at: datetime
|
|
271
293
|
updated_at: datetime
|
|
272
294
|
metadata: dict[str, str | float | int | bool | None]
|
|
@@ -298,6 +320,7 @@ class MemoryBase(ABC):
|
|
|
298
320
|
self.value = cast(str, memory["value"])
|
|
299
321
|
self.embedding = memory["embedding"]
|
|
300
322
|
self.source_id = memory["source_id"]
|
|
323
|
+
self.partition_id = memory["partition_id"]
|
|
301
324
|
self.created_at = datetime.fromisoformat(memory["created_at"])
|
|
302
325
|
self.updated_at = datetime.fromisoformat(memory["updated_at"])
|
|
303
326
|
self.metadata = memory["metadata"]
|
|
@@ -419,6 +442,7 @@ class MemoryBase(ABC):
|
|
|
419
442
|
*,
|
|
420
443
|
value: str = UNSET,
|
|
421
444
|
source_id: str | None = UNSET,
|
|
445
|
+
partition_id: str | None = UNSET,
|
|
422
446
|
**metadata: None | bool | float | int | str,
|
|
423
447
|
) -> Self:
|
|
424
448
|
client = OrcaClient._resolve_client()
|
|
@@ -429,6 +453,7 @@ class MemoryBase(ABC):
|
|
|
429
453
|
{"memory_id": self.memory_id}
|
|
430
454
|
| ({"value": value} if value is not UNSET else {})
|
|
431
455
|
| ({"source_id": source_id} if source_id is not UNSET else {})
|
|
456
|
+
| ({"partition_id": partition_id} if partition_id is not UNSET else {})
|
|
432
457
|
| {k: v for k, v in metadata.items() if v is not UNSET},
|
|
433
458
|
type=self.memory_type,
|
|
434
459
|
),
|
|
@@ -444,6 +469,7 @@ class MemoryBase(ABC):
|
|
|
444
469
|
"value": self.value,
|
|
445
470
|
"embedding": self.embedding,
|
|
446
471
|
"source_id": self.source_id,
|
|
472
|
+
"partition_id": self.partition_id,
|
|
447
473
|
"created_at": self.created_at,
|
|
448
474
|
"updated_at": self.updated_at,
|
|
449
475
|
"metadata": self.metadata,
|
|
@@ -468,6 +494,7 @@ class LabeledMemory(MemoryBase):
|
|
|
468
494
|
label_name: Human-readable name of the label, automatically populated from the
|
|
469
495
|
[`LabeledMemoryset.label_names`][orca_sdk.LabeledMemoryset]
|
|
470
496
|
source_id: Optional unique identifier of the memory in a system of reference
|
|
497
|
+
partition_id: Optional identifier of the partition the memory belongs to
|
|
471
498
|
metrics: Metrics about the memory, generated when running an analysis on the
|
|
472
499
|
[`LabeledMemoryset`][orca_sdk.LabeledMemoryset]
|
|
473
500
|
metadata: Metadata associated with the memory that is not used in the model. Metadata
|
|
@@ -506,6 +533,7 @@ class LabeledMemory(MemoryBase):
|
|
|
506
533
|
+ f"label: {('<' + self.label_name + ': ' + str(self.label) + '>') if self.label_name else str(self.label)}"
|
|
507
534
|
+ f", value: '{self.value[:100] + '...' if isinstance(self.value, str) and len(self.value) > 100 else self.value}'"
|
|
508
535
|
+ (f", source_id: '{self.source_id}'" if self.source_id is not None else "")
|
|
536
|
+
+ (f", partition_id: '{self.partition_id}'" if self.partition_id is not None else "")
|
|
509
537
|
+ " })"
|
|
510
538
|
)
|
|
511
539
|
|
|
@@ -518,6 +546,7 @@ class LabeledMemory(MemoryBase):
|
|
|
518
546
|
value: str = UNSET,
|
|
519
547
|
label: int | None = UNSET,
|
|
520
548
|
source_id: str | None = UNSET,
|
|
549
|
+
partition_id: str | None = UNSET,
|
|
521
550
|
**metadata: None | bool | float | int | str,
|
|
522
551
|
) -> LabeledMemory:
|
|
523
552
|
"""
|
|
@@ -530,12 +559,13 @@ class LabeledMemory(MemoryBase):
|
|
|
530
559
|
value: New value of the memory
|
|
531
560
|
label: New label of the memory
|
|
532
561
|
source_id: New source ID of the memory
|
|
562
|
+
partition_id: New partition ID of the memory
|
|
533
563
|
**metadata: New values for metadata properties
|
|
534
564
|
|
|
535
565
|
Returns:
|
|
536
566
|
The updated memory
|
|
537
567
|
"""
|
|
538
|
-
self._update(value=value, label=label, source_id=source_id, **metadata)
|
|
568
|
+
self._update(value=value, label=label, source_id=source_id, partition_id=partition_id, **metadata)
|
|
539
569
|
return self
|
|
540
570
|
|
|
541
571
|
def predictions(
|
|
@@ -632,6 +662,7 @@ class LabeledMemoryLookup(LabeledMemory):
|
|
|
632
662
|
label_name: Human-readable name of the label, automatically populated from the
|
|
633
663
|
[`LabeledMemoryset.label_names`][orca_sdk.LabeledMemoryset]
|
|
634
664
|
source_id: Optional unique identifier of the memory in a system of reference
|
|
665
|
+
partition_id: Optional identifier of the partition the memory belongs to
|
|
635
666
|
metrics: Metrics about the memory, generated when running an analysis on the
|
|
636
667
|
[`LabeledMemoryset`][orca_sdk.LabeledMemoryset]
|
|
637
668
|
metadata: Metadata associated with the memory that is not used in the model. Metadata
|
|
@@ -666,6 +697,7 @@ class LabeledMemoryLookup(LabeledMemory):
|
|
|
666
697
|
+ (f", attention_weight: {self.attention_weight:.2f}" if self.attention_weight is not None else "")
|
|
667
698
|
+ f", value: '{self.value[:100] + '...' if isinstance(self.value, str) and len(self.value) > 100 else self.value}'"
|
|
668
699
|
+ (f", source_id: '{self.source_id}'" if self.source_id is not None else "")
|
|
700
|
+
+ (f", partition_id: '{self.partition_id}'" if self.partition_id is not None else "")
|
|
669
701
|
+ " })"
|
|
670
702
|
)
|
|
671
703
|
|
|
@@ -680,6 +712,7 @@ class ScoredMemory(MemoryBase):
|
|
|
680
712
|
with the [`ScoredMemoryset.embedding_model`][orca_sdk.ScoredMemoryset]
|
|
681
713
|
score: Score of the memory
|
|
682
714
|
source_id: Optional unique identifier of the memory in a system of reference
|
|
715
|
+
partition_id: Optional identifier of the partition the memory belongs to
|
|
683
716
|
metrics: Metrics about the memory, generated when running an analysis on the
|
|
684
717
|
[`ScoredMemoryset`][orca_sdk.ScoredMemoryset]
|
|
685
718
|
metadata: Metadata associated with the memory that is not used in the model. Metadata
|
|
@@ -716,6 +749,7 @@ class ScoredMemory(MemoryBase):
|
|
|
716
749
|
+ f"score: {self.score:.2f}"
|
|
717
750
|
+ f", value: '{self.value[:100] + '...' if isinstance(self.value, str) and len(self.value) > 100 else self.value}'"
|
|
718
751
|
+ (f", source_id: '{self.source_id}'" if self.source_id is not None else "")
|
|
752
|
+
+ (f", partition_id: '{self.partition_id}'" if self.partition_id is not None else "")
|
|
719
753
|
+ " })"
|
|
720
754
|
)
|
|
721
755
|
|
|
@@ -728,6 +762,7 @@ class ScoredMemory(MemoryBase):
|
|
|
728
762
|
value: str = UNSET,
|
|
729
763
|
score: float | None = UNSET,
|
|
730
764
|
source_id: str | None = UNSET,
|
|
765
|
+
partition_id: str | None = UNSET,
|
|
731
766
|
**metadata: None | bool | float | int | str,
|
|
732
767
|
) -> ScoredMemory:
|
|
733
768
|
"""
|
|
@@ -745,7 +780,7 @@ class ScoredMemory(MemoryBase):
|
|
|
745
780
|
Returns:
|
|
746
781
|
The updated memory
|
|
747
782
|
"""
|
|
748
|
-
self._update(value=value, score=score, source_id=source_id, **metadata)
|
|
783
|
+
self._update(value=value, score=score, source_id=source_id, partition_id=partition_id, **metadata)
|
|
749
784
|
return self
|
|
750
785
|
|
|
751
786
|
def predictions(
|
|
@@ -839,6 +874,7 @@ class ScoredMemoryLookup(ScoredMemory):
|
|
|
839
874
|
with the [`ScoredMemoryset.embedding_model`][orca_sdk.ScoredMemoryset]
|
|
840
875
|
score: Score of the memory
|
|
841
876
|
source_id: Optional unique identifier of the memory in a system of reference
|
|
877
|
+
partition_id: Optional identifier of the partition the memory belongs to
|
|
842
878
|
metrics: Metrics about the memory, generated when running an analysis on the
|
|
843
879
|
[`ScoredMemoryset`][orca_sdk.ScoredMemoryset]
|
|
844
880
|
memory_id: The unique identifier for the memory, automatically generated on insert
|
|
@@ -870,6 +906,7 @@ class ScoredMemoryLookup(ScoredMemory):
|
|
|
870
906
|
+ f", lookup_score: {self.lookup_score:.2f}"
|
|
871
907
|
+ f", value: '{self.value[:100] + '...' if isinstance(self.value, str) and len(self.value) > 100 else self.value}'"
|
|
872
908
|
+ (f", source_id: '{self.source_id}'" if self.source_id is not None else "")
|
|
909
|
+
+ (f", partition_id: '{self.partition_id}'" if self.partition_id is not None else "")
|
|
873
910
|
+ " })"
|
|
874
911
|
)
|
|
875
912
|
|
|
@@ -995,6 +1032,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
995
1032
|
label_column: str | None = None,
|
|
996
1033
|
score_column: str | None = None,
|
|
997
1034
|
source_id_column: str | None = None,
|
|
1035
|
+
partition_id_column: str | None = None,
|
|
998
1036
|
description: str | None = None,
|
|
999
1037
|
label_names: list[str] | None = None,
|
|
1000
1038
|
max_seq_length_override: int | None = None,
|
|
@@ -1012,7 +1050,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1012
1050
|
Create a new memoryset in the OrcaCloud
|
|
1013
1051
|
|
|
1014
1052
|
All columns from the datasource that are not specified in the `value_column`,
|
|
1015
|
-
`label_column`, or `
|
|
1053
|
+
`label_column`, `source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1016
1054
|
|
|
1017
1055
|
Params:
|
|
1018
1056
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1026,6 +1064,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1026
1064
|
score_column: Name of the column in the datasource that contains the memory scores
|
|
1027
1065
|
source_id_column: Optional name of the column in the datasource that contains the ids in
|
|
1028
1066
|
the system of reference
|
|
1067
|
+
partition_id_column: Optional name of the column in the datasource that contains the partition ids
|
|
1029
1068
|
description: Optional description for the memoryset, this will be used in agentic flows,
|
|
1030
1069
|
so make sure it is concise and describes the contents of your memoryset not the
|
|
1031
1070
|
datasource or the embedding model.
|
|
@@ -1077,6 +1116,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1077
1116
|
"datasource_score_column": score_column,
|
|
1078
1117
|
"datasource_value_column": value_column,
|
|
1079
1118
|
"datasource_source_id_column": source_id_column,
|
|
1119
|
+
"datasource_partition_id_column": partition_id_column,
|
|
1080
1120
|
"label_names": label_names,
|
|
1081
1121
|
"max_seq_length_override": max_seq_length_override,
|
|
1082
1122
|
"remove_duplicates": remove_duplicates,
|
|
@@ -1193,7 +1233,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1193
1233
|
appended with `_datasource` and use that as the datasource for the memoryset.
|
|
1194
1234
|
|
|
1195
1235
|
All properties that are not specified to be used as `value_column`, `label_column`, or
|
|
1196
|
-
`source_id_column` will be stored as metadata in the memoryset.
|
|
1236
|
+
`source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1197
1237
|
|
|
1198
1238
|
Params:
|
|
1199
1239
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1263,7 +1303,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1263
1303
|
appended with `_datasource` and use that as the datasource for the memoryset.
|
|
1264
1304
|
|
|
1265
1305
|
All properties that are not specified to be used as `value_column`, `label_column`, or
|
|
1266
|
-
`source_id_column` will be stored as metadata in the memoryset.
|
|
1306
|
+
`source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1267
1307
|
|
|
1268
1308
|
Params:
|
|
1269
1309
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1335,7 +1375,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1335
1375
|
appended with `_datasource` and use that as the datasource for the memoryset.
|
|
1336
1376
|
|
|
1337
1377
|
All columns from the datasource that are not specified in the `value_column`,
|
|
1338
|
-
`label_column`, or `
|
|
1378
|
+
`label_column`, `source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1339
1379
|
|
|
1340
1380
|
Params:
|
|
1341
1381
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1408,7 +1448,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1408
1448
|
appended with `_datasource` and use that as the datasource for the memoryset.
|
|
1409
1449
|
|
|
1410
1450
|
All columns that are not specified to be used as `value_column`, `label_column`, or
|
|
1411
|
-
`source_id_column` will be stored as metadata in the memoryset.
|
|
1451
|
+
`source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1412
1452
|
|
|
1413
1453
|
Params:
|
|
1414
1454
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1474,7 +1514,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1474
1514
|
appended with `_datasource` and use that as the datasource for the memoryset.
|
|
1475
1515
|
|
|
1476
1516
|
All columns that are not specified to be used as `value_column`, `label_column`, or
|
|
1477
|
-
`source_id_column` will be stored as metadata in the memoryset.
|
|
1517
|
+
`source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1478
1518
|
|
|
1479
1519
|
Params:
|
|
1480
1520
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1542,7 +1582,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1542
1582
|
appended with `_datasource` and use that as the datasource for the memoryset.
|
|
1543
1583
|
|
|
1544
1584
|
All columns from the datasource that are not specified in the `value_column`,
|
|
1545
|
-
`label_column`, or `
|
|
1585
|
+
`label_column`, `source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
1546
1586
|
|
|
1547
1587
|
Params:
|
|
1548
1588
|
name: Name for the new memoryset (must be unique)
|
|
@@ -1870,15 +1910,43 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1870
1910
|
raise ValueError(f"Invalid index type: {type(index)}")
|
|
1871
1911
|
|
|
1872
1912
|
@overload
|
|
1873
|
-
def search(
|
|
1913
|
+
def search(
|
|
1914
|
+
self,
|
|
1915
|
+
query: str,
|
|
1916
|
+
*,
|
|
1917
|
+
count: int = 1,
|
|
1918
|
+
prompt: str | None = None,
|
|
1919
|
+
partition_id: str | None = None,
|
|
1920
|
+
partition_filter_mode: Literal[
|
|
1921
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
1922
|
+
] = "include_global",
|
|
1923
|
+
) -> list[MemoryLookupT]:
|
|
1874
1924
|
pass
|
|
1875
1925
|
|
|
1876
1926
|
@overload
|
|
1877
|
-
def search(
|
|
1927
|
+
def search(
|
|
1928
|
+
self,
|
|
1929
|
+
query: list[str],
|
|
1930
|
+
*,
|
|
1931
|
+
count: int = 1,
|
|
1932
|
+
prompt: str | None = None,
|
|
1933
|
+
partition_id: str | None = None,
|
|
1934
|
+
partition_filter_mode: Literal[
|
|
1935
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
1936
|
+
] = "include_global",
|
|
1937
|
+
) -> list[list[MemoryLookupT]]:
|
|
1878
1938
|
pass
|
|
1879
1939
|
|
|
1880
1940
|
def search(
|
|
1881
|
-
self,
|
|
1941
|
+
self,
|
|
1942
|
+
query: str | list[str],
|
|
1943
|
+
*,
|
|
1944
|
+
count: int = 1,
|
|
1945
|
+
prompt: str | None = None,
|
|
1946
|
+
partition_id: str | None = None,
|
|
1947
|
+
partition_filter_mode: Literal[
|
|
1948
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
1949
|
+
] = "include_global",
|
|
1882
1950
|
) -> list[MemoryLookupT] | list[list[MemoryLookupT]]:
|
|
1883
1951
|
"""
|
|
1884
1952
|
Search for memories that are semantically similar to the query
|
|
@@ -1888,7 +1956,12 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1888
1956
|
count: Number of memories to return for each query
|
|
1889
1957
|
prompt: Optional prompt for query embedding during search.
|
|
1890
1958
|
If not provided, the memoryset's default query prompt will be used if available.
|
|
1891
|
-
|
|
1959
|
+
partition_id: Optional partition ID to filter memories by
|
|
1960
|
+
partition_filter_mode: How to filter partitions when searching for memories
|
|
1961
|
+
- "ignore_partitions": Ignore partitions
|
|
1962
|
+
- "include_global": Include global memories
|
|
1963
|
+
- "exclude_global": Exclude global memories
|
|
1964
|
+
- "only_global": Only include global memories
|
|
1892
1965
|
Returns:
|
|
1893
1966
|
List of memories from the memoryset that match the query. If a single query is provided,
|
|
1894
1967
|
the return value is a list containing a single list of memories. If a list of
|
|
@@ -1928,6 +2001,8 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1928
2001
|
"query": query if isinstance(query, list) else [query],
|
|
1929
2002
|
"count": count,
|
|
1930
2003
|
"prompt": prompt,
|
|
2004
|
+
"partition_id": partition_id,
|
|
2005
|
+
"partition_filter_mode": partition_filter_mode,
|
|
1931
2006
|
},
|
|
1932
2007
|
)
|
|
1933
2008
|
lookups = [
|
|
@@ -1953,6 +2028,10 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1953
2028
|
filters: list[FilterItemTuple] = [],
|
|
1954
2029
|
with_feedback_metrics: bool = False,
|
|
1955
2030
|
sort: list[TelemetrySortItem] | None = None,
|
|
2031
|
+
partition_id: str | None = None,
|
|
2032
|
+
partition_filter_mode: Literal[
|
|
2033
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
2034
|
+
] = "include_global",
|
|
1956
2035
|
) -> list[MemoryT]:
|
|
1957
2036
|
"""
|
|
1958
2037
|
Query the memoryset for memories that match the filters
|
|
@@ -1978,6 +2057,13 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
1978
2057
|
]
|
|
1979
2058
|
|
|
1980
2059
|
if with_feedback_metrics:
|
|
2060
|
+
if partition_id:
|
|
2061
|
+
raise ValueError("Partition ID is not supported when with_feedback_metrics is True")
|
|
2062
|
+
if partition_filter_mode != "include_global":
|
|
2063
|
+
raise ValueError(
|
|
2064
|
+
f"Partition filter mode {partition_filter_mode} is not supported when with_feedback_metrics is True. Only 'include_global' is supported."
|
|
2065
|
+
)
|
|
2066
|
+
|
|
1981
2067
|
client = OrcaClient._resolve_client()
|
|
1982
2068
|
response = client.POST(
|
|
1983
2069
|
"/telemetry/memories",
|
|
@@ -2011,6 +2097,8 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2011
2097
|
"offset": offset,
|
|
2012
2098
|
"limit": limit,
|
|
2013
2099
|
"filters": cast(list[FilterItem], parsed_filters),
|
|
2100
|
+
"partition_id": partition_id,
|
|
2101
|
+
"partition_filter_mode": partition_filter_mode,
|
|
2014
2102
|
},
|
|
2015
2103
|
)
|
|
2016
2104
|
return [
|
|
@@ -2061,8 +2149,8 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2061
2149
|
|
|
2062
2150
|
Examples:
|
|
2063
2151
|
>>> memoryset.insert([
|
|
2064
|
-
... {"value": "I am happy", "label": 1, "source_id": "
|
|
2065
|
-
... {"value": "I am sad", "label": 0, "source_id": "
|
|
2152
|
+
... {"value": "I am happy", "label": 1, "source_id": "data_123", "partition_id": "user_1", "tag": "happy"},
|
|
2153
|
+
... {"value": "I am sad", "label": 0, "source_id": "data_124", "partition_id": "user_1", "tag": "sad"},
|
|
2066
2154
|
... ])
|
|
2067
2155
|
"""
|
|
2068
2156
|
client = OrcaClient._resolve_client()
|
|
@@ -2093,12 +2181,13 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2093
2181
|
- `label`: Label of the memory
|
|
2094
2182
|
- `score`: Score of the memory
|
|
2095
2183
|
- `source_id`: Optional unique ID of the memory in a system of reference
|
|
2184
|
+
- `partition_id`: Optional partition ID of the memory
|
|
2096
2185
|
- `...`: Any other metadata to store for the memory
|
|
2097
2186
|
|
|
2098
2187
|
Examples:
|
|
2099
2188
|
>>> await memoryset.ainsert([
|
|
2100
|
-
... {"value": "I am happy", "label": 1, "source_id": "
|
|
2101
|
-
... {"value": "I am sad", "label": 0, "source_id": "
|
|
2189
|
+
... {"value": "I am happy", "label": 1, "source_id": "data_123", "partition_id": "user_1", "tag": "happy"},
|
|
2190
|
+
... {"value": "I am sad", "label": 0, "source_id": "data_124", "partition_id": "user_1", "tag": "sad"},
|
|
2102
2191
|
... ])
|
|
2103
2192
|
"""
|
|
2104
2193
|
client = OrcaAsyncClient._resolve_client()
|
|
@@ -2213,6 +2302,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2213
2302
|
- `value`: Optional new value of the memory
|
|
2214
2303
|
- `label`: Optional new label of the memory
|
|
2215
2304
|
- `source_id`: Optional new source ID of the memory
|
|
2305
|
+
- `partition_id`: Optional new partition ID of the memory
|
|
2216
2306
|
- `...`: Optional new values for metadata properties
|
|
2217
2307
|
|
|
2218
2308
|
Returns:
|
|
@@ -2350,6 +2440,9 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2350
2440
|
lookup_count: int = 15,
|
|
2351
2441
|
clear_metrics: bool = False,
|
|
2352
2442
|
background: Literal[True],
|
|
2443
|
+
partition_filter_mode: Literal[
|
|
2444
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
2445
|
+
] = "include_global",
|
|
2353
2446
|
) -> Job[MemorysetMetrics]:
|
|
2354
2447
|
pass
|
|
2355
2448
|
|
|
@@ -2360,6 +2453,9 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2360
2453
|
lookup_count: int = 15,
|
|
2361
2454
|
clear_metrics: bool = False,
|
|
2362
2455
|
background: Literal[False] = False,
|
|
2456
|
+
partition_filter_mode: Literal[
|
|
2457
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
2458
|
+
] = "include_global",
|
|
2363
2459
|
) -> MemorysetMetrics:
|
|
2364
2460
|
pass
|
|
2365
2461
|
|
|
@@ -2369,6 +2465,9 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2369
2465
|
lookup_count: int = 15,
|
|
2370
2466
|
clear_metrics: bool = False,
|
|
2371
2467
|
background: bool = False,
|
|
2468
|
+
partition_filter_mode: Literal[
|
|
2469
|
+
"ignore_partitions", "include_global", "exclude_global", "only_global"
|
|
2470
|
+
] = "include_global",
|
|
2372
2471
|
) -> Job[MemorysetMetrics] | MemorysetMetrics:
|
|
2373
2472
|
"""
|
|
2374
2473
|
Run analyses on the memoryset to find duplicates, clusters, mislabelings, and more
|
|
@@ -2389,6 +2488,11 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2389
2488
|
|
|
2390
2489
|
lookup_count: Number of memories to lookup for each memory in the memoryset
|
|
2391
2490
|
clear_metrics: Whether to clear any existing metrics from the memories before running the analysis
|
|
2491
|
+
partition_filter_mode: How to filter partitions when running the analysis
|
|
2492
|
+
- "ignore_partitions": Ignore partitions
|
|
2493
|
+
- "include_global": Include global memories
|
|
2494
|
+
- "exclude_global": Exclude global memories
|
|
2495
|
+
- "only_global": Only include global memories
|
|
2392
2496
|
|
|
2393
2497
|
Returns:
|
|
2394
2498
|
dictionary with aggregate metrics for each analysis that was run
|
|
@@ -2458,6 +2562,7 @@ class MemorysetBase(Generic[MemoryT, MemoryLookupT], ABC):
|
|
|
2458
2562
|
"configs": configs,
|
|
2459
2563
|
"lookup_count": lookup_count,
|
|
2460
2564
|
"clear_metrics": clear_metrics,
|
|
2565
|
+
"partition_filter_mode": partition_filter_mode,
|
|
2461
2566
|
},
|
|
2462
2567
|
)
|
|
2463
2568
|
|
|
@@ -2518,6 +2623,7 @@ class LabeledMemoryset(MemorysetBase[LabeledMemory, LabeledMemoryLookup]):
|
|
|
2518
2623
|
value_column: str = "value",
|
|
2519
2624
|
label_column: str | None = "label",
|
|
2520
2625
|
source_id_column: str | None = None,
|
|
2626
|
+
partition_id_column: str | None = None,
|
|
2521
2627
|
description: str | None = None,
|
|
2522
2628
|
label_names: list[str] | None = None,
|
|
2523
2629
|
max_seq_length_override: int | None = None,
|
|
@@ -2543,6 +2649,7 @@ class LabeledMemoryset(MemorysetBase[LabeledMemory, LabeledMemoryLookup]):
|
|
|
2543
2649
|
value_column: str = "value",
|
|
2544
2650
|
label_column: str | None = "label",
|
|
2545
2651
|
source_id_column: str | None = None,
|
|
2652
|
+
partition_id_column: str | None = None,
|
|
2546
2653
|
description: str | None = None,
|
|
2547
2654
|
label_names: list[str] | None = None,
|
|
2548
2655
|
max_seq_length_override: int | None = None,
|
|
@@ -2567,6 +2674,7 @@ class LabeledMemoryset(MemorysetBase[LabeledMemory, LabeledMemoryLookup]):
|
|
|
2567
2674
|
value_column: str = "value",
|
|
2568
2675
|
label_column: str | None = "label",
|
|
2569
2676
|
source_id_column: str | None = None,
|
|
2677
|
+
partition_id_column: str | None = None,
|
|
2570
2678
|
description: str | None = None,
|
|
2571
2679
|
label_names: list[str] | None = None,
|
|
2572
2680
|
max_seq_length_override: int | None = None,
|
|
@@ -2583,7 +2691,7 @@ class LabeledMemoryset(MemorysetBase[LabeledMemory, LabeledMemoryLookup]):
|
|
|
2583
2691
|
Create a new labeled memoryset in the OrcaCloud
|
|
2584
2692
|
|
|
2585
2693
|
All columns from the datasource that are not specified in the `value_column`,
|
|
2586
|
-
`label_column`, or `
|
|
2694
|
+
`label_column`, `source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
2587
2695
|
|
|
2588
2696
|
Params:
|
|
2589
2697
|
name: Name for the new memoryset (must be unique)
|
|
@@ -2597,6 +2705,7 @@ class LabeledMemoryset(MemorysetBase[LabeledMemory, LabeledMemoryLookup]):
|
|
|
2597
2705
|
a memoryset with all none labels, set to `None`.
|
|
2598
2706
|
source_id_column: Optional name of the column in the datasource that contains the ids in
|
|
2599
2707
|
the system of reference
|
|
2708
|
+
partition_id_column: Optional name of the column in the datasource that contains the partition ids
|
|
2600
2709
|
description: Optional description for the memoryset, this will be used in agentic flows,
|
|
2601
2710
|
so make sure it is concise and describes the contents of your memoryset not the
|
|
2602
2711
|
datasource or the embedding model.
|
|
@@ -2633,6 +2742,7 @@ class LabeledMemoryset(MemorysetBase[LabeledMemory, LabeledMemoryLookup]):
|
|
|
2633
2742
|
embedding_model=embedding_model,
|
|
2634
2743
|
value_column=value_column,
|
|
2635
2744
|
source_id_column=source_id_column,
|
|
2745
|
+
partition_id_column=partition_id_column,
|
|
2636
2746
|
description=description,
|
|
2637
2747
|
label_names=label_names,
|
|
2638
2748
|
max_seq_length_override=max_seq_length_override,
|
|
@@ -2689,6 +2799,7 @@ class ScoredMemoryset(MemorysetBase[ScoredMemory, ScoredMemoryLookup]):
|
|
|
2689
2799
|
value_column: str = "value",
|
|
2690
2800
|
score_column: str | None = "score",
|
|
2691
2801
|
source_id_column: str | None = None,
|
|
2802
|
+
partition_id_column: str | None = None,
|
|
2692
2803
|
description: str | None = None,
|
|
2693
2804
|
max_seq_length_override: int | None = None,
|
|
2694
2805
|
prompt: str | None = None,
|
|
@@ -2713,6 +2824,7 @@ class ScoredMemoryset(MemorysetBase[ScoredMemory, ScoredMemoryLookup]):
|
|
|
2713
2824
|
score_column: str | None = "score",
|
|
2714
2825
|
value_column: str = "value",
|
|
2715
2826
|
source_id_column: str | None = None,
|
|
2827
|
+
partition_id_column: str | None = None,
|
|
2716
2828
|
description: str | None = None,
|
|
2717
2829
|
max_seq_length_override: int | None = None,
|
|
2718
2830
|
prompt: str | None = None,
|
|
@@ -2736,6 +2848,7 @@ class ScoredMemoryset(MemorysetBase[ScoredMemory, ScoredMemoryLookup]):
|
|
|
2736
2848
|
value_column: str = "value",
|
|
2737
2849
|
score_column: str | None = "score",
|
|
2738
2850
|
source_id_column: str | None = None,
|
|
2851
|
+
partition_id_column: str | None = None,
|
|
2739
2852
|
description: str | None = None,
|
|
2740
2853
|
max_seq_length_override: int | None = None,
|
|
2741
2854
|
prompt: str | None = None,
|
|
@@ -2751,7 +2864,7 @@ class ScoredMemoryset(MemorysetBase[ScoredMemory, ScoredMemoryLookup]):
|
|
|
2751
2864
|
Create a new scored memoryset in the OrcaCloud
|
|
2752
2865
|
|
|
2753
2866
|
All columns from the datasource that are not specified in the `value_column`,
|
|
2754
|
-
`score_column`, or `
|
|
2867
|
+
`score_column`, `source_id_column`, or `partition_id_column` will be stored as metadata in the memoryset.
|
|
2755
2868
|
|
|
2756
2869
|
Params:
|
|
2757
2870
|
name: Name for the new memoryset (must be unique)
|
|
@@ -2763,6 +2876,7 @@ class ScoredMemoryset(MemorysetBase[ScoredMemory, ScoredMemoryLookup]):
|
|
|
2763
2876
|
contain numerical values. To create a memoryset with all none scores, set to `None`.
|
|
2764
2877
|
source_id_column: Optional name of the column in the datasource that contains the ids in
|
|
2765
2878
|
the system of reference
|
|
2879
|
+
partition_id_column: Optional name of the column in the datasource that contains the partition ids
|
|
2766
2880
|
description: Optional description for the memoryset, this will be used in agentic flows,
|
|
2767
2881
|
so make sure it is concise and describes the contents of your memoryset not the
|
|
2768
2882
|
datasource or the embedding model.
|
|
@@ -2794,6 +2908,7 @@ class ScoredMemoryset(MemorysetBase[ScoredMemory, ScoredMemoryLookup]):
|
|
|
2794
2908
|
value_column=value_column,
|
|
2795
2909
|
score_column=score_column,
|
|
2796
2910
|
source_id_column=source_id_column,
|
|
2911
|
+
partition_id_column=partition_id_column,
|
|
2797
2912
|
description=description,
|
|
2798
2913
|
max_seq_length_override=max_seq_length_override,
|
|
2799
2914
|
prompt=prompt,
|