mlrun 1.7.2rc4__py3-none-any.whl → 1.8.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 mlrun might be problematic. Click here for more details.

Files changed (275) hide show
  1. mlrun/__init__.py +26 -22
  2. mlrun/__main__.py +15 -16
  3. mlrun/alerts/alert.py +150 -15
  4. mlrun/api/schemas/__init__.py +1 -9
  5. mlrun/artifacts/__init__.py +2 -3
  6. mlrun/artifacts/base.py +62 -19
  7. mlrun/artifacts/dataset.py +17 -17
  8. mlrun/artifacts/document.py +454 -0
  9. mlrun/artifacts/manager.py +28 -18
  10. mlrun/artifacts/model.py +91 -59
  11. mlrun/artifacts/plots.py +2 -2
  12. mlrun/common/constants.py +8 -0
  13. mlrun/common/formatters/__init__.py +1 -0
  14. mlrun/common/formatters/artifact.py +1 -1
  15. mlrun/common/formatters/feature_set.py +2 -0
  16. mlrun/common/formatters/function.py +1 -0
  17. mlrun/{model_monitoring/db/stores/v3io_kv/__init__.py → common/formatters/model_endpoint.py} +17 -0
  18. mlrun/common/formatters/pipeline.py +1 -2
  19. mlrun/common/formatters/project.py +9 -0
  20. mlrun/common/model_monitoring/__init__.py +0 -5
  21. mlrun/common/model_monitoring/helpers.py +12 -62
  22. mlrun/common/runtimes/constants.py +25 -4
  23. mlrun/common/schemas/__init__.py +9 -5
  24. mlrun/common/schemas/alert.py +114 -19
  25. mlrun/common/schemas/api_gateway.py +3 -3
  26. mlrun/common/schemas/artifact.py +22 -9
  27. mlrun/common/schemas/auth.py +8 -4
  28. mlrun/common/schemas/background_task.py +7 -7
  29. mlrun/common/schemas/client_spec.py +4 -4
  30. mlrun/common/schemas/clusterization_spec.py +2 -2
  31. mlrun/common/schemas/common.py +53 -3
  32. mlrun/common/schemas/constants.py +15 -0
  33. mlrun/common/schemas/datastore_profile.py +1 -1
  34. mlrun/common/schemas/feature_store.py +9 -9
  35. mlrun/common/schemas/frontend_spec.py +4 -4
  36. mlrun/common/schemas/function.py +10 -10
  37. mlrun/common/schemas/hub.py +1 -1
  38. mlrun/common/schemas/k8s.py +3 -3
  39. mlrun/common/schemas/memory_reports.py +3 -3
  40. mlrun/common/schemas/model_monitoring/__init__.py +4 -8
  41. mlrun/common/schemas/model_monitoring/constants.py +127 -46
  42. mlrun/common/schemas/model_monitoring/grafana.py +18 -12
  43. mlrun/common/schemas/model_monitoring/model_endpoints.py +154 -160
  44. mlrun/common/schemas/notification.py +24 -3
  45. mlrun/common/schemas/object.py +1 -1
  46. mlrun/common/schemas/pagination.py +4 -4
  47. mlrun/common/schemas/partition.py +142 -0
  48. mlrun/common/schemas/pipeline.py +3 -3
  49. mlrun/common/schemas/project.py +26 -18
  50. mlrun/common/schemas/runs.py +3 -3
  51. mlrun/common/schemas/runtime_resource.py +5 -5
  52. mlrun/common/schemas/schedule.py +1 -1
  53. mlrun/common/schemas/secret.py +1 -1
  54. mlrun/{model_monitoring/db/stores/sqldb/__init__.py → common/schemas/serving.py} +10 -1
  55. mlrun/common/schemas/tag.py +3 -3
  56. mlrun/common/schemas/workflow.py +6 -5
  57. mlrun/common/types.py +1 -0
  58. mlrun/config.py +157 -89
  59. mlrun/data_types/__init__.py +5 -3
  60. mlrun/data_types/infer.py +13 -3
  61. mlrun/data_types/spark.py +2 -1
  62. mlrun/datastore/__init__.py +59 -18
  63. mlrun/datastore/alibaba_oss.py +4 -1
  64. mlrun/datastore/azure_blob.py +4 -1
  65. mlrun/datastore/base.py +19 -24
  66. mlrun/datastore/datastore.py +10 -4
  67. mlrun/datastore/datastore_profile.py +178 -45
  68. mlrun/datastore/dbfs_store.py +4 -1
  69. mlrun/datastore/filestore.py +4 -1
  70. mlrun/datastore/google_cloud_storage.py +4 -1
  71. mlrun/datastore/hdfs.py +4 -1
  72. mlrun/datastore/inmem.py +4 -1
  73. mlrun/datastore/redis.py +4 -1
  74. mlrun/datastore/s3.py +14 -3
  75. mlrun/datastore/sources.py +89 -92
  76. mlrun/datastore/store_resources.py +7 -4
  77. mlrun/datastore/storeytargets.py +51 -16
  78. mlrun/datastore/targets.py +38 -31
  79. mlrun/datastore/utils.py +87 -4
  80. mlrun/datastore/v3io.py +4 -1
  81. mlrun/datastore/vectorstore.py +291 -0
  82. mlrun/datastore/wasbfs/fs.py +13 -12
  83. mlrun/db/base.py +286 -100
  84. mlrun/db/httpdb.py +1562 -490
  85. mlrun/db/nopdb.py +250 -83
  86. mlrun/errors.py +6 -2
  87. mlrun/execution.py +194 -50
  88. mlrun/feature_store/__init__.py +2 -10
  89. mlrun/feature_store/api.py +20 -458
  90. mlrun/feature_store/common.py +9 -9
  91. mlrun/feature_store/feature_set.py +20 -18
  92. mlrun/feature_store/feature_vector.py +105 -479
  93. mlrun/feature_store/feature_vector_utils.py +466 -0
  94. mlrun/feature_store/retrieval/base.py +15 -11
  95. mlrun/feature_store/retrieval/job.py +2 -1
  96. mlrun/feature_store/retrieval/storey_merger.py +1 -1
  97. mlrun/feature_store/steps.py +3 -3
  98. mlrun/features.py +30 -13
  99. mlrun/frameworks/__init__.py +1 -2
  100. mlrun/frameworks/_common/__init__.py +1 -2
  101. mlrun/frameworks/_common/artifacts_library.py +2 -2
  102. mlrun/frameworks/_common/mlrun_interface.py +10 -6
  103. mlrun/frameworks/_common/model_handler.py +31 -31
  104. mlrun/frameworks/_common/producer.py +3 -1
  105. mlrun/frameworks/_dl_common/__init__.py +1 -2
  106. mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
  107. mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
  108. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
  109. mlrun/frameworks/_ml_common/__init__.py +1 -2
  110. mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
  111. mlrun/frameworks/_ml_common/model_handler.py +21 -21
  112. mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
  113. mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
  114. mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
  115. mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
  116. mlrun/frameworks/auto_mlrun/__init__.py +1 -2
  117. mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
  118. mlrun/frameworks/huggingface/__init__.py +1 -2
  119. mlrun/frameworks/huggingface/model_server.py +9 -9
  120. mlrun/frameworks/lgbm/__init__.py +47 -44
  121. mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
  122. mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
  123. mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
  124. mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
  125. mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
  126. mlrun/frameworks/lgbm/model_handler.py +15 -11
  127. mlrun/frameworks/lgbm/model_server.py +11 -7
  128. mlrun/frameworks/lgbm/utils.py +2 -2
  129. mlrun/frameworks/onnx/__init__.py +1 -2
  130. mlrun/frameworks/onnx/dataset.py +3 -3
  131. mlrun/frameworks/onnx/mlrun_interface.py +2 -2
  132. mlrun/frameworks/onnx/model_handler.py +7 -5
  133. mlrun/frameworks/onnx/model_server.py +8 -6
  134. mlrun/frameworks/parallel_coordinates.py +11 -11
  135. mlrun/frameworks/pytorch/__init__.py +22 -23
  136. mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
  137. mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
  138. mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
  139. mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
  140. mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
  141. mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
  142. mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
  143. mlrun/frameworks/pytorch/model_handler.py +21 -17
  144. mlrun/frameworks/pytorch/model_server.py +13 -9
  145. mlrun/frameworks/sklearn/__init__.py +19 -18
  146. mlrun/frameworks/sklearn/estimator.py +2 -2
  147. mlrun/frameworks/sklearn/metric.py +3 -3
  148. mlrun/frameworks/sklearn/metrics_library.py +8 -6
  149. mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
  150. mlrun/frameworks/sklearn/model_handler.py +4 -3
  151. mlrun/frameworks/tf_keras/__init__.py +11 -12
  152. mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
  153. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
  154. mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
  155. mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
  156. mlrun/frameworks/tf_keras/model_handler.py +17 -13
  157. mlrun/frameworks/tf_keras/model_server.py +12 -8
  158. mlrun/frameworks/xgboost/__init__.py +19 -18
  159. mlrun/frameworks/xgboost/model_handler.py +13 -9
  160. mlrun/k8s_utils.py +2 -5
  161. mlrun/launcher/base.py +3 -4
  162. mlrun/launcher/client.py +2 -2
  163. mlrun/launcher/local.py +6 -2
  164. mlrun/launcher/remote.py +1 -1
  165. mlrun/lists.py +8 -4
  166. mlrun/model.py +132 -46
  167. mlrun/model_monitoring/__init__.py +3 -5
  168. mlrun/model_monitoring/api.py +113 -98
  169. mlrun/model_monitoring/applications/__init__.py +0 -5
  170. mlrun/model_monitoring/applications/_application_steps.py +81 -50
  171. mlrun/model_monitoring/applications/base.py +467 -14
  172. mlrun/model_monitoring/applications/context.py +212 -134
  173. mlrun/model_monitoring/{db/stores/base → applications/evidently}/__init__.py +6 -2
  174. mlrun/model_monitoring/applications/evidently/base.py +146 -0
  175. mlrun/model_monitoring/applications/histogram_data_drift.py +89 -56
  176. mlrun/model_monitoring/applications/results.py +67 -15
  177. mlrun/model_monitoring/controller.py +701 -315
  178. mlrun/model_monitoring/db/__init__.py +0 -2
  179. mlrun/model_monitoring/db/_schedules.py +242 -0
  180. mlrun/model_monitoring/db/_stats.py +189 -0
  181. mlrun/model_monitoring/db/tsdb/__init__.py +33 -22
  182. mlrun/model_monitoring/db/tsdb/base.py +243 -49
  183. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +76 -36
  184. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
  185. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connection.py +213 -0
  186. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +534 -88
  187. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
  188. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +436 -106
  189. mlrun/model_monitoring/helpers.py +356 -114
  190. mlrun/model_monitoring/stream_processing.py +190 -345
  191. mlrun/model_monitoring/tracking_policy.py +11 -4
  192. mlrun/model_monitoring/writer.py +49 -90
  193. mlrun/package/__init__.py +3 -6
  194. mlrun/package/context_handler.py +2 -2
  195. mlrun/package/packager.py +12 -9
  196. mlrun/package/packagers/__init__.py +0 -2
  197. mlrun/package/packagers/default_packager.py +14 -11
  198. mlrun/package/packagers/numpy_packagers.py +16 -7
  199. mlrun/package/packagers/pandas_packagers.py +18 -18
  200. mlrun/package/packagers/python_standard_library_packagers.py +25 -11
  201. mlrun/package/packagers_manager.py +35 -32
  202. mlrun/package/utils/__init__.py +0 -3
  203. mlrun/package/utils/_pickler.py +6 -6
  204. mlrun/platforms/__init__.py +47 -16
  205. mlrun/platforms/iguazio.py +4 -1
  206. mlrun/projects/operations.py +30 -30
  207. mlrun/projects/pipelines.py +116 -47
  208. mlrun/projects/project.py +1292 -329
  209. mlrun/render.py +5 -9
  210. mlrun/run.py +57 -14
  211. mlrun/runtimes/__init__.py +1 -3
  212. mlrun/runtimes/base.py +30 -22
  213. mlrun/runtimes/daskjob.py +9 -9
  214. mlrun/runtimes/databricks_job/databricks_runtime.py +6 -5
  215. mlrun/runtimes/function_reference.py +5 -2
  216. mlrun/runtimes/generators.py +3 -2
  217. mlrun/runtimes/kubejob.py +6 -7
  218. mlrun/runtimes/mounts.py +574 -0
  219. mlrun/runtimes/mpijob/__init__.py +0 -2
  220. mlrun/runtimes/mpijob/abstract.py +7 -6
  221. mlrun/runtimes/nuclio/api_gateway.py +7 -7
  222. mlrun/runtimes/nuclio/application/application.py +11 -13
  223. mlrun/runtimes/nuclio/application/reverse_proxy.go +66 -64
  224. mlrun/runtimes/nuclio/function.py +127 -70
  225. mlrun/runtimes/nuclio/serving.py +105 -37
  226. mlrun/runtimes/pod.py +159 -54
  227. mlrun/runtimes/remotesparkjob.py +3 -2
  228. mlrun/runtimes/sparkjob/__init__.py +0 -2
  229. mlrun/runtimes/sparkjob/spark3job.py +22 -12
  230. mlrun/runtimes/utils.py +7 -6
  231. mlrun/secrets.py +2 -2
  232. mlrun/serving/__init__.py +8 -0
  233. mlrun/serving/merger.py +7 -5
  234. mlrun/serving/remote.py +35 -22
  235. mlrun/serving/routers.py +186 -240
  236. mlrun/serving/server.py +41 -10
  237. mlrun/serving/states.py +432 -118
  238. mlrun/serving/utils.py +13 -2
  239. mlrun/serving/v1_serving.py +3 -2
  240. mlrun/serving/v2_serving.py +161 -203
  241. mlrun/track/__init__.py +1 -1
  242. mlrun/track/tracker.py +2 -2
  243. mlrun/track/trackers/mlflow_tracker.py +6 -5
  244. mlrun/utils/async_http.py +35 -22
  245. mlrun/utils/clones.py +7 -4
  246. mlrun/utils/helpers.py +511 -58
  247. mlrun/utils/logger.py +119 -13
  248. mlrun/utils/notifications/notification/__init__.py +22 -19
  249. mlrun/utils/notifications/notification/base.py +39 -15
  250. mlrun/utils/notifications/notification/console.py +6 -6
  251. mlrun/utils/notifications/notification/git.py +11 -11
  252. mlrun/utils/notifications/notification/ipython.py +10 -9
  253. mlrun/utils/notifications/notification/mail.py +176 -0
  254. mlrun/utils/notifications/notification/slack.py +16 -8
  255. mlrun/utils/notifications/notification/webhook.py +24 -8
  256. mlrun/utils/notifications/notification_pusher.py +191 -200
  257. mlrun/utils/regex.py +12 -2
  258. mlrun/utils/version/version.json +2 -2
  259. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/METADATA +69 -54
  260. mlrun-1.8.0.dist-info/RECORD +351 -0
  261. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/WHEEL +1 -1
  262. mlrun/model_monitoring/applications/evidently_base.py +0 -137
  263. mlrun/model_monitoring/db/stores/__init__.py +0 -136
  264. mlrun/model_monitoring/db/stores/base/store.py +0 -213
  265. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
  266. mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
  267. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
  268. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
  269. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
  270. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
  271. mlrun/model_monitoring/model_endpoint.py +0 -118
  272. mlrun-1.7.2rc4.dist-info/RECORD +0 -351
  273. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/entry_points.txt +0 -0
  274. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info/licenses}/LICENSE +0 -0
  275. {mlrun-1.7.2rc4.dist-info → mlrun-1.8.0.dist-info}/top_level.txt +0 -0
mlrun/execution.py CHANGED
@@ -15,8 +15,9 @@
15
15
  import logging
16
16
  import os
17
17
  import uuid
18
+ import warnings
18
19
  from copy import deepcopy
19
- from typing import Union
20
+ from typing import Optional, Union, cast
20
21
 
21
22
  import numpy as np
22
23
  import yaml
@@ -25,17 +26,23 @@ from dateutil import parser
25
26
  import mlrun
26
27
  import mlrun.common.constants as mlrun_constants
27
28
  import mlrun.common.formatters
28
- from mlrun.artifacts import ModelArtifact
29
+ from mlrun.artifacts import (
30
+ Artifact,
31
+ DatasetArtifact,
32
+ DocumentArtifact,
33
+ DocumentLoaderSpec,
34
+ ModelArtifact,
35
+ )
29
36
  from mlrun.datastore.store_resources import get_store_resource
30
37
  from mlrun.errors import MLRunInvalidArgumentError
31
38
 
32
- from .artifacts import DatasetArtifact
33
39
  from .artifacts.manager import ArtifactManager, dict_to_artifact, extend_artifact_path
34
40
  from .datastore import store_manager
35
41
  from .features import Feature
36
42
  from .model import HyperParamOptions
37
43
  from .secrets import SecretsStore
38
44
  from .utils import (
45
+ Logger,
39
46
  RunKeys,
40
47
  dict_to_json,
41
48
  dict_to_yaml,
@@ -152,7 +159,7 @@ class MLClientCtx:
152
159
  return self._project
153
160
 
154
161
  @property
155
- def logger(self):
162
+ def logger(self) -> Logger:
156
163
  """Built-in logger interface
157
164
 
158
165
  Example::
@@ -194,6 +201,11 @@ class MLClientCtx:
194
201
  """Dictionary of artifacts (read-only)"""
195
202
  return deepcopy(self._artifacts_manager.artifact_list())
196
203
 
204
+ @property
205
+ def artifact_uris(self):
206
+ """Dictionary of artifact URIs (read-only)"""
207
+ return deepcopy(self._artifacts_manager.artifact_uris)
208
+
197
209
  @property
198
210
  def in_path(self):
199
211
  """Default input path for data objects"""
@@ -296,7 +308,7 @@ class MLClientCtx:
296
308
  )
297
309
  self._parent.log_iteration_results(self._iteration, None, self.to_dict())
298
310
 
299
- def get_store_resource(self, url, secrets: dict = None):
311
+ def get_store_resource(self, url, secrets: Optional[dict] = None):
300
312
  """Get mlrun data resource (feature set/vector, artifact, item) from url.
301
313
 
302
314
  Example::
@@ -317,7 +329,7 @@ class MLClientCtx:
317
329
  data_store_secrets=secrets,
318
330
  )
319
331
 
320
- def get_dataitem(self, url, secrets: dict = None):
332
+ def get_dataitem(self, url, secrets: Optional[dict] = None):
321
333
  """Get mlrun dataitem from url
322
334
 
323
335
  Example::
@@ -425,8 +437,11 @@ class MLClientCtx:
425
437
  self._results = status.get("results", self._results)
426
438
  for artifact in status.get("artifacts", []):
427
439
  artifact_obj = dict_to_artifact(artifact)
428
- key = artifact_obj.key
429
- self._artifacts_manager.artifacts[key] = artifact_obj
440
+ self._artifacts_manager.artifact_uris[artifact_obj.key] = (
441
+ artifact_obj.uri
442
+ )
443
+ for key, uri in status.get("artifact_uris", {}).items():
444
+ self._artifacts_manager.artifact_uris[key] = uri
430
445
  self._state = status.get("state", self._state)
431
446
 
432
447
  # No need to store the run for every worker
@@ -486,11 +501,11 @@ class MLClientCtx:
486
501
  return default
487
502
  return self._parameters[key]
488
503
 
489
- def get_project_object(self):
504
+ def get_project_object(self) -> Optional["mlrun.MlrunProject"]:
490
505
  """
491
506
  Get the MLRun project object by the project name set in the context.
492
507
 
493
- :return: The project object or None if it couldn't be retrieved.
508
+ :returns: The project object or None if it couldn't be retrieved.
494
509
  """
495
510
  return self._load_project_object()
496
511
 
@@ -573,22 +588,25 @@ class MLClientCtx:
573
588
  """Reserved for internal use"""
574
589
 
575
590
  if best:
591
+ # Recreate the best iteration context for the interface of getting its artifacts
592
+ best_context = MLClientCtx.from_dict(
593
+ task, store_run=False, include_status=True
594
+ )
576
595
  self._results["best_iteration"] = best
577
- for k, v in get_in(task, ["status", "results"], {}).items():
578
- self._results[k] = v
579
- for artifact in get_in(task, ["status", RunKeys.artifacts], []):
580
- self._artifacts_manager.artifacts[artifact["metadata"]["key"]] = (
581
- artifact
582
- )
596
+ for key, result in best_context.results.items():
597
+ self._results[key] = result
598
+ for key, artifact_uri in best_context.artifact_uris.items():
599
+ self._artifacts_manager.artifact_uris[key] = artifact_uri
600
+ artifact = best_context.get_artifact(key)
583
601
  self._artifacts_manager.link_artifact(
584
602
  self.project,
585
603
  self.name,
586
604
  self.tag,
587
- artifact["metadata"]["key"],
605
+ key,
588
606
  self.iteration,
589
- artifact["spec"]["target_path"],
607
+ artifact.target_path,
608
+ db_key=artifact.db_key,
590
609
  link_iteration=best,
591
- db_key=artifact["spec"]["db_key"],
592
610
  )
593
611
 
594
612
  if summary is not None:
@@ -611,7 +629,7 @@ class MLClientCtx:
611
629
  format=None,
612
630
  db_key=None,
613
631
  **kwargs,
614
- ):
632
+ ) -> Artifact:
615
633
  """Log an output artifact and optionally upload it to datastore
616
634
 
617
635
  Example::
@@ -679,9 +697,9 @@ class MLClientCtx:
679
697
  db_key=None,
680
698
  target_path="",
681
699
  extra_data=None,
682
- label_column: str = None,
700
+ label_column: Optional[str] = None,
683
701
  **kwargs,
684
- ):
702
+ ) -> DatasetArtifact:
685
703
  """Log a dataset artifact and optionally upload it to datastore
686
704
 
687
705
  If the dataset exists with the same key and tag, it will be overwritten.
@@ -719,7 +737,7 @@ class MLClientCtx:
719
737
  :param db_key: The key to use in the artifact DB table, by default its run name + '_' + key
720
738
  db_key=False will not register it in the artifacts table
721
739
 
722
- :returns: Artifact object
740
+ :returns: Dataset artifact object
723
741
  """
724
742
  ds = DatasetArtifact(
725
743
  key,
@@ -732,16 +750,19 @@ class MLClientCtx:
732
750
  **kwargs,
733
751
  )
734
752
 
735
- item = self._artifacts_manager.log_artifact(
736
- self,
737
- ds,
738
- local_path=local_path,
739
- artifact_path=extend_artifact_path(artifact_path, self.artifact_path),
740
- target_path=target_path,
741
- tag=tag,
742
- upload=upload,
743
- db_key=db_key,
744
- labels=labels,
753
+ item = cast(
754
+ DatasetArtifact,
755
+ self._artifacts_manager.log_artifact(
756
+ self,
757
+ ds,
758
+ local_path=local_path,
759
+ artifact_path=extend_artifact_path(artifact_path, self.artifact_path),
760
+ target_path=target_path,
761
+ tag=tag,
762
+ upload=upload,
763
+ db_key=db_key,
764
+ labels=labels,
765
+ ),
745
766
  )
746
767
  self._update_run()
747
768
  return item
@@ -760,16 +781,16 @@ class MLClientCtx:
760
781
  artifact_path=None,
761
782
  upload=True,
762
783
  labels=None,
763
- inputs: list[Feature] = None,
764
- outputs: list[Feature] = None,
765
- feature_vector: str = None,
766
- feature_weights: list = None,
784
+ inputs: Optional[list[Feature]] = None,
785
+ outputs: Optional[list[Feature]] = None,
786
+ feature_vector: Optional[str] = None,
787
+ feature_weights: Optional[list] = None,
767
788
  training_set=None,
768
- label_column: Union[str, list] = None,
789
+ label_column: Optional[Union[str, list]] = None,
769
790
  extra_data=None,
770
791
  db_key=None,
771
792
  **kwargs,
772
- ):
793
+ ) -> ModelArtifact:
773
794
  """Log a model artifact and optionally upload it to datastore
774
795
 
775
796
  Example::
@@ -788,7 +809,7 @@ class MLClientCtx:
788
809
  :param key: Artifact key or artifact class ()
789
810
  :param body: Will use the body as the artifact content
790
811
  :param model_file: Path to the local model file we upload (see also model_dir)
791
- or to a model file data url (e.g. http://host/path/model.pkl)
812
+ or to a model file data url (e.g. `http://host/path/model.pkl`)
792
813
  :param model_dir: Path to the local dir holding the model file and extra files
793
814
  :param artifact_path: Target artifact path (when not using the default)
794
815
  to define a subpath under the default location use:
@@ -811,7 +832,7 @@ class MLClientCtx:
811
832
  :param db_key: The key to use in the artifact DB table, by default its run name + '_' + key
812
833
  db_key=False will not register it in the artifacts table
813
834
 
814
- :returns: Artifact object
835
+ :returns: Model artifact object
815
836
  """
816
837
 
817
838
  if training_set is not None and inputs:
@@ -838,24 +859,140 @@ class MLClientCtx:
838
859
  if training_set is not None:
839
860
  model.infer_from_df(training_set, label_column)
840
861
 
862
+ item = cast(
863
+ ModelArtifact,
864
+ self._artifacts_manager.log_artifact(
865
+ self,
866
+ model,
867
+ artifact_path=extend_artifact_path(artifact_path, self.artifact_path),
868
+ tag=tag,
869
+ upload=upload,
870
+ db_key=db_key,
871
+ labels=labels,
872
+ ),
873
+ )
874
+ self._update_run()
875
+ return item
876
+
877
+ def log_document(
878
+ self,
879
+ key: str = "",
880
+ tag: str = "",
881
+ local_path: str = "",
882
+ artifact_path: Optional[str] = None,
883
+ document_loader_spec: DocumentLoaderSpec = DocumentLoaderSpec(),
884
+ upload: Optional[bool] = False,
885
+ labels: Optional[dict[str, str]] = None,
886
+ target_path: Optional[str] = None,
887
+ db_key: Optional[str] = None,
888
+ **kwargs,
889
+ ) -> DocumentArtifact:
890
+ """
891
+ Log a document as an artifact.
892
+
893
+ :param key: Optional artifact key. If not provided, will be derived from local_path
894
+ or target_path using DocumentArtifact.key_from_source()
895
+ :param tag: Version tag
896
+ :param local_path: path to the local file we upload, will also be use
897
+ as the destination subpath (under "artifact_path")
898
+ :param artifact_path: Target artifact path (when not using the default)
899
+ to define a subpath under the default location use:
900
+ `artifact_path=context.artifact_subpath('data')`
901
+ :param document_loader_spec: Spec to use to load the artifact as langchain document.
902
+
903
+ By default, uses DocumentLoaderSpec() which initializes with:
904
+
905
+ * loader_class_name="langchain_community.document_loaders.TextLoader"
906
+ * src_name="file_path"
907
+ * kwargs=None
908
+
909
+ Can be customized for different document types, e.g.::
910
+
911
+ DocumentLoaderSpec(
912
+ loader_class_name="langchain_community.document_loaders.PDFLoader",
913
+ src_name="file_path",
914
+ kwargs={"extract_images": True}
915
+ )
916
+ :param upload: Whether to upload the artifact
917
+ :param labels: Key-value labels. A 'source' label is automatically added using either
918
+ local_path or target_path to facilitate easier document searching.
919
+ :param target_path: Path to the local file
920
+ :param db_key: The key to use in the artifact DB table, by default its run name + '_' + key
921
+ db_key=False will not register it in the artifacts table
922
+ :param kwargs: Additional keyword arguments
923
+ :return: DocumentArtifact object
924
+
925
+ Example:
926
+ >>> # Log a PDF document with custom loader
927
+ >>> project.log_document(
928
+ ... local_path="path/to/doc.pdf",
929
+ ... document_loader_spec=DocumentLoaderSpec(
930
+ ... loader_class_name="langchain_community.document_loaders.PDFLoader",
931
+ ... src_name="file_path",
932
+ ... kwargs={"extract_images": True},
933
+ ... ),
934
+ ... )
935
+ """
936
+ original_source = local_path or target_path
937
+
938
+ if not key and not original_source:
939
+ raise ValueError(
940
+ "Must provide either 'key' parameter or 'local_path'/'target_path' to derive the key from"
941
+ )
942
+ if not key:
943
+ key = DocumentArtifact.key_from_source(original_source)
944
+
945
+ doc_artifact = DocumentArtifact(
946
+ key=key,
947
+ original_source=original_source,
948
+ document_loader_spec=document_loader_spec,
949
+ collections=kwargs.pop("collections", None),
950
+ **kwargs,
951
+ )
952
+
953
+ # limit label to a max of 255 characters (for db reasons)
954
+ max_length = 255
955
+ labels = labels or {}
956
+ labels["source"] = (
957
+ original_source[: max_length - 3] + "..."
958
+ if len(original_source) > max_length
959
+ else original_source
960
+ )
961
+
841
962
  item = self._artifacts_manager.log_artifact(
842
963
  self,
843
- model,
964
+ doc_artifact,
844
965
  artifact_path=extend_artifact_path(artifact_path, self.artifact_path),
845
966
  tag=tag,
846
967
  upload=upload,
847
- db_key=db_key,
848
968
  labels=labels,
969
+ local_path=local_path,
970
+ target_path=target_path,
971
+ db_key=db_key,
849
972
  )
850
973
  self._update_run()
851
974
  return item
852
975
 
853
976
  def get_cached_artifact(self, key):
854
977
  """Return a logged artifact from cache (for potential updates)"""
855
- return self._artifacts_manager.artifacts[key]
978
+ warnings.warn(
979
+ "get_cached_artifact is deprecated in 1.8.0 and will be removed in 1.11.0. Use get_artifact instead.",
980
+ FutureWarning,
981
+ )
982
+ return self.get_artifact(key)
983
+
984
+ def get_artifact(
985
+ self, key, tag=None, iter=None, tree=None, uid=None
986
+ ) -> Optional[Artifact]:
987
+ cached_artifact_uri = self._artifacts_manager.artifact_uris.get(key, None)
988
+ if tag or iter or tree or uid or (not cached_artifact_uri):
989
+ project = self.get_project_object()
990
+ return project.get_artifact(key=key, tag=tag, iter=iter, tree=tree, uid=uid)
991
+ else:
992
+ return self.get_store_resource(cached_artifact_uri)
856
993
 
857
- def update_artifact(self, artifact_object):
858
- """Update an artifact object in the cache and the DB"""
994
+ def update_artifact(self, artifact_object: Artifact):
995
+ """Update an artifact object in the DB and the cached uri"""
859
996
  self._artifacts_manager.update_artifact(self, artifact_object)
860
997
 
861
998
  def commit(self, message: str = "", completed=False):
@@ -885,7 +1022,12 @@ class MLClientCtx:
885
1022
  if completed and not self.iteration:
886
1023
  mlrun.runtimes.utils.global_context.set(None)
887
1024
 
888
- def set_state(self, execution_state: str = None, error: str = None, commit=True):
1025
+ def set_state(
1026
+ self,
1027
+ execution_state: Optional[str] = None,
1028
+ error: Optional[str] = None,
1029
+ commit=True,
1030
+ ):
889
1031
  """
890
1032
  Modify and store the execution state or mark an error and update the run state accordingly.
891
1033
  This method allows to set the run state to 'completed' in the DB which is discouraged.
@@ -1013,7 +1155,7 @@ class MLClientCtx:
1013
1155
  set_if_not_none(struct["status"], "commit", self._commit)
1014
1156
  set_if_not_none(struct["status"], "iterations", self._iteration_results)
1015
1157
 
1016
- struct["status"][RunKeys.artifacts] = self._artifacts_manager.artifact_list()
1158
+ struct["status"][RunKeys.artifact_uris] = self._artifacts_manager.artifact_uris
1017
1159
  self._data_stores.to_dict(struct["spec"])
1018
1160
  return struct
1019
1161
 
@@ -1107,7 +1249,9 @@ class MLClientCtx:
1107
1249
  set_if_not_none(struct, "status.commit", self._commit)
1108
1250
  set_if_not_none(struct, "status.iterations", self._iteration_results)
1109
1251
 
1110
- struct[f"status.{RunKeys.artifacts}"] = self._artifacts_manager.artifact_list()
1252
+ struct[f"status.{RunKeys.artifact_uris}"] = (
1253
+ self._artifacts_manager.artifact_uris
1254
+ )
1111
1255
  return struct
1112
1256
 
1113
1257
  def _init_dbs(self, rundb):
@@ -1121,7 +1265,7 @@ class MLClientCtx:
1121
1265
  self._data_stores = store_manager.set(self._secrets_manager, db=self._rundb)
1122
1266
  self._artifacts_manager = ArtifactManager(db=self._rundb)
1123
1267
 
1124
- def _load_project_object(self):
1268
+ def _load_project_object(self) -> Optional["mlrun.MlrunProject"]:
1125
1269
  if not self._project_object:
1126
1270
  if not self._project:
1127
1271
  self.logger.warning(
@@ -12,14 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # flake8: noqa
16
-
17
15
  __all__ = [
18
- "get_offline_features",
19
- "get_online_feature_service",
20
16
  "ingest",
21
- "preview",
22
- "deploy_ingestion_service_v2",
23
17
  "delete_feature_set",
24
18
  "delete_feature_vector",
25
19
  "get_feature_set",
@@ -40,19 +34,17 @@ from ..features import Entity, Feature
40
34
  from .api import (
41
35
  delete_feature_set,
42
36
  delete_feature_vector,
43
- deploy_ingestion_service_v2,
44
37
  get_feature_set,
45
38
  get_feature_vector,
46
- get_offline_features,
47
- get_online_feature_service,
48
39
  ingest,
49
- preview,
50
40
  )
51
41
  from .common import RunConfig
52
42
  from .feature_set import FeatureSet
53
43
  from .feature_vector import (
54
44
  FeatureVector,
55
45
  FixedWindowType,
46
+ )
47
+ from .feature_vector_utils import (
56
48
  JoinGraph,
57
49
  OfflineVectorResponse,
58
50
  OnlineVectorService,