gotsimplified 0.1.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.
- gotsimplified/__init__.py +6 -0
- gotsimplified/ask.py +226 -0
- gotsimplified/client.py +261 -0
- gotsimplified/errors.py +5 -0
- gotsimplified/llm.py +126 -0
- gotsimplified/ml_graph.py +424 -0
- gotsimplified/resources.py +520 -0
- gotsimplified/validate.py +16 -0
- gotsimplified-0.1.0.dist-info/METADATA +113 -0
- gotsimplified-0.1.0.dist-info/RECORD +13 -0
- gotsimplified-0.1.0.dist-info/WHEEL +5 -0
- gotsimplified-0.1.0.dist-info/licenses/LICENSE +202 -0
- gotsimplified-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
"""Grouped functions for machine learning (c.ml) and graphs (c.graph).
|
|
2
|
+
|
|
3
|
+
Each function sends one tool call and returns the tool's text. Reads (ml query) never change anything.
|
|
4
|
+
Writes that create or delete models or graphs say so in their docstring. Where the server has no
|
|
5
|
+
preview, the client requires confirm=True and says so.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from typing import Any, Optional, Sequence
|
|
12
|
+
|
|
13
|
+
from .ask import Scope
|
|
14
|
+
from .errors import GSError
|
|
15
|
+
from .validate import check_name
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _need_confirm(action: str) -> None:
|
|
19
|
+
raise GSError(f"{action} needs confirm=True. Nothing was changed.")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ML(Scope):
|
|
23
|
+
"""Machine learning. Reads analyse your data; ml_manage functions train, predict and schedule models."""
|
|
24
|
+
|
|
25
|
+
def __init__(self, client):
|
|
26
|
+
super().__init__(client, "ml", "machine learning")
|
|
27
|
+
|
|
28
|
+
# ----- reads: never change anything -----------------------------------
|
|
29
|
+
|
|
30
|
+
def _read(self, action: str, **args) -> str:
|
|
31
|
+
return self._client._call("ml", "ml_query", {"action": action, **args})
|
|
32
|
+
|
|
33
|
+
def profile(self, table: Optional[str] = None, sql: Optional[str] = None,
|
|
34
|
+
analytics_sql: Optional[str] = None, detail: str = "simple") -> str:
|
|
35
|
+
"""What the data looks like: column kinds, gaps, and which analyses fit.
|
|
36
|
+
|
|
37
|
+
Give one of: table ("namespace.table"), sql (a SELECT over data lake tables), or
|
|
38
|
+
analytics_sql (a SELECT over analytics models). detail: "simple" (default) or "full".
|
|
39
|
+
Run this first, and use the column names it shows.
|
|
40
|
+
"""
|
|
41
|
+
return self._read("profile", table=table, sql=sql, analytics_sql=analytics_sql, detail=detail)
|
|
42
|
+
|
|
43
|
+
def health(self, table: str, time_column: Optional[str] = None, max_age_days: Optional[int] = None) -> str:
|
|
44
|
+
"""Is the table fresh and complete? max_age_days: how old the newest row may be."""
|
|
45
|
+
return self._read("health", table=table, time_column=time_column, max_age_days=max_age_days)
|
|
46
|
+
|
|
47
|
+
def models(self) -> str:
|
|
48
|
+
"""List your saved models."""
|
|
49
|
+
return self._read("list")
|
|
50
|
+
|
|
51
|
+
def model(self, name: str) -> str:
|
|
52
|
+
"""Versions and report card of one saved model."""
|
|
53
|
+
return self._read("get", model=name)
|
|
54
|
+
|
|
55
|
+
def job(self, job_id: str) -> str:
|
|
56
|
+
"""Result of a job that did not finish within the wait time."""
|
|
57
|
+
return self._read("job", job_id=job_id)
|
|
58
|
+
|
|
59
|
+
def detect(self, table: str, time_column: str, value_column: str,
|
|
60
|
+
series_columns: Optional[Sequence[str]] = None) -> str:
|
|
61
|
+
"""Find unusual periods in a number over time."""
|
|
62
|
+
return self._read("detect", table=table, time_column=time_column, value_column=value_column,
|
|
63
|
+
series_columns=list(series_columns) if series_columns else None)
|
|
64
|
+
|
|
65
|
+
def changes(self, table: str, time_column: str, value_column: str,
|
|
66
|
+
series_columns: Optional[Sequence[str]] = None) -> str:
|
|
67
|
+
"""Find when the level of a number moved."""
|
|
68
|
+
return self._read("changes", table=table, time_column=time_column, value_column=value_column,
|
|
69
|
+
series_columns=list(series_columns) if series_columns else None)
|
|
70
|
+
|
|
71
|
+
def insights(self, table: str, time_column: str, value_column: str, group_column: Optional[str] = None,
|
|
72
|
+
top: Optional[int] = None) -> str:
|
|
73
|
+
"""The findings that matter most in a number over time, optionally split by a group column."""
|
|
74
|
+
return self._read("insights", table=table, time_column=time_column, value_column=value_column,
|
|
75
|
+
group_column=group_column, top=top)
|
|
76
|
+
|
|
77
|
+
def drivers(self, table: str, time_column: str, value_column: str, group_column: str,
|
|
78
|
+
before_period: Optional[str] = None, after_period: Optional[str] = None,
|
|
79
|
+
top: Optional[int] = None) -> str:
|
|
80
|
+
"""Which segments caused a change in a total between two periods."""
|
|
81
|
+
return self._read("drivers", table=table, time_column=time_column, value_column=value_column,
|
|
82
|
+
group_column=group_column, before_period=before_period,
|
|
83
|
+
after_period=after_period, top=top)
|
|
84
|
+
|
|
85
|
+
def classify(self, table: str, value_column: str, series_columns: Sequence[str],
|
|
86
|
+
personal_columns: Optional[Sequence[str]] = None, code_columns: Optional[Sequence[str]] = None,
|
|
87
|
+
number_columns: Optional[Sequence[str]] = None, yes_value: Optional[str] = None,
|
|
88
|
+
test_share: Optional[str] = None, penalty: Optional[str] = None) -> str:
|
|
89
|
+
"""Test whether a yes/no outcome can be predicted from the other columns. Saves nothing."""
|
|
90
|
+
return self._read("classify", table=table, value_column=value_column,
|
|
91
|
+
series_columns=list(series_columns), personal_columns=_list(personal_columns),
|
|
92
|
+
code_columns=_list(code_columns), number_columns=_list(number_columns),
|
|
93
|
+
yes_value=yes_value, test_share=test_share, penalty=penalty)
|
|
94
|
+
|
|
95
|
+
def regress(self, table: str, value_column: str, series_columns: Sequence[str],
|
|
96
|
+
time_column: Optional[str] = None, test_share: Optional[str] = None,
|
|
97
|
+
penalty: Optional[str] = None) -> str:
|
|
98
|
+
"""Test whether a number can be predicted from the other columns. Saves nothing."""
|
|
99
|
+
return self._read("regress", table=table, value_column=value_column,
|
|
100
|
+
series_columns=list(series_columns), time_column=time_column,
|
|
101
|
+
test_share=test_share, penalty=penalty)
|
|
102
|
+
|
|
103
|
+
def accuracy(self, model: str, table: str) -> str:
|
|
104
|
+
"""How a saved model does on rows whose outcome is now known."""
|
|
105
|
+
return self._read("accuracy", model=model, table=table)
|
|
106
|
+
|
|
107
|
+
def monitor(self, model: str, table: str) -> str:
|
|
108
|
+
"""Has the data drifted away from what the model was trained on?"""
|
|
109
|
+
return self._read("monitor", model=model, table=table)
|
|
110
|
+
|
|
111
|
+
def elasticity(self, model: str, change_pct: float = 10) -> str:
|
|
112
|
+
"""Which inputs move a saved model's prediction most. change_pct: the change to test, in percent."""
|
|
113
|
+
return self._read("elasticity", model=model, change_pct=change_pct)
|
|
114
|
+
|
|
115
|
+
def whatif(self, model: str, what_if: dict) -> str:
|
|
116
|
+
"""Score one hypothetical row, for example {"spend": 80, "size": "large"}. Missing inputs use typical values."""
|
|
117
|
+
return self._read("whatif", model=model, what_if=what_if)
|
|
118
|
+
|
|
119
|
+
def compare(self, model: str, compare_with: str) -> str:
|
|
120
|
+
"""Compare two saved models."""
|
|
121
|
+
return self._read("compare", model=model, compare_with=compare_with)
|
|
122
|
+
|
|
123
|
+
def cluster(self, table: str, series_columns: Sequence[str]) -> str:
|
|
124
|
+
"""Find natural groups of rows."""
|
|
125
|
+
return self._read("cluster", table=table, series_columns=list(series_columns))
|
|
126
|
+
|
|
127
|
+
def recommend(self, table: str, id_column: str, item_column: str, seed_id: str, top: Optional[int] = None) -> str:
|
|
128
|
+
"""Suggest items for one customer (seed_id), from what similar customers bought."""
|
|
129
|
+
return self._read("recommend", table=table, id_column=id_column, item_column=item_column,
|
|
130
|
+
seed_id=seed_id, top=top)
|
|
131
|
+
|
|
132
|
+
def associate(self, table: str, basket_column: str, item_column: str,
|
|
133
|
+
min_support: Optional[str] = None, min_confidence: Optional[str] = None) -> str:
|
|
134
|
+
"""Items that are bought together. min_support and min_confidence: low, medium, high, or a number."""
|
|
135
|
+
return self._read("associate", table=table, basket_column=basket_column, item_column=item_column,
|
|
136
|
+
min_support=min_support, min_confidence=min_confidence)
|
|
137
|
+
|
|
138
|
+
# ----- writes: train, predict and schedule saved models -----------------
|
|
139
|
+
|
|
140
|
+
def train_forecast(self, model: str, table: str, time_column: str, value_column: str, horizon: int,
|
|
141
|
+
frequency: Optional[str] = None, series_columns: Optional[Sequence[str]] = None,
|
|
142
|
+
aggregate: Optional[str] = None, write_mode: str = "replace") -> str:
|
|
143
|
+
"""Train and save a forecast model, and write its forecast to ml.<model>_forecast.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
value_column: the number to forecast, or "count" for rows per period.
|
|
147
|
+
horizon: how many periods ahead.
|
|
148
|
+
frequency: "daily", "weekly", "monthly", "quarterly" or "yearly". Automatic when omitted.
|
|
149
|
+
aggregate: "sum" (default), "mean", "last", "max" or "min".
|
|
150
|
+
write_mode: "replace" (default, latest only) or "append" (keep every run).
|
|
151
|
+
Returns a verdict: Useful, Weak, or Not better than a simple guess.
|
|
152
|
+
"""
|
|
153
|
+
return self._train("forecast", model=model, table=table, time_column=time_column,
|
|
154
|
+
value_column=value_column, horizon=horizon, frequency=frequency,
|
|
155
|
+
series_columns=_list(series_columns), aggregate=aggregate, write_mode=write_mode)
|
|
156
|
+
|
|
157
|
+
def train_classifier(self, model: str, table: str, value_column: str, series_columns: Sequence[str],
|
|
158
|
+
time_column: Optional[str] = None, test_share: Optional[str] = None,
|
|
159
|
+
penalty: Optional[str] = None, miss_cost: Optional[float] = None,
|
|
160
|
+
false_alarm_cost: Optional[float] = None,
|
|
161
|
+
personal_columns: Optional[Sequence[str]] = None,
|
|
162
|
+
code_columns: Optional[Sequence[str]] = None,
|
|
163
|
+
number_columns: Optional[Sequence[str]] = None, yes_value: Optional[str] = None,
|
|
164
|
+
about_people: bool = False, purpose: Optional[str] = None,
|
|
165
|
+
reviewer: Optional[str] = None, notify: bool = False) -> str:
|
|
166
|
+
"""Train and save a yes/no model. miss_cost and false_alarm_cost set the decision threshold.
|
|
167
|
+
|
|
168
|
+
about_people=True (models about customers, staff, patients and so on) needs purpose and reviewer.
|
|
169
|
+
"""
|
|
170
|
+
return self._train("classify", model=model, table=table, value_column=value_column,
|
|
171
|
+
series_columns=list(series_columns), time_column=time_column, test_share=test_share,
|
|
172
|
+
penalty=penalty, miss_cost=miss_cost, false_alarm_cost=false_alarm_cost,
|
|
173
|
+
personal_columns=_list(personal_columns), code_columns=_list(code_columns),
|
|
174
|
+
number_columns=_list(number_columns), yes_value=yes_value,
|
|
175
|
+
about_people=about_people, purpose=purpose, reviewer=reviewer, notify=notify)
|
|
176
|
+
|
|
177
|
+
def train_regressor(self, model: str, table: str, value_column: str, series_columns: Sequence[str],
|
|
178
|
+
time_column: Optional[str] = None, test_share: Optional[str] = None,
|
|
179
|
+
penalty: Optional[str] = None, personal_columns: Optional[Sequence[str]] = None,
|
|
180
|
+
code_columns: Optional[Sequence[str]] = None, number_columns: Optional[Sequence[str]] = None,
|
|
181
|
+
about_people: bool = False, purpose: Optional[str] = None,
|
|
182
|
+
reviewer: Optional[str] = None, notify: bool = False) -> str:
|
|
183
|
+
"""Train and save a model that predicts a number. Same rules for people-related models as above."""
|
|
184
|
+
return self._train("regress", model=model, table=table, value_column=value_column,
|
|
185
|
+
series_columns=list(series_columns), time_column=time_column, test_share=test_share,
|
|
186
|
+
penalty=penalty, personal_columns=_list(personal_columns),
|
|
187
|
+
code_columns=_list(code_columns), number_columns=_list(number_columns),
|
|
188
|
+
about_people=about_people, purpose=purpose, reviewer=reviewer, notify=notify)
|
|
189
|
+
|
|
190
|
+
def _train(self, task: str, **args) -> str:
|
|
191
|
+
return self._client._call("ml", "ml_manage", {"action": "train", "task": task, **args})
|
|
192
|
+
|
|
193
|
+
def predict(self, model: str, table: Optional[str] = None, horizon: Optional[int] = None) -> str:
|
|
194
|
+
"""Run a saved model again, on new rows (table) or for the next periods (horizon)."""
|
|
195
|
+
return self._client._call("ml", "ml_manage", {"action": "predict", "model": model,
|
|
196
|
+
"table": table, "horizon": horizon})
|
|
197
|
+
|
|
198
|
+
def delete_model(self, model: str, confirm: bool = False) -> str:
|
|
199
|
+
"""Remove a model, its schedules and its watches. Preview first; confirm=True applies."""
|
|
200
|
+
return self._client._call("ml", "ml_manage", {"action": "delete", "model": model, "confirm": confirm})
|
|
201
|
+
|
|
202
|
+
def schedule(self, model: str, cadence: str, table: Optional[str] = None) -> str:
|
|
203
|
+
"""Refresh a model automatically. cadence: "daily" (07:00 UTC) or "weekly" (Monday 07:00 UTC).
|
|
204
|
+
At most 5 schedules per user."""
|
|
205
|
+
return self._client._call("ml", "ml_manage", {"action": "schedule", "model": model,
|
|
206
|
+
"cadence": cadence, "table": table})
|
|
207
|
+
|
|
208
|
+
def unschedule(self, model: str) -> str:
|
|
209
|
+
"""Stop the automatic refresh of a model."""
|
|
210
|
+
return self._client._call("ml", "ml_manage", {"action": "unschedule", "model": model})
|
|
211
|
+
|
|
212
|
+
def watch(self, model: str, table: str, cadence: Optional[str] = None) -> str:
|
|
213
|
+
"""Create a task when the model gets worse or its inputs drift. table: rows whose outcome is known."""
|
|
214
|
+
return self._client._call("ml", "ml_manage", {"action": "watch", "model": model,
|
|
215
|
+
"table": table, "cadence": cadence})
|
|
216
|
+
|
|
217
|
+
def unwatch(self, model: str) -> str:
|
|
218
|
+
"""Stop the watch on a model."""
|
|
219
|
+
return self._client._call("ml", "ml_manage", {"action": "unwatch", "model": model})
|
|
220
|
+
|
|
221
|
+
def publish(self, model: str) -> str:
|
|
222
|
+
"""Save the predictions for all rows to ml.<model>_scores."""
|
|
223
|
+
return self._client._call("ml", "ml_manage", {"action": "publish", "model": model})
|
|
224
|
+
|
|
225
|
+
def publish_model(self, model: str) -> str:
|
|
226
|
+
"""Make the published predictions an analytics model. Run publish() first."""
|
|
227
|
+
return self._client._call("ml", "ml_manage", {"action": "publish_model", "model": model})
|
|
228
|
+
|
|
229
|
+
def submit_labels(self, model: str, labels: list) -> str:
|
|
230
|
+
"""Save yes/no/unsure answers as labels. labels: [{"a": 3, "b": 7, "label": "yes"}, ...]."""
|
|
231
|
+
return self._client._call("ml", "ml_manage", {"action": "submit_labels", "model": model,
|
|
232
|
+
"labels": json.dumps(labels)})
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class Graph(Scope):
|
|
236
|
+
"""Graphs: connected records (people, companies, devices) and the links between them."""
|
|
237
|
+
|
|
238
|
+
def __init__(self, client):
|
|
239
|
+
super().__init__(client, "graph", "graph")
|
|
240
|
+
|
|
241
|
+
# ----- read ------------------------------------------------------------
|
|
242
|
+
|
|
243
|
+
def query(self, graph: str, cypher: str, params: Optional[dict] = None, limit: int = 10,
|
|
244
|
+
wait: bool = True) -> str:
|
|
245
|
+
"""Run a read-only Cypher query on a graph. params fill $names in the query.
|
|
246
|
+
|
|
247
|
+
Example: query("club_network", "MATCH (m:Member) RETURN m.name LIMIT 5")
|
|
248
|
+
"""
|
|
249
|
+
check_name(graph, "graph")
|
|
250
|
+
return self._client._call("graph", "graph_query", {"graph": graph, "query": cypher, "params": params,
|
|
251
|
+
"limit": limit, "wait": wait})
|
|
252
|
+
|
|
253
|
+
def describe(self, graph: str) -> str:
|
|
254
|
+
"""The node types, relationship types and properties of a graph."""
|
|
255
|
+
check_name(graph, "graph")
|
|
256
|
+
return self._client._call("graph", "graph_query", {"graph": graph, "describe": True})
|
|
257
|
+
|
|
258
|
+
def job(self, job_id: str) -> str:
|
|
259
|
+
"""Result of a query that did not finish within the wait time."""
|
|
260
|
+
return self._client._call("graph", "graph_query", {"job_id": job_id})
|
|
261
|
+
|
|
262
|
+
# ----- change records and links ----------------------------------------
|
|
263
|
+
|
|
264
|
+
def upsert_nodes(self, graph: str, node_type: str, records: list) -> str:
|
|
265
|
+
"""Add or update records of one node type. Each record needs the type's primary key.
|
|
266
|
+
Example: upsert_nodes("club_network", "Member", [{"member_id": "m1", "name": "Ann"}])"""
|
|
267
|
+
check_name(graph, "graph")
|
|
268
|
+
return self._client._call("graph", "graph_mutate", {"action": "upsert_nodes", "graph": graph,
|
|
269
|
+
"node_type": node_type, "records": records})
|
|
270
|
+
|
|
271
|
+
def upsert_relationships(self, graph: str, rel_type: str, records: list) -> str:
|
|
272
|
+
"""Add or update links. Each record: {"from": <key of start node>, "to": <key of end node>, ...}.
|
|
273
|
+
Links whose nodes don't exist are skipped and counted."""
|
|
274
|
+
check_name(graph, "graph")
|
|
275
|
+
return self._client._call("graph", "graph_mutate", {"action": "upsert_relationships", "graph": graph,
|
|
276
|
+
"rel_type": rel_type, "records": records})
|
|
277
|
+
|
|
278
|
+
def update(self, graph: str, set_values: dict, node_type: Optional[str] = None,
|
|
279
|
+
rel_type: Optional[str] = None, where: Optional[Any] = None, all_rows: bool = False,
|
|
280
|
+
confirm: bool = False) -> str:
|
|
281
|
+
"""Change matching nodes or links. Give node_type or rel_type. Preview first; confirm=True applies."""
|
|
282
|
+
check_name(graph, "graph")
|
|
283
|
+
return self._client._call("graph", "graph_mutate", {
|
|
284
|
+
"action": "update", "graph": graph, "node_type": node_type, "rel_type": rel_type,
|
|
285
|
+
"where": where, "set_values": set_values, "all_rows": all_rows, "confirm": confirm})
|
|
286
|
+
|
|
287
|
+
def delete(self, graph: str, node_type: Optional[str] = None, rel_type: Optional[str] = None,
|
|
288
|
+
where: Optional[Any] = None, all_rows: bool = False, detach: bool = False,
|
|
289
|
+
confirm: bool = False) -> str:
|
|
290
|
+
"""Remove matching nodes or links. detach=True also removes a node's links.
|
|
291
|
+
Preview first; confirm=True applies."""
|
|
292
|
+
check_name(graph, "graph")
|
|
293
|
+
return self._client._call("graph", "graph_mutate", {
|
|
294
|
+
"action": "delete", "graph": graph, "node_type": node_type, "rel_type": rel_type,
|
|
295
|
+
"where": where, "all_rows": all_rows, "detach": detach, "confirm": confirm})
|
|
296
|
+
|
|
297
|
+
def import_data(self, graph: str, url: Optional[str] = None, source_model: Optional[str] = None,
|
|
298
|
+
source_table: Optional[str] = None, node_type: Optional[str] = None,
|
|
299
|
+
rel_type: Optional[str] = None, file_format: Optional[str] = None,
|
|
300
|
+
delimiter: Optional[str] = None, key: Optional[str] = None,
|
|
301
|
+
from_column: Optional[str] = None, to_column: Optional[str] = None,
|
|
302
|
+
from_type: Optional[str] = None, to_type: Optional[str] = None,
|
|
303
|
+
columns: Optional[list] = None) -> str:
|
|
304
|
+
"""Load many nodes or links at once, from a link (url), a saved analytics model, or a data table.
|
|
305
|
+
Give exactly one source. For links, give rel_type with from_column, to_column, from_type, to_type."""
|
|
306
|
+
check_name(graph, "graph")
|
|
307
|
+
given = [x for x in (url, source_model, source_table) if x]
|
|
308
|
+
if len(given) != 1:
|
|
309
|
+
raise GSError("Give exactly one of url, source_model or source_table.")
|
|
310
|
+
return self._client._call("graph", "graph_mutate", {
|
|
311
|
+
"action": "import", "graph": graph, "url": url, "source_model": source_model,
|
|
312
|
+
"source_table": source_table, "node_type": node_type, "rel_type": rel_type,
|
|
313
|
+
"file_format": file_format, "delimiter": delimiter, "key": key, "from_column": from_column,
|
|
314
|
+
"to_column": to_column, "from_type": from_type, "to_type": to_type, "columns": columns})
|
|
315
|
+
|
|
316
|
+
# ----- structure and lifecycle -----------------------------------------
|
|
317
|
+
|
|
318
|
+
def _manage(self, action: str, **args) -> str:
|
|
319
|
+
return self._client._call("graph", "graph_manage", {"action": action, **args})
|
|
320
|
+
|
|
321
|
+
def create(self, graph: str) -> str:
|
|
322
|
+
"""Create a graph. Names: letters, digits and underscore, starting with a letter. Protected from deletion."""
|
|
323
|
+
check_name(graph, "graph")
|
|
324
|
+
return self._manage("create_graph", graph=graph)
|
|
325
|
+
|
|
326
|
+
def drop(self, graph: str, confirm: bool = False) -> str:
|
|
327
|
+
"""Delete a whole graph. Protected graphs must be unprotected first. confirm=True is required."""
|
|
328
|
+
if not confirm:
|
|
329
|
+
_need_confirm("Dropping a graph")
|
|
330
|
+
return self._manage("drop_graph", graph=graph)
|
|
331
|
+
|
|
332
|
+
def rename(self, graph: str, new_name: str) -> str:
|
|
333
|
+
"""Rename a graph."""
|
|
334
|
+
return self._manage("rename_graph", graph=graph, new_name=new_name)
|
|
335
|
+
|
|
336
|
+
def protect(self, graph: str, protect: bool = True) -> str:
|
|
337
|
+
"""Protect a graph from deletion (True) or allow it (False)."""
|
|
338
|
+
return self._manage("set_protection", graph=graph, protect=protect)
|
|
339
|
+
|
|
340
|
+
def create_node_type(self, graph: str, node_type: str, properties: dict, primary_key: str) -> str:
|
|
341
|
+
"""Add a kind of node. properties maps names to types, for example {"member_id": "string", "name": "string"}.
|
|
342
|
+
primary_key: the property that identifies each node."""
|
|
343
|
+
return self._manage("create_node_type", graph=graph, node_type=node_type,
|
|
344
|
+
properties=properties, primary_key=primary_key)
|
|
345
|
+
|
|
346
|
+
def create_relationship_type(self, graph: str, rel_type: str, from_type: str, to_type: str,
|
|
347
|
+
properties: Optional[dict] = None) -> str:
|
|
348
|
+
"""Add a kind of link between two node types."""
|
|
349
|
+
return self._manage("create_relationship_type", graph=graph, rel_type=rel_type,
|
|
350
|
+
from_type=from_type, to_type=to_type, properties=properties)
|
|
351
|
+
|
|
352
|
+
def add_property(self, graph: str, property: str, data_type: str,
|
|
353
|
+
node_type: Optional[str] = None, rel_type: Optional[str] = None) -> str:
|
|
354
|
+
"""Add a property to a node or link type. data_type: for example "string", "int64", "float[1536]" for vectors."""
|
|
355
|
+
return self._manage("add_property", graph=graph, node_type=node_type, rel_type=rel_type,
|
|
356
|
+
property=property, data_type=data_type)
|
|
357
|
+
|
|
358
|
+
def drop_property(self, graph: str, property: str, node_type: Optional[str] = None,
|
|
359
|
+
rel_type: Optional[str] = None, confirm: bool = False) -> str:
|
|
360
|
+
"""Remove a property and its values. confirm=True is required."""
|
|
361
|
+
if not confirm:
|
|
362
|
+
_need_confirm("Dropping a property")
|
|
363
|
+
return self._manage("drop_property", graph=graph, node_type=node_type, rel_type=rel_type,
|
|
364
|
+
property=property)
|
|
365
|
+
|
|
366
|
+
def rename_property(self, graph: str, property: str, new_name: str,
|
|
367
|
+
node_type: Optional[str] = None, rel_type: Optional[str] = None) -> str:
|
|
368
|
+
"""Rename a property."""
|
|
369
|
+
return self._manage("rename_property", graph=graph, node_type=node_type, rel_type=rel_type,
|
|
370
|
+
property=property, new_name=new_name)
|
|
371
|
+
|
|
372
|
+
def drop_type(self, graph: str, node_type: Optional[str] = None, rel_type: Optional[str] = None,
|
|
373
|
+
confirm: bool = False) -> str:
|
|
374
|
+
"""Remove a node or link type and its records. confirm=True is required."""
|
|
375
|
+
if not confirm:
|
|
376
|
+
_need_confirm("Dropping a type")
|
|
377
|
+
return self._manage("drop_type", graph=graph, node_type=node_type, rel_type=rel_type)
|
|
378
|
+
|
|
379
|
+
def create_index(self, graph: str, node_type: str, property: str, kind: str = "text") -> str:
|
|
380
|
+
"""Add a search index. kind: "text" for keyword search, or "vector" for a float property."""
|
|
381
|
+
return self._manage("create_index", graph=graph, node_type=node_type, property=property, kind=kind)
|
|
382
|
+
|
|
383
|
+
def drop_index(self, graph: str, node_type: str, property: str) -> str:
|
|
384
|
+
"""Remove a search index."""
|
|
385
|
+
return self._manage("drop_index", graph=graph, node_type=node_type, property=property)
|
|
386
|
+
|
|
387
|
+
def link(self, graph: str, source_model: Optional[str] = None, source_table: Optional[str] = None,
|
|
388
|
+
node_type: Optional[str] = None, rel_type: Optional[str] = None) -> str:
|
|
389
|
+
"""Keep a node or link type in step with an analytics model or a data table."""
|
|
390
|
+
return self._manage("link", graph=graph, node_type=node_type, rel_type=rel_type,
|
|
391
|
+
source_model=source_model, source_table=source_table)
|
|
392
|
+
|
|
393
|
+
def unlink(self, graph: str, node_type: Optional[str] = None, rel_type: Optional[str] = None) -> str:
|
|
394
|
+
"""Stop keeping a node or link type in step with its source."""
|
|
395
|
+
return self._manage("unlink", graph=graph, node_type=node_type, rel_type=rel_type)
|
|
396
|
+
|
|
397
|
+
def refresh(self, graph: str) -> str:
|
|
398
|
+
"""Update linked node and link types from their sources now."""
|
|
399
|
+
return self._manage("refresh", graph=graph)
|
|
400
|
+
|
|
401
|
+
def export(self, graph: str, node_type: Optional[str] = None, rel_type: Optional[str] = None,
|
|
402
|
+
export_format: Optional[str] = None) -> str:
|
|
403
|
+
"""Export a node or link type, and return the file link."""
|
|
404
|
+
return self._manage("export", graph=graph, node_type=node_type, rel_type=rel_type, format=export_format)
|
|
405
|
+
|
|
406
|
+
def snapshots(self, graph: str) -> str:
|
|
407
|
+
"""List saved versions of a graph."""
|
|
408
|
+
return self._manage("snapshots", graph=graph)
|
|
409
|
+
|
|
410
|
+
def rollback(self, graph: str, target_version: str) -> str:
|
|
411
|
+
"""Restore an earlier version. The restore is saved as a new version, so it can be undone too."""
|
|
412
|
+
return self._manage("rollback", graph=graph, target_version=str(target_version))
|
|
413
|
+
|
|
414
|
+
def describe_graph(self, graph: str, description: str) -> str:
|
|
415
|
+
"""Set the graph's description, shown in its listing."""
|
|
416
|
+
return self._manage("describe_graph", graph=graph, description=description)
|
|
417
|
+
|
|
418
|
+
def set_default(self, graph: str) -> str:
|
|
419
|
+
"""Make this the graph used when none is named."""
|
|
420
|
+
return self._manage("set_default", graph=graph)
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def _list(value: Optional[Sequence[str]]) -> Optional[list]:
|
|
424
|
+
return list(value) if value else None
|