graphdatascience 2.1__py3-none-any.whl → 2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. graphdatascience/arrow_client/v2/api_types.py +21 -0
  2. graphdatascience/arrow_client/v2/job_client.py +67 -15
  3. graphdatascience/embedding/__init__.py +7 -0
  4. graphdatascience/{procedure_surface/api/node_embedding → embedding}/config.py +0 -22
  5. graphdatascience/error/feature_not_enabled.py +24 -0
  6. graphdatascience/procedure_surface/api/node_embedding/__init__.py +0 -14
  7. graphdatascience/procedure_surface/api/node_embedding/embedding_endpoints.py +30 -29
  8. graphdatascience/procedure_surface/api/node_embedding/graphsage_endpoints.py +0 -48
  9. graphdatascience/procedure_surface/arrow/node_embedding/embedding_arrow_endpoints.py +22 -18
  10. graphdatascience/procedure_surface/arrow/node_embedding/fastpath_arrow_endpoints.py +6 -28
  11. graphdatascience/procedure_surface/arrow/node_embedding/graphsage_session_endpoints.py +93 -0
  12. graphdatascience/procedure_surface/arrow/node_embedding/graphsage_supervised_arrow_endpoints.py +36 -0
  13. graphdatascience/procedure_surface/arrow/node_embedding/graphsage_unsupervised_arrow_endpoints.py +35 -0
  14. graphdatascience/procedure_surface/utils/node_matching.py +11 -7
  15. graphdatascience/progress/progress_bar.py +40 -13
  16. graphdatascience/progress/query_progress_provider.py +12 -5
  17. graphdatascience/query_runner/neo4j_query_runner.py +16 -4
  18. graphdatascience/query_runner/query_runner.py +1 -1
  19. graphdatascience/session/aura_graph_data_science.py +5 -3
  20. graphdatascience/session/gds_sessions.py +1 -1
  21. graphdatascience/session/remote_ops/project_protocols.py +63 -20
  22. graphdatascience/version.py +1 -1
  23. {graphdatascience-2.1.dist-info → graphdatascience-2.2.dist-info}/METADATA +1 -1
  24. {graphdatascience-2.1.dist-info → graphdatascience-2.2.dist-info}/RECORD +27 -24
  25. {graphdatascience-2.1.dist-info → graphdatascience-2.2.dist-info}/WHEEL +0 -0
  26. {graphdatascience-2.1.dist-info → graphdatascience-2.2.dist-info}/licenses/LICENSE +0 -0
  27. {graphdatascience-2.1.dist-info → graphdatascience-2.2.dist-info}/top_level.txt +0 -0
@@ -8,6 +8,26 @@ class JobIdConfig(ArrowBaseModel):
8
8
  UNKNOWN_PROGRESS = -1
9
9
 
10
10
 
11
+ class StepProgress(ArrowBaseModel):
12
+ """Progress of a single step within a multi-step job.
13
+
14
+ ``progress`` is ``None`` for qualitative steps (e.g. "Fetching graph") and a fraction
15
+ in ``[0, 1]`` for quantitative steps (e.g. "Training epoch 3").
16
+ """
17
+
18
+ current: int
19
+ total: int
20
+ progress: float | None = None
21
+
22
+ def progress_percent(self) -> float | None:
23
+ if self.progress is None:
24
+ return None
25
+ return self.progress * 100
26
+
27
+ def label(self) -> str:
28
+ return f"{self.current}/{self.total}"
29
+
30
+
11
31
  class JobStatus(ArrowBaseModel):
12
32
  """Status and progress information for a GDS Arrow job."""
13
33
 
@@ -15,6 +35,7 @@ class JobStatus(ArrowBaseModel):
15
35
  status: str
16
36
  progress: float
17
37
  description: str
38
+ step_progress: StepProgress | None = None
18
39
 
19
40
  def progress_known(self) -> bool:
20
41
  if self.progress == UNKNOWN_PROGRESS:
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import logging
3
3
  import uuid
4
+ from dataclasses import dataclass
4
5
  from typing import Any
5
6
 
6
7
  from pandas import ArrowDtype, DataFrame
@@ -23,6 +24,67 @@ JOBS_CANCEL_ENDPOINT = "v2/jobs.cancel"
23
24
  RESULTS_SUMMARY_ENDPOINT = "v2/results.summary"
24
25
 
25
26
 
27
+ @dataclass(frozen=True)
28
+ class BarSignature:
29
+ """Identifies the bar currently shown; a change means the bar must be replaced."""
30
+
31
+ step: int
32
+ quantitative: bool
33
+
34
+
35
+ class JobProgressBar:
36
+ """The single progress bar shown while waiting for one job.
37
+
38
+ Renders one status per poll and replaces the bar whenever the reported step (or its
39
+ qualitative <-> quantitative mode) changes.
40
+ """
41
+
42
+ def __init__(self, bar_options: dict[str, Any]) -> None:
43
+ self._bar_options = bar_options
44
+ self._bar: TqdmProgressBar | None = None
45
+ self._signature: BarSignature | None = None
46
+
47
+ def render(self, job_status: JobStatus) -> None:
48
+ base_task = job_status.base_task()
49
+ sub_tasks = job_status.sub_tasks()
50
+ step = job_status.step_progress
51
+
52
+ if step is None:
53
+ if self._bar is None:
54
+ self._bar = TqdmProgressBar(
55
+ task_name=base_task,
56
+ relative_progress=job_status.progress_percent(),
57
+ bar_options=self._bar_options,
58
+ )
59
+ self._bar.update(job_status.status, job_status.progress_percent(), sub_tasks)
60
+ else:
61
+ percent = step.progress_percent()
62
+ signature = BarSignature(step=step.current, quantitative=percent is not None)
63
+ if self._bar is None or signature != self._signature:
64
+ # A new step (or a qualitative <-> quantitative switch) replaces the bar.
65
+ if self._bar is not None:
66
+ self._bar.close()
67
+ self._bar = TqdmProgressBar(
68
+ task_name=base_task,
69
+ relative_progress=percent,
70
+ bar_options=self._bar_options,
71
+ )
72
+ self._signature = signature
73
+ self._bar.update(job_status.status, percent, sub_tasks, step=step.label())
74
+
75
+ def finish(self, job_status: JobStatus) -> None:
76
+ if self._bar is None:
77
+ return
78
+ if job_status.base_task():
79
+ self.render(job_status)
80
+ step = job_status.step_progress
81
+ self._bar.finish(
82
+ success=job_status.succeeded(),
83
+ step=None if step is None else step.label(),
84
+ sub_tasks_description=job_status.sub_tasks(),
85
+ )
86
+
87
+
26
88
  class JobClient:
27
89
  def __init__(self, progress_bar_options: dict[str, Any] | None = None):
28
90
  self._progress_bar_options = progress_bar_options or {}
@@ -70,10 +132,10 @@ class JobClient:
70
132
  expected_status: str | None = None,
71
133
  termination_flag: TerminationFlag | None = None,
72
134
  ) -> None:
73
- progress_bar: TqdmProgressBar | None = None
135
+ progress = JobProgressBar(self._progress_bar_options)
74
136
 
75
137
  def check_expected_status(status: JobStatus) -> bool:
76
- return job_status.succeeded() if expected_status is None else status.status == expected_status
138
+ return status.succeeded() if expected_status is None else status.status == expected_status
77
139
 
78
140
  if termination_flag is None:
79
141
  termination_flag = TerminationFlag.create()
@@ -84,21 +146,11 @@ class JobClient:
84
146
  job_status = self.get_job_status(client, job_id)
85
147
 
86
148
  if check_expected_status(job_status) or job_status.aborted():
87
- if progress_bar:
88
- progress_bar.finish(success=job_status.succeeded())
149
+ progress.finish(job_status)
89
150
  return
90
151
 
91
- if show_progress:
92
- if progress_bar is None:
93
- base_task = job_status.base_task()
94
- if base_task:
95
- progress_bar = TqdmProgressBar(
96
- task_name=base_task,
97
- relative_progress=job_status.progress_percent(),
98
- bar_options=self._progress_bar_options,
99
- )
100
- if progress_bar:
101
- progress_bar.update(job_status.status, job_status.progress_percent(), job_status.sub_tasks())
152
+ if show_progress and job_status.base_task():
153
+ progress.render(job_status)
102
154
 
103
155
  @staticmethod
104
156
  def cancel_job(client: AuthenticatedArrowClient, job_id: str) -> None:
@@ -0,0 +1,7 @@
1
+ from .config import FastRPConfig, GraphSAGEConfig, MLPClassifierConfig
2
+
3
+ __all__ = [
4
+ "FastRPConfig",
5
+ "GraphSAGEConfig",
6
+ "MLPClassifierConfig",
7
+ ]
@@ -12,7 +12,6 @@ class GraphSAGEConfig(BaseModel):
12
12
  """Configuration for the GraphSAGE graph encoder."""
13
13
 
14
14
  graph_encoder_type: Literal["graphsage"] = "graphsage"
15
- target_type: NodeType = Field(description="Node type (label) of the nodes the encoder is trained on.")
16
15
  hidden_dims: Annotated[list[PositiveInt], Len(max_length=3)] | None = Field(
17
16
  default=None,
18
17
  description="Sizes of the hidden layers. The depth of the GNN is inferred as `len(hidden_dims) + 1`.",
@@ -50,24 +49,6 @@ class FastRPConfig(BaseModel):
50
49
  )
51
50
 
52
51
 
53
- class IdentityConfig(BaseModel):
54
- """Configuration for the Identity encoder, which passes node properties through unchanged."""
55
-
56
- graph_encoder_type: Literal["identity"] = "identity"
57
- target_type: NodeType = Field(description="Node type (label) of the nodes to encode.")
58
- out_dim: PositiveInt = Field(description="Output dimensionality of the embeddings.")
59
-
60
-
61
- NoTrainGraphEncoderConfig = FastRPConfig | IdentityConfig # can be run without training
62
- GraphEncoderConfig = FastRPConfig | GraphSAGEConfig | IdentityConfig
63
-
64
-
65
- class GBClassifierConfig(BaseModel):
66
- """Configuration for the gradient boosted tree classifier decoder."""
67
-
68
- decoder_type: Literal["gb_classifier"] = "gb_classifier"
69
-
70
-
71
52
  class MLPClassifierConfig(BaseModel):
72
53
  """Configuration for the multi-layer perceptron classifier decoder."""
73
54
 
@@ -76,6 +57,3 @@ class MLPClassifierConfig(BaseModel):
76
57
  default=None, description="Sizes of the hidden layers of the network."
77
58
  )
78
59
  dropout: Dropout | None = Field(default=None, description="Dropout probability applied during training.")
79
-
80
-
81
- DecoderConfig = GBClassifierConfig | MLPClassifierConfig
@@ -0,0 +1,24 @@
1
+ from contextlib import contextmanager
2
+ from typing import Iterator
3
+
4
+
5
+ class FeatureNotEnabledError(Exception):
6
+ """Raised when an endpoint is invoked against a session that does not have the feature enabled."""
7
+
8
+ def __init__(self, feature: str) -> None:
9
+ super().__init__(
10
+ f"{feature} is not enabled for this session. "
11
+ "Please reach out to the Neo4j GDS team to have it enabled for your session."
12
+ )
13
+
14
+
15
+ @contextmanager
16
+ def translate_feature_not_enabled(endpoint: str, feature: str) -> Iterator[None]:
17
+ """Translate the session's "unsupported action" error into a clear feature-not-enabled error."""
18
+ try:
19
+ yield
20
+ except Exception as e:
21
+ message = str(e)
22
+ if "Unsupported action" in message and endpoint in message:
23
+ raise FeatureNotEnabledError(feature) from e
24
+ raise
@@ -1,10 +1,3 @@
1
- from graphdatascience.procedure_surface.api.node_embedding.config import (
2
- FastRPConfig,
3
- GBClassifierConfig,
4
- GraphSAGEConfig,
5
- IdentityConfig,
6
- MLPClassifierConfig,
7
- )
8
1
  from graphdatascience.procedure_surface.api.node_embedding.embedding_endpoints import (
9
2
  EmbeddingCreateResult,
10
3
  EmbeddingEndpoints,
@@ -23,7 +16,6 @@ from graphdatascience.procedure_surface.api.node_embedding.fastrp_endpoints impo
23
16
  )
24
17
  from graphdatascience.procedure_surface.api.node_embedding.graphsage_endpoints import (
25
18
  GraphSageEndpoints,
26
- SessionGraphSageEndpoints,
27
19
  )
28
20
  from graphdatascience.procedure_surface.api.node_embedding.graphsage_predict_endpoints import (
29
21
  GraphSageMutateResult,
@@ -69,7 +61,6 @@ __all__ = [
69
61
  "EmbeddingEndpoints",
70
62
  "EmbeddingCreateResult",
71
63
  "EmbeddingTrainResult",
72
- "FastRPConfig",
73
64
  "FastRPEndpoints",
74
65
  "FastRPMutateResult",
75
66
  "FastRPStatsResult",
@@ -77,8 +68,6 @@ __all__ = [
77
68
  "FastPathEndpoints",
78
69
  "FastPathMutateResult",
79
70
  "FastPathWriteResult",
80
- "GBClassifierConfig",
81
- "GraphSAGEConfig",
82
71
  "GraphSageEndpoints",
83
72
  "GraphSageMutateResult",
84
73
  "GraphSagePredictEndpoints",
@@ -98,10 +87,7 @@ __all__ = [
98
87
  "HashGNNEndpoints",
99
88
  "HashGNNMutateResult",
100
89
  "HashGNNWriteResult",
101
- "IdentityConfig",
102
- "MLPClassifierConfig",
103
90
  "Node2VecEndpoints",
104
91
  "Node2VecMutateResult",
105
92
  "Node2VecWriteResult",
106
- "SessionGraphSageEndpoints",
107
93
  ]
@@ -2,23 +2,14 @@ from __future__ import annotations
2
2
 
3
3
  import random
4
4
  from abc import ABC, abstractmethod
5
- from typing import Annotated, Literal
5
+ from typing import Literal
6
6
 
7
7
  from pydantic import BaseModel, Field, PositiveInt
8
8
 
9
+ from graphdatascience.embedding import FastRPConfig, GraphSAGEConfig, MLPClassifierConfig
9
10
  from graphdatascience.graph.graph_api import Graph
10
11
  from graphdatascience.procedure_surface.api.base_result import MutateResult, NodeResult, StatsResult
11
12
  from graphdatascience.procedure_surface.api.descriptions import RANDOM_SEED_DESCRIPTION, TASK_NAME_DESCRIPTION
12
- from graphdatascience.procedure_surface.api.node_embedding.config import (
13
- DecoderConfig,
14
- FastRPConfig,
15
- GBClassifierConfig,
16
- GraphEncoderConfig,
17
- GraphSAGEConfig,
18
- IdentityConfig,
19
- MLPClassifierConfig,
20
- NoTrainGraphEncoderConfig,
21
- )
22
13
 
23
14
 
24
15
  class EmbeddingEndpoints(ABC):
@@ -27,13 +18,14 @@ class EmbeddingEndpoints(ABC):
27
18
  self,
28
19
  G: Graph,
29
20
  *,
30
- graph_encoder: str | (FastRPConfig | IdentityConfig),
21
+ graph_encoder: str | FastRPConfig | None = None,
22
+ embedding_dimension: int | None = None,
31
23
  random_seed: int | None = None,
32
- mutate_property: str,
24
+ mutate_property: str = "embedding",
33
25
  job_id: str | None = None,
34
26
  node_labels: list[str] = ["*"],
35
27
  relationship_types: list[str] = ["*"],
36
- feature_properties: list[str] = [],
28
+ input_properties: list[str] = [],
37
29
  ) -> EmbeddingCreateResult:
38
30
  """
39
31
  Parameters
@@ -42,6 +34,8 @@ class EmbeddingEndpoints(ABC):
42
34
  Graph object to use
43
35
  graph_encoder
44
36
  Encoder used to produce node embeddings: either the name of a previously trained encoder model, or an inline configuration for a non-trainable encoder (e.g. FastRP or Identity).
37
+ embedding_dimension
38
+ Dimension of the node embeddings.
45
39
  random_seed
46
40
  Seed for random number generation to ensure reproducible results.
47
41
  mutate_property
@@ -52,7 +46,7 @@ class EmbeddingEndpoints(ABC):
52
46
  Filter the graph using the given node labels. Nodes with any of the given labels will be included.
53
47
  relationship_types
54
48
  Filter the graph using the given relationship types. Relationships with any of the given types will be included.
55
- feature_properties
49
+ input_properties
56
50
  Names of the node properties to use as input features
57
51
 
58
52
  Returns
@@ -65,19 +59,19 @@ class EmbeddingEndpoints(ABC):
65
59
  self,
66
60
  G: Graph,
67
61
  *,
68
- graph_encoder: FastRPConfig | GraphSAGEConfig | IdentityConfig,
69
- decoder: GBClassifierConfig | MLPClassifierConfig,
70
- model_save_name: str,
62
+ graph_encoder: GraphSAGEConfig | None = None,
63
+ decoder: MLPClassifierConfig | None = None,
64
+ embedding_dimension: int | None = None,
65
+ model_name: str,
71
66
  target_label: str,
72
67
  target_property: str,
73
68
  num_epochs: int | None = None,
74
69
  batch_size: int | None = None,
75
- num_trials: int = 1,
76
70
  random_seed: int | None = None,
77
71
  job_id: str | None = None,
78
72
  node_labels: list[str] = ["*"],
79
73
  relationship_types: list[str] = ["*"],
80
- feature_properties: list[str] = [],
74
+ input_properties: list[str],
81
75
  ) -> EmbeddingTrainResult:
82
76
  """
83
77
  embeddings.train is a preview feature and may change or be removed in future releases.
@@ -90,7 +84,9 @@ class EmbeddingEndpoints(ABC):
90
84
  Configuration for the graph encoder to train (e.g. FastRP, GraphSAGE, or Identity).
91
85
  decoder
92
86
  Configuration for the decoder to train on top of the graph encoder's embeddings.
93
- model_save_name
87
+ embedding_dimension
88
+ Dimension of the node embeddings.
89
+ model_name
94
90
  Name to save the trained graph encoder + decoder model under.
95
91
  target_label
96
92
  Node label to train on.
@@ -110,7 +106,7 @@ class EmbeddingEndpoints(ABC):
110
106
  Filter the graph using the given node labels. Nodes with any of the given labels will be included.
111
107
  relationship_types
112
108
  Filter the graph using the given relationship types. Relationships with any of the given types will be included.
113
- feature_properties
109
+ input_properties
114
110
  Names of the node properties to use as input features
115
111
  """
116
112
 
@@ -119,21 +115,26 @@ class EncodeConfig(BaseModel):
119
115
  task_name: Literal["GML_ENCODE"] = Field(
120
116
  "GML_ENCODE", validation_alias="taskName", description=TASK_NAME_DESCRIPTION
121
117
  )
122
- graph_encoder: str | Annotated[NoTrainGraphEncoderConfig, Field(discriminator="graph_encoder_type")] = Field(
123
- description="Encoder used to produce node embeddings: either the name of a previously trained encoder model, or an inline configuration for a non-trainable encoder (e.g. FastRP or Identity)."
118
+ graph_encoder: str | FastRPConfig | None = Field(
119
+ description="Encoder used to produce node embeddings: either the name of a previously trained encoder model, or an inline configuration for a non-trainable encoder, i.e. FastRP."
124
120
  )
121
+ embedding_dimension: int | None = Field(default=None, description="Dimension of the node embeddings.")
125
122
  random_seed: int = Field(default_factory=lambda: random.randint(0, 2**32 - 1), description=RANDOM_SEED_DESCRIPTION)
126
123
 
127
124
 
128
125
  class EmbeddingTrainConfig(BaseModel):
129
126
  task_name: Literal["GML_TRAIN"] = Field("GML_TRAIN", validation_alias="taskName", description=TASK_NAME_DESCRIPTION)
130
- graph_encoder: Annotated[GraphEncoderConfig, Field(discriminator="graph_encoder_type")] = Field(
131
- description="Configuration for the graph encoder to train (e.g. FastRP, GraphSAGE, or Identity)."
127
+ graph_encoder: GraphSAGEConfig | None = Field(
128
+ default=None, description="Configuration for the graph encoder (GraphSAGE) to train."
132
129
  )
133
- decoder: Annotated[DecoderConfig, Field(discriminator="decoder_type")] = Field(
134
- description="Configuration for the decoder to train on top of the graph encoder's embeddings."
130
+ decoder: MLPClassifierConfig | None = Field(
131
+ default=None,
132
+ description="Configuration for the decoder (MLP) to train on top of the graph encoder's embeddings.",
133
+ )
134
+ embedding_dimension: int | None = Field(default=None, description="Dimension of the node embeddings.")
135
+ model_save_name: str | None = Field(
136
+ default=None, description="Name to save the trained graph encoder + decoder model under."
135
137
  )
136
- model_save_name: str = Field(description="Name to save the trained graph encoder + decoder model under.")
137
138
  target_label: str = Field(description="Node label to train on.")
138
139
  target_property: str = Field(description="Node property to train on.")
139
140
  num_epochs: PositiveInt | None = Field(default=None, description="Maximum number of training epochs.")
@@ -12,15 +12,9 @@ from graphdatascience.procedure_surface.api.node_embedding.graphsage_predict_end
12
12
  GraphSagePredictEndpoints,
13
13
  GraphSageWriteResult,
14
14
  )
15
- from graphdatascience.procedure_surface.api.node_embedding.graphsage_supervised_endpoints import (
16
- GraphSageSupervisedEndpoints,
17
- )
18
15
  from graphdatascience.procedure_surface.api.node_embedding.graphsage_train_endpoints import (
19
16
  GraphSageTrainEndpoints,
20
17
  )
21
- from graphdatascience.procedure_surface.api.node_embedding.graphsage_unsupervised_endpoints import (
22
- GraphSageUnsupervisedEndpoints,
23
- )
24
18
 
25
19
 
26
20
  class GraphSageEndpoints(GraphSagePredictEndpoints):
@@ -221,45 +215,3 @@ class GraphSageEndpoints(GraphSagePredictEndpoints):
221
215
  sudo=sudo,
222
216
  job_id=job_id,
223
217
  )
224
-
225
-
226
- class SessionGraphSageEndpoints(GraphSageEndpoints):
227
- """
228
- API for the GraphSage algorithm in GDS Sessions, combining classic training and prediction
229
- with the unsupervised GraphSage endpoints (the successor of the classic `gds.graph_sage.train`)
230
- and the supervised (node classification) GraphSage endpoints.
231
- """
232
-
233
- def __init__(
234
- self,
235
- train_endpoints: GraphSageTrainEndpoints,
236
- predict_endpoints: GraphSagePredictEndpoints,
237
- catalog_endpoints: ModelCatalogProtocol,
238
- unsupervised_endpoints: GraphSageUnsupervisedEndpoints,
239
- supervised_endpoints: GraphSageSupervisedEndpoints,
240
- ) -> None:
241
- super().__init__(train_endpoints, predict_endpoints, catalog_endpoints)
242
- self._unsupervised_endpoints = unsupervised_endpoints
243
- self._supervised_endpoints = supervised_endpoints
244
-
245
- @property
246
- def unsupervised(self) -> GraphSageUnsupervisedEndpoints:
247
- """
248
- Endpoints for the unsupervised GraphSage.
249
-
250
- Returns
251
- -------
252
- GraphSageUnsupervisedEndpoints
253
- """
254
- return self._unsupervised_endpoints
255
-
256
- @property
257
- def supervised(self) -> GraphSageSupervisedEndpoints:
258
- """
259
- Endpoints for the supervised (node classification) GraphSage.
260
-
261
- Returns
262
- -------
263
- GraphSageSupervisedEndpoints
264
- """
265
- return self._supervised_endpoints
@@ -2,14 +2,12 @@ import warnings
2
2
  from typing import Any
3
3
 
4
4
  from graphdatascience.arrow_client.authenticated_flight_client import AuthenticatedArrowClient
5
- from graphdatascience.graph.graph_api import Graph
6
- from graphdatascience.procedure_surface.api.node_embedding.config import (
5
+ from graphdatascience.embedding.config import (
7
6
  FastRPConfig,
8
- GBClassifierConfig,
9
7
  GraphSAGEConfig,
10
- IdentityConfig,
11
8
  MLPClassifierConfig,
12
9
  )
10
+ from graphdatascience.graph.graph_api import Graph
13
11
  from graphdatascience.procedure_surface.api.node_embedding.embedding_endpoints import (
14
12
  EmbeddingCreateResult,
15
13
  EmbeddingEndpoints,
@@ -31,7 +29,7 @@ class EmbeddingArrowEndpoints(EmbeddingEndpoints):
31
29
  self._arrow_client = arrow_client
32
30
  self._endpoints_helper = NodePropertyEndpointsHelper(arrow_client, write_protocol, show_progress)
33
31
  warnings.warn(
34
- "embeddings.encode is a preview feature and may change or be removed in future releases.",
32
+ "gds.embedding.create and gds.embedding.train are preview features and may change or be removed in future releases.",
35
33
  UserWarning,
36
34
  stacklevel=2,
37
35
  )
@@ -40,23 +38,26 @@ class EmbeddingArrowEndpoints(EmbeddingEndpoints):
40
38
  self,
41
39
  G: Graph,
42
40
  *,
43
- graph_encoder: str | (FastRPConfig | IdentityConfig),
41
+ graph_encoder: str | FastRPConfig | None = None,
42
+ embedding_dimension: int | None = None,
44
43
  random_seed: int | None = None,
45
- mutate_property: str,
44
+ mutate_property: str = "embedding",
46
45
  job_id: str | None = None,
47
46
  node_labels: list[str] = ["*"],
48
47
  relationship_types: list[str] = ["*"],
49
- feature_properties: list[str] = [],
48
+ input_properties: list[str] = [],
50
49
  ) -> EmbeddingCreateResult:
51
50
  extra_kwargs: dict[str, Any] = {}
52
51
  if random_seed is not None:
53
52
  extra_kwargs["random_seed"] = random_seed
54
- config = EncodeConfig(graph_encoder=graph_encoder, **extra_kwargs).model_dump(exclude={"task_name"})
53
+ config = EncodeConfig(
54
+ graph_encoder=graph_encoder, embedding_dimension=embedding_dimension, **extra_kwargs
55
+ ).model_dump(exclude={"task_name"})
55
56
  config.update(
56
57
  job_id=job_id,
57
58
  node_labels=node_labels,
58
59
  relationship_types=relationship_types,
59
- feature_properties=feature_properties,
60
+ feature_properties=input_properties,
60
61
  )
61
62
  config = self._endpoints_helper.create_base_config(G=G, **config)
62
63
  result = self._endpoints_helper.run_job_and_mutate("v2/embeddings.encode", config, mutate_property)
@@ -66,39 +67,42 @@ class EmbeddingArrowEndpoints(EmbeddingEndpoints):
66
67
  self,
67
68
  G: Graph,
68
69
  *,
69
- graph_encoder: FastRPConfig | GraphSAGEConfig | IdentityConfig,
70
- decoder: GBClassifierConfig | MLPClassifierConfig,
71
- model_save_name: str,
70
+ graph_encoder: GraphSAGEConfig | None = None,
71
+ decoder: MLPClassifierConfig | None = None,
72
+ embedding_dimension: int | None = None,
73
+ model_name: str,
72
74
  target_label: str,
73
75
  target_property: str,
74
76
  num_epochs: int | None = None,
75
77
  batch_size: int | None = None,
76
- num_trials: int = 1,
77
78
  random_seed: int | None = None,
78
79
  job_id: str | None = None,
79
80
  node_labels: list[str] = ["*"],
80
81
  relationship_types: list[str] = ["*"],
81
- feature_properties: list[str] = [],
82
+ input_properties: list[str],
82
83
  ) -> EmbeddingTrainResult:
83
84
  extra_kwargs: dict[str, Any] = {}
84
85
  if random_seed is not None:
85
86
  extra_kwargs["random_seed"] = random_seed
87
+ if target_property in input_properties:
88
+ raise ValueError("Target property cannot be used as a feature property")
86
89
  config = EmbeddingTrainConfig(
87
90
  graph_encoder=graph_encoder,
88
91
  decoder=decoder,
89
- model_save_name=model_save_name,
92
+ embedding_dimension=embedding_dimension,
93
+ model_save_name=model_name,
90
94
  target_label=target_label,
91
95
  target_property=target_property,
92
96
  num_epochs=num_epochs,
93
97
  batch_size=batch_size,
94
- num_trials=num_trials,
98
+ num_trials=1,
95
99
  **extra_kwargs,
96
100
  ).model_dump(exclude={"task_name"})
97
101
  config.update(
98
102
  job_id=job_id,
99
103
  node_labels=node_labels,
100
104
  relationship_types=relationship_types,
101
- feature_properties=feature_properties,
105
+ feature_properties=input_properties + [target_property],
102
106
  )
103
107
  config = self._endpoints_helper.create_base_config(G=G, **config)
104
108
  result = self._endpoints_helper.run_job_and_get_summary("v2/embeddings.train", config)
@@ -1,9 +1,9 @@
1
- from contextlib import contextmanager
2
- from typing import Any, Iterator
1
+ from typing import Any
3
2
 
4
3
  from pandas import DataFrame
5
4
 
6
5
  from graphdatascience.arrow_client.authenticated_flight_client import AuthenticatedArrowClient
6
+ from graphdatascience.error.feature_not_enabled import translate_feature_not_enabled
7
7
  from graphdatascience.graph.graph_api import Graph
8
8
  from graphdatascience.procedure_surface.api.default_values import ALL_TYPES
9
9
  from graphdatascience.procedure_surface.api.job_handle import JobHandle
@@ -18,28 +18,6 @@ from graphdatascience.session.remote_ops.write_protocols import WriteProtocol
18
18
  FAST_PATH_ENDPOINT = "v2/embeddings.fastPath"
19
19
 
20
20
 
21
- class FeatureNotEnabledError(Exception):
22
- """Raised when endpoint is invoked against a session that does not have the feature enabled."""
23
-
24
-
25
- _NOT_ENABLED_MESSAGE = (
26
- "{feature} is not enabled for this session. "
27
- "Please reach out to the Neo4j GDS team to have it enabled for your session."
28
- )
29
-
30
-
31
- @contextmanager
32
- def _translate_feature_not_enabled(endpoint: str, feature: str) -> Iterator[None]:
33
- """Translate the session's "unsupported action" error into a clear feature-not-enabled error."""
34
- try:
35
- yield
36
- except Exception as e:
37
- message = str(e)
38
- if "Unsupported action" in message and endpoint in message:
39
- raise FeatureNotEnabledError(_NOT_ENABLED_MESSAGE.format(feature=feature)) from e
40
- raise
41
-
42
-
43
21
  class FastPathArrowEndpoints(FastPathEndpoints):
44
22
  def __init__(
45
23
  self,
@@ -107,7 +85,7 @@ class FastPathArrowEndpoints(FastPathEndpoints):
107
85
  job_id=job_id,
108
86
  )
109
87
 
110
- with _translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
88
+ with translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
111
89
  return self._node_property_endpoints.run_job(G, FAST_PATH_ENDPOINT, config)
112
90
 
113
91
  def mutate(
@@ -160,7 +138,7 @@ class FastPathArrowEndpoints(FastPathEndpoints):
160
138
  job_id=job_id,
161
139
  )
162
140
 
163
- with _translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
141
+ with translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
164
142
  result = self._node_property_endpoints.run_job_and_mutate(FAST_PATH_ENDPOINT, config, mutate_property)
165
143
 
166
144
  # FastPath writes a single property per node, so the node count equals the properties written
@@ -216,7 +194,7 @@ class FastPathArrowEndpoints(FastPathEndpoints):
216
194
  job_id=job_id,
217
195
  )
218
196
 
219
- with _translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
197
+ with translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
220
198
  return self._node_property_endpoints.run_job_and_stream(FAST_PATH_ENDPOINT, G, config)
221
199
 
222
200
  def write(
@@ -270,7 +248,7 @@ class FastPathArrowEndpoints(FastPathEndpoints):
270
248
  job_id=job_id,
271
249
  )
272
250
 
273
- with _translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
251
+ with translate_feature_not_enabled(FAST_PATH_ENDPOINT, "FastPath"):
274
252
  result = self._node_property_endpoints.run_job_and_write(
275
253
  FAST_PATH_ENDPOINT,
276
254
  G,