mostlyai 5.6.0__tar.gz → 5.7.0__tar.gz

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 (89) hide show
  1. {mostlyai-5.6.0 → mostlyai-5.7.0}/PKG-INFO +3 -3
  2. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/__init__.py +1 -1
  3. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/non_context.py +123 -46
  4. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_finalize_generation.py +1 -1
  5. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_finalize_training.py +29 -7
  6. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/synthetic_datasets.py +1 -1
  7. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/domain.py +12 -2
  8. {mostlyai-5.6.0 → mostlyai-5.7.0}/pyproject.toml +3 -3
  9. {mostlyai-5.6.0 → mostlyai-5.7.0}/.gitignore +0 -0
  10. {mostlyai-5.6.0 → mostlyai-5.7.0}/LICENSE +0 -0
  11. {mostlyai-5.6.0 → mostlyai-5.7.0}/README.md +0 -0
  12. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/__init__.py +0 -0
  13. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/auto_detect.py +0 -0
  14. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/base.py +0 -0
  15. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/context.py +0 -0
  16. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/conversions.py +0 -0
  17. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/__init__.py +0 -0
  18. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/base.py +0 -0
  19. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/bigquery.py +0 -0
  20. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/databricks.py +0 -0
  21. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/hive.py +0 -0
  22. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/mssql.py +0 -0
  23. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/mysql.py +0 -0
  24. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/oracle.py +0 -0
  25. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/postgresql.py +0 -0
  26. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/redshift.py +0 -0
  27. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/snowflake.py +0 -0
  28. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/sqlite.py +0 -0
  29. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
  30. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/dtype.py +0 -0
  31. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/exceptions.py +0 -0
  32. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/__init__.py +0 -0
  33. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/base.py +0 -0
  34. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
  35. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/container/aws.py +0 -0
  36. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/container/azure.py +0 -0
  37. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
  38. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
  39. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/container/minio.py +0 -0
  40. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
  41. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/table/csv.py +0 -0
  42. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/table/feather.py +0 -0
  43. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/table/json.py +0 -0
  44. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
  45. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/file/utils.py +0 -0
  46. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/language_model.py +0 -0
  47. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/metadata_objects.py +0 -0
  48. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/progress_callback.py +0 -0
  49. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/pull.py +0 -0
  50. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/pull_context.py +0 -0
  51. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/pull_utils.py +0 -0
  52. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/push.py +0 -0
  53. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/util/__init__.py +0 -0
  54. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/util/common.py +0 -0
  55. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_data/util/kerberos.py +0 -0
  56. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/__init__.py +0 -0
  57. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/cli.py +0 -0
  58. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/connectors.py +0 -0
  59. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/__init__.py +0 -0
  60. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/jobs.py +0 -0
  61. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/migration.py +0 -0
  62. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/plan.py +0 -0
  63. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
  64. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
  65. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_create_model_report.py +0 -0
  66. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
  67. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
  68. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
  69. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
  70. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
  71. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
  72. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/generators.py +0 -0
  73. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/progress.py +0 -0
  74. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/routes.py +0 -0
  75. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/server.py +0 -0
  76. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/storage.py +0 -0
  77. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/_local/synthetic_datasets.py +0 -0
  78. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/__init__.py +0 -0
  79. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/_base_utils.py +0 -0
  80. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/_naming_conventions.py +0 -0
  81. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/_utils.py +0 -0
  82. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/api.py +0 -0
  83. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/artifacts.py +0 -0
  84. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/base.py +0 -0
  85. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/connectors.py +0 -0
  86. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/datasets.py +0 -0
  87. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/exceptions.py +0 -0
  88. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/client/generators.py +0 -0
  89. {mostlyai-5.6.0 → mostlyai-5.7.0}/mostlyai/sdk/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyai
3
- Version: 5.6.0
3
+ Version: 5.7.0
4
4
  Summary: Synthetic Data SDK
5
5
  Project-URL: homepage, https://app.mostly.ai/
6
6
  Project-URL: repository, https://github.com/mostly-ai/mostlyai
@@ -60,7 +60,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
60
60
  Requires-Dist: filelock>=3.16.1; extra == 'local'
61
61
  Requires-Dist: gcsfs>=2023.1.0; extra == 'local'
62
62
  Requires-Dist: joblib>=1.4.2; extra == 'local'
63
- Requires-Dist: mostlyai-engine==2.0.0; extra == 'local'
63
+ Requires-Dist: mostlyai-engine==2.0.1; extra == 'local'
64
64
  Requires-Dist: mostlyai-qa==1.9.8; extra == 'local'
65
65
  Requires-Dist: networkx<4,>=3.0; extra == 'local'
66
66
  Requires-Dist: openpyxl>=3.1.5; extra == 'local'
@@ -82,7 +82,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
82
82
  Requires-Dist: filelock>=3.16.1; extra == 'local-gpu'
83
83
  Requires-Dist: gcsfs>=2023.1.0; extra == 'local-gpu'
84
84
  Requires-Dist: joblib>=1.4.2; extra == 'local-gpu'
85
- Requires-Dist: mostlyai-engine[gpu]==2.0.0; extra == 'local-gpu'
85
+ Requires-Dist: mostlyai-engine[gpu]==2.0.1; extra == 'local-gpu'
86
86
  Requires-Dist: mostlyai-qa==1.9.8; extra == 'local-gpu'
87
87
  Requires-Dist: networkx<4,>=3.0; extra == 'local-gpu'
88
88
  Requires-Dist: openpyxl>=3.1.5; extra == 'local-gpu'
@@ -49,4 +49,4 @@ For more information, visit: https://mostly-ai.github.io/mostlyai/
49
49
  from mostlyai.sdk.client.api import MostlyAI
50
50
 
51
51
  __all__ = ["MostlyAI"]
52
- __version__ = "5.6.0" # Do not set this manually. Use poetry version [params].
52
+ __version__ = "5.7.0" # Do not set this manually. Use poetry version [params].
@@ -61,21 +61,24 @@ _LOG = logging.getLogger(__name__)
61
61
 
62
62
  # Model Architecture Parameters
63
63
  SUB_COLUMN_EMBEDDING_DIM = 32
64
- ENTITY_HIDDEN_DIM = 256
65
- ENTITY_EMBEDDING_DIM = 128
64
+ MIN_ENTITY_EMBEDDING_DIM = 128
66
65
  PEAKEDNESS_SCALER = 7.0
67
66
 
68
67
  # Training Parameters
69
68
  BATCH_SIZE = 256
70
- LEARNING_RATE = 0.0001
69
+ LEARNING_RATE = 1e-3
70
+ LR_SCHEDULER_FACTOR = 0.8
71
+ LR_SCHEDULER_PATIENCE = 2
72
+ LR_SCHEDULER_MIN_LR = 1e-6
71
73
  MAX_EPOCHS = 1000
72
- PATIENCE = 5
74
+ PATIENCE = 10
73
75
  N_NEGATIVE_SAMPLES = 20
74
76
  VAL_SPLIT = 0.2
75
77
  DROPOUT_RATE = 0.2
76
78
  EARLY_STOPPING_DELTA = 1e-5
77
79
  NUMERICAL_STABILITY_EPSILON = 1e-10
78
80
 
81
+
79
82
  # Data Sampling Parameters
80
83
  MAX_TGT_PER_PARENT = 10
81
84
  MAX_CHILDREN = 5000
@@ -86,7 +89,7 @@ TOP_K = None
86
89
  TOP_P = 0.95
87
90
  QUOTA_PENALTY_FACTOR = 0.02
88
91
 
89
- # Supported Encoding Types
92
+ # Supported Encoding Types for FK Models
90
93
  FK_MODEL_ENCODING_TYPES = [
91
94
  ModelEncodingType.tabular_categorical,
92
95
  ModelEncodingType.tabular_numeric_auto,
@@ -133,7 +136,7 @@ def add_is_null_for_non_context_relation(
133
136
  is_target: bool = False,
134
137
  ) -> pd.DataFrame:
135
138
  """Handle a single non-context relation for a table and add an is_null column."""
136
- _LOG.info(f"handle non-context relation {table.name}")
139
+ _LOG.info(f"[NonContext] Handle relation | table={table.name}")
137
140
 
138
141
  assert isinstance(relation, NonContextRelation)
139
142
  fk = relation.child.ref_name(prefixed=not is_target)
@@ -207,7 +210,7 @@ def assign_non_context_fks_randomly(
207
210
  continue
208
211
  tgt_fk_name = rel.child.column
209
212
  tgt_is_null_column_name = rel.get_is_null_column()
210
- _LOG.info(f"sample non-context keys for {tgt_fk_name}")
213
+ _LOG.info(f"[NonContext] Sample keys | fk={tgt_fk_name}")
211
214
  tgt_is_null = tgt_data[tgt_is_null_column_name]
212
215
  # read referenced table's keys
213
216
  non_ctx_pk_name = rel.parent.column
@@ -233,9 +236,9 @@ class EntityEncoder(nn.Module):
233
236
  def __init__(
234
237
  self,
235
238
  cardinalities: dict[str, int],
236
- sub_column_embedding_dim: int = SUB_COLUMN_EMBEDDING_DIM,
237
- entity_hidden_dim: int = ENTITY_HIDDEN_DIM,
238
- entity_embedding_dim: int = ENTITY_EMBEDDING_DIM,
239
+ sub_column_embedding_dim: int,
240
+ entity_hidden_dim: int,
241
+ entity_embedding_dim: int,
239
242
  ):
240
243
  super().__init__()
241
244
  self.cardinalities = cardinalities
@@ -269,24 +272,35 @@ class ParentChildMatcher(nn.Module):
269
272
  self,
270
273
  parent_cardinalities: dict[str, int],
271
274
  child_cardinalities: dict[str, int],
272
- sub_column_embedding_dim: int = SUB_COLUMN_EMBEDDING_DIM,
273
- entity_hidden_dim: int = ENTITY_HIDDEN_DIM,
274
- entity_embedding_dim: int = ENTITY_EMBEDDING_DIM,
275
+ sub_column_embedding_dim: int | None = None,
276
+ entity_hidden_dim: int | None = None,
277
+ parent_entity_embedding_dim: int | None = None,
278
+ child_entity_embedding_dim: int | None = None,
275
279
  ):
276
280
  super().__init__()
277
- self.entity_embedding_dim = entity_embedding_dim
281
+
282
+ sub_column_embedding_dim = sub_column_embedding_dim or SUB_COLUMN_EMBEDDING_DIM
283
+
284
+ parent_entity_embedding_dim = parent_entity_embedding_dim or max(
285
+ MIN_ENTITY_EMBEDDING_DIM, int((len(parent_cardinalities) * sub_column_embedding_dim) ** 0.5)
286
+ )
287
+ child_entity_embedding_dim = child_entity_embedding_dim or max(
288
+ MIN_ENTITY_EMBEDDING_DIM, int((len(child_cardinalities) * sub_column_embedding_dim) ** 0.5)
289
+ )
290
+
291
+ entity_hidden_dim = entity_hidden_dim or (max(parent_entity_embedding_dim, child_entity_embedding_dim) * 2)
278
292
 
279
293
  self.parent_encoder = EntityEncoder(
280
294
  cardinalities=parent_cardinalities,
281
295
  sub_column_embedding_dim=sub_column_embedding_dim,
282
296
  entity_hidden_dim=entity_hidden_dim,
283
- entity_embedding_dim=self.entity_embedding_dim,
297
+ entity_embedding_dim=parent_entity_embedding_dim,
284
298
  )
285
299
  self.child_encoder = EntityEncoder(
286
300
  cardinalities=child_cardinalities,
287
301
  sub_column_embedding_dim=sub_column_embedding_dim,
288
302
  entity_hidden_dim=entity_hidden_dim,
289
- entity_embedding_dim=self.entity_embedding_dim,
303
+ entity_embedding_dim=child_entity_embedding_dim,
290
304
  )
291
305
 
292
306
  def forward(self, parent_inputs: dict[str, torch.Tensor], child_inputs: dict[str, torch.Tensor]) -> torch.Tensor:
@@ -329,9 +343,22 @@ def analyze_df(
329
343
  primary_key: str | None = None,
330
344
  parent_key: str | None = None,
331
345
  data_columns: list[str] | None = None,
346
+ encoding_types: dict[str, ModelEncodingType] | None = None,
332
347
  stats_dir: Path,
333
348
  ) -> None:
334
- """Analyze dataframe and compute statistics for encoding."""
349
+ """
350
+ Analyze dataframe and compute statistics for encoding.
351
+
352
+ Args:
353
+ df: DataFrame to analyze
354
+ primary_key: Primary key column name (excluded from analysis)
355
+ parent_key: Parent key column name (excluded from analysis)
356
+ data_columns: List of data columns to analyze
357
+ encoding_types: Resolved encoding types (column_name -> ModelEncodingType).
358
+ When provided, these are used to determine column categories.
359
+ When None, infers categories from pandas dtypes.
360
+ stats_dir: Directory to save statistics
361
+ """
335
362
  stats_dir.mkdir(parents=True, exist_ok=True)
336
363
 
337
364
  key_columns = []
@@ -344,9 +371,49 @@ def analyze_df(
344
371
 
345
372
  # preserve column order to ensure deterministic encoding
346
373
  data_columns = [col for col in data_columns if col not in key_columns and col in df.columns]
347
- num_columns = [col for col in data_columns if col in df.select_dtypes(include="number").columns]
348
- dt_columns = [col for col in data_columns if col in df.select_dtypes(include="datetime").columns]
349
- cat_columns = [col for col in data_columns if col not in num_columns + dt_columns]
374
+
375
+ # Determine column types: use user-defined encoding types if available, otherwise infer from dtypes
376
+ if encoding_types:
377
+ _LOG.info(f"[NonContext] Using user-defined encoding types | columns={list(encoding_types.keys())}")
378
+ num_columns = []
379
+ dt_columns = []
380
+ cat_columns = []
381
+
382
+ for col in data_columns:
383
+ encoding_type = encoding_types.get(col)
384
+ if encoding_type is None:
385
+ # Column not in encoding_types, infer from pandas dtype
386
+ if col in df.select_dtypes(include="number").columns:
387
+ num_columns.append(col)
388
+ elif col in df.select_dtypes(include="datetime").columns:
389
+ dt_columns.append(col)
390
+ else:
391
+ cat_columns.append(col)
392
+ continue
393
+
394
+ # Map numeric encoding types
395
+ if encoding_type in [
396
+ ModelEncodingType.tabular_numeric_auto,
397
+ ModelEncodingType.tabular_numeric_discrete,
398
+ ModelEncodingType.tabular_numeric_binned,
399
+ ModelEncodingType.tabular_numeric_digit,
400
+ ]:
401
+ num_columns.append(col)
402
+ # Map datetime encoding types
403
+ elif encoding_type == ModelEncodingType.tabular_datetime:
404
+ dt_columns.append(col)
405
+ # Map categorical encoding type
406
+ elif encoding_type == ModelEncodingType.tabular_categorical:
407
+ cat_columns.append(col)
408
+
409
+ _LOG.info(
410
+ f"[NonContext] Column mapping | numeric={num_columns} | datetime={dt_columns} | categorical={cat_columns}"
411
+ )
412
+ else:
413
+ # Fallback to dtype inference when no encoding types provided
414
+ num_columns = [col for col in data_columns if col in df.select_dtypes(include="number").columns]
415
+ dt_columns = [col for col in data_columns if col in df.select_dtypes(include="datetime").columns]
416
+ cat_columns = [col for col in data_columns if col not in num_columns + dt_columns]
350
417
 
351
418
  stats = {
352
419
  "primary_key": primary_key,
@@ -441,7 +508,7 @@ def add_context_parent_data(
441
508
  # get unique context parent keys from tgt_data
442
509
  ctx_parent_keys = tgt_data[tgt_ctx_fk].dropna().unique().tolist()
443
510
  if not ctx_parent_keys:
444
- _LOG.info(f"No context parent keys found in tgt_data for {tgt_table.name}")
511
+ _LOG.info(f"[NonContext] No parent keys found | table={tgt_table.name}")
445
512
  return tgt_data
446
513
 
447
514
  # identify key columns to exclude (primary key + foreign keys)
@@ -470,7 +537,7 @@ def add_context_parent_data(
470
537
  )
471
538
 
472
539
  if ctx_parent_data.empty:
473
- _LOG.info(f"No context parent data found for {tgt_table.name}")
540
+ _LOG.info(f"[NonContext] No parent data found | table={tgt_table.name}")
474
541
  return tgt_data
475
542
 
476
543
  # join context parent data with tgt_data
@@ -492,7 +559,7 @@ def add_context_parent_data(
492
559
  tgt_data = tgt_data.drop(columns=[tgt_ctx_fk])
493
560
 
494
561
  added_columns = [c for c in tgt_data.columns if c in ctx_parent_data.columns]
495
- _LOG.info(f"add_context_parent_data | time: {time.time() - t0:.2f}s | added_columns: {added_columns}")
562
+ _LOG.info(f"[NonContext] Add context parent data | time={time.time() - t0:.2f}s | added_columns={added_columns}")
496
563
  return tgt_data
497
564
 
498
565
 
@@ -619,11 +686,7 @@ def pull_fk_model_training_data(
619
686
  len(tgt_data) / len(parent_keys_with_children) if len(parent_keys_with_children) > 0 else 0
620
687
  )
621
688
  _LOG.info(
622
- f"pull_fk_model_training_data | time: {time.time() - t0:.2f}s\n"
623
- f" Training data:\n"
624
- f" - Parents: {len(parent_data)} total "
625
- f"({len(parent_keys_with_children)} with children, {len(sampled_parent_keys_without_children)} without)\n"
626
- f" - Children: {len(tgt_data)} (max {max_children_per_parent} per parent, avg {avg_children_per_parent:.2f} per parent with children)"
689
+ f"[NonContext] Pull training data | parents_total={len(parent_data)} | parents_with_children={len(parent_keys_with_children)} | parents_without={len(sampled_parent_keys_without_children)} | children={len(tgt_data)} | max_per_parent={max_children_per_parent} | avg_per_parent={avg_children_per_parent:.2f} | time={time.time() - t0:.2f}s"
627
690
  )
628
691
  return parent_data, tgt_data
629
692
 
@@ -659,7 +722,7 @@ def prepare_training_data_for_cardinality_model(
659
722
  parent_data_enriched = parent_data.assign(**{CHILDREN_COUNT_COLUMN_NAME: children_counts})
660
723
 
661
724
  _LOG.info(
662
- f"prepare_training_data_for_cardinality_model | n_rows: {len(parent_data_enriched)} | time: {time.time() - t0:.2f}s"
725
+ f"[NonContext Cardinality] Prepare training data | n_rows={len(parent_data_enriched)} | time={time.time() - t0:.2f}s"
663
726
  )
664
727
 
665
728
  return parent_data_enriched
@@ -758,7 +821,7 @@ def prepare_training_pairs_for_fk_model(
758
821
  labels_pd = pd.Series(labels_vec, name="labels")
759
822
 
760
823
  n_pairs = len(parent_pd)
761
- _LOG.info(f"prepare_training_pairs_for_fk_model | n_pairs: {n_pairs} | time: {time.time() - t0:.2f}s")
824
+ _LOG.info(f"[NonContext Matching] Prepare training pairs | n_pairs={n_pairs} | time={time.time() - t0:.2f}s")
762
825
  return parent_pd, tgt_pd, labels_pd
763
826
 
764
827
 
@@ -790,6 +853,13 @@ def train_fk_model(
790
853
  val_loader = DataLoader(val_ds, batch_size=BATCH_SIZE, shuffle=False)
791
854
 
792
855
  optimizer = torch.optim.Adam(model.parameters(), lr=LEARNING_RATE)
856
+ scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(
857
+ optimizer,
858
+ mode="min",
859
+ factor=LR_SCHEDULER_FACTOR,
860
+ patience=LR_SCHEDULER_PATIENCE,
861
+ min_lr=LR_SCHEDULER_MIN_LR,
862
+ )
793
863
 
794
864
  # calculate class imbalance for loss weighting
795
865
  num_positives = int(labels.sum())
@@ -830,12 +900,16 @@ def train_fk_model(
830
900
  val_loss /= val_size
831
901
  val_losses.append(val_loss)
832
902
 
903
+ scheduler.step(val_loss)
904
+ current_lr = optimizer.param_groups[0]["lr"]
905
+
833
906
  progress_msg = {
834
907
  "epoch": epoch,
835
908
  "train_loss": round(train_loss, 4),
836
909
  "val_loss": round(val_loss, 4),
910
+ "lr": f"{current_lr:.2e}",
837
911
  }
838
- _LOG.info(progress_msg)
912
+ _LOG.info(f"[NonContext Matching] {progress_msg}")
839
913
 
840
914
  if val_loss < best_val_loss - EARLY_STOPPING_DELTA:
841
915
  epochs_no_improve = 0
@@ -845,13 +919,13 @@ def train_fk_model(
845
919
  else:
846
920
  epochs_no_improve += 1
847
921
  if epochs_no_improve >= PATIENCE:
848
- _LOG.info("early stopping: val_loss stopped improving")
922
+ _LOG.info("[NonContext Matching] Early stopping | reason=val_loss_plateau")
849
923
  break
850
924
 
851
925
  assert best_model_state is not None
852
926
  model.load_state_dict(best_model_state)
853
927
  _LOG.info(
854
- f"train_fk_model() | time: {time.time() - t0:.2f}s | best_epoch: {best_epoch} | best_val_loss: {best_val_loss:.4f}"
928
+ f"[NonContext Matching] Train FK model | time={time.time() - t0:.2f}s | best_epoch={best_epoch} | best_val_loss={best_val_loss:.4f}"
855
929
  )
856
930
 
857
931
 
@@ -894,7 +968,8 @@ def load_fk_model(*, fk_model_workspace_dir: Path) -> ParentChildMatcher:
894
968
  child_cardinalities=model_config["child_encoder"]["cardinalities"],
895
969
  sub_column_embedding_dim=model_config["parent_encoder"]["sub_column_embedding_dim"],
896
970
  entity_hidden_dim=model_config["parent_encoder"]["entity_hidden_dim"],
897
- entity_embedding_dim=model_config["parent_encoder"]["entity_embedding_dim"],
971
+ parent_entity_embedding_dim=model_config["parent_encoder"]["entity_embedding_dim"],
972
+ child_entity_embedding_dim=model_config["child_encoder"]["entity_embedding_dim"],
898
973
  )
899
974
  model_state_path = matching_model_dir / "model_weights.pt"
900
975
  model.load_state_dict(torch.load(model_state_path))
@@ -988,11 +1063,11 @@ def sample_best_parents(
988
1063
  total_initial_capacity = sum(remaining_capacity.get(pid, 0) for pid in parent_ids)
989
1064
 
990
1065
  _LOG.info(
991
- f"FK matching with capacity enforcement | "
992
- f"n_children: {n_tgt} | "
993
- f"n_parents: {len(parent_ids)} | "
994
- f"total_capacity: {total_initial_capacity} | "
995
- f"capacity_deficit: {n_tgt - total_initial_capacity}"
1066
+ f"[NonContext Matching] FK matching with capacity enforcement | "
1067
+ f"n_children={n_tgt} | "
1068
+ f"n_parents={len(parent_ids)} | "
1069
+ f"total_capacity={total_initial_capacity} | "
1070
+ f"capacity_deficit={n_tgt - total_initial_capacity}"
996
1071
  )
997
1072
 
998
1073
  for child_idx in range(n_tgt):
@@ -1104,10 +1179,10 @@ def initialize_remaining_capacity(
1104
1179
  remaining_capacity = {}
1105
1180
  total_parents = 0
1106
1181
 
1107
- _LOG.info(f"Generating cardinality predictions in chunks for parent table {parent_table.name}")
1182
+ _LOG.info(f"[NonContext Cardinality] Generate predictions | table={parent_table.name}")
1108
1183
  for chunk_idx, parent_chunk in enumerate(parent_table.read_chunks(do_coerce_dtypes=True)):
1109
1184
  chunk_size = len(parent_chunk)
1110
- _LOG.info(f"Processing cardinality chunk {chunk_idx} with {chunk_size} parents")
1185
+ _LOG.info(f"[NonContext Cardinality] Process chunk | chunk_idx={chunk_idx} | chunk_size={chunk_size}")
1111
1186
 
1112
1187
  engine.generate(
1113
1188
  seed_data=parent_chunk[
@@ -1130,7 +1205,7 @@ def initialize_remaining_capacity(
1130
1205
 
1131
1206
  total_capacity = sum(remaining_capacity.values())
1132
1207
  _LOG.info(
1133
- f"initialize_remaining_capacity | total_parents: {total_parents} | total_capacity: {total_capacity} | time: {time.time() - t0:.2f}s"
1208
+ f"[NonContext Cardinality] Initialize remaining capacity | total_parents={total_parents} | total_capacity={total_capacity} | time={time.time() - t0:.2f}s"
1134
1209
  )
1135
1210
 
1136
1211
  return remaining_capacity
@@ -1185,7 +1260,7 @@ def match_non_context(
1185
1260
  non_null_mask = ~null_mask
1186
1261
 
1187
1262
  _LOG.info(
1188
- f"FK matching data | total_rows: {len(tgt_data)} | null_rows: {null_mask.sum()} | non_null_rows: {non_null_mask.sum()}"
1263
+ f"[NonContext Matching] FK matching data | total_rows={len(tgt_data)} | null_rows={null_mask.sum()} | non_null_rows={non_null_mask.sum()}"
1189
1264
  )
1190
1265
 
1191
1266
  if non_null_mask.sum() == 0:
@@ -1202,7 +1277,9 @@ def match_non_context(
1202
1277
  if is_null_col in tgt_data_non_null.columns:
1203
1278
  tgt_data_non_null = tgt_data_non_null.drop(columns=[is_null_col])
1204
1279
  else:
1205
- _LOG.info(f"FK matching data | total_rows: {len(tgt_data)} | null_rows: 0 | non_null_rows: {len(tgt_data)}")
1280
+ _LOG.info(
1281
+ f"[NonContext Matching] FK matching data | total_rows={len(tgt_data)} | null_rows=0 | non_null_rows={len(tgt_data)}"
1282
+ )
1206
1283
  tgt_data_non_null = tgt_data.copy()
1207
1284
  non_null_indices = tgt_data.index.tolist()
1208
1285
  non_null_mask = pd.Series(True, index=tgt_data.index)
@@ -1228,7 +1305,7 @@ def match_non_context(
1228
1305
 
1229
1306
  fk_parent_sample_size = len(parent_encoded)
1230
1307
  _LOG.info(
1231
- f"FK model matching | temperature: {temperature} | top_k: {top_k} | top_p: {top_p} | parent_sample_size: {fk_parent_sample_size}"
1308
+ f"[NonContext Matching] FK model matching | temperature={temperature} | top_k={top_k} | top_p={top_p} | parent_sample_size={fk_parent_sample_size}"
1232
1309
  )
1233
1310
 
1234
1311
  prob_matrix = build_parent_child_probabilities(
@@ -1256,6 +1333,6 @@ def match_non_context(
1256
1333
 
1257
1334
  n_matched = non_null_mask.sum()
1258
1335
  n_null = (~non_null_mask).sum()
1259
- _LOG.info(f"FK matching completed | matched: {n_matched} | null: {n_null}")
1336
+ _LOG.info(f"[NonContext Matching] FK matching completed | matched={n_matched} | null={n_null}")
1260
1337
 
1261
1338
  return tgt_data
@@ -429,7 +429,7 @@ def process_table_with_fk_models(
429
429
  batch_data = chunk_data.iloc[batch_start:batch_end].copy()
430
430
 
431
431
  sampled_parent_keys = parent_keys_df.sample(
432
- n=parent_batch_size, replace=len(parent_keys_df) < parent_batch_size
432
+ n=min(parent_batch_size, len(parent_keys_df)), replace=False
433
433
  )[parent_pk].tolist()
434
434
 
435
435
  parent_data = parent_table.read_data(
@@ -77,6 +77,8 @@ def train_fk_matching_model(
77
77
  tgt_data: pd.DataFrame,
78
78
  parent_primary_key: str,
79
79
  tgt_parent_key: str,
80
+ parent_encoding_types: dict[str, any] | None,
81
+ tgt_encoding_types: dict[str, any] | None,
80
82
  fk_model_workspace_dir: Path,
81
83
  ):
82
84
  """
@@ -90,6 +92,8 @@ def train_fk_matching_model(
90
92
  tgt_data: Target/child table data
91
93
  parent_primary_key: Primary key column in parent data
92
94
  tgt_parent_key: Foreign key column in target data
95
+ parent_encoding_types: User-defined encoding types for parent columns
96
+ tgt_encoding_types: User-defined encoding types for target columns
93
97
  fk_model_workspace_dir: Directory to save model artifacts
94
98
  """
95
99
  tgt_data_columns = [c for c in tgt_data.columns if c != tgt_parent_key]
@@ -101,6 +105,7 @@ def train_fk_matching_model(
101
105
  df=tgt_data,
102
106
  parent_key=tgt_parent_key,
103
107
  data_columns=tgt_data_columns,
108
+ encoding_types=tgt_encoding_types,
104
109
  stats_dir=tgt_stats_dir,
105
110
  )
106
111
 
@@ -109,6 +114,7 @@ def train_fk_matching_model(
109
114
  df=parent_data,
110
115
  primary_key=parent_primary_key,
111
116
  data_columns=parent_data_columns,
117
+ encoding_types=parent_encoding_types,
112
118
  stats_dir=parent_stats_dir,
113
119
  )
114
120
 
@@ -171,6 +177,7 @@ def train_cardinality_model(
171
177
  cardinality_workspace_dir = fk_model_workspace_dir / "cardinality_model"
172
178
  cardinality_workspace_dir.mkdir(parents=True, exist_ok=True)
173
179
 
180
+ _LOG.info(f"[NonContext Cardinality] Split data | n_rows={len(parent_data)}")
174
181
  engine.split(
175
182
  tgt_data=parent_data,
176
183
  tgt_primary_key=parent_primary_key,
@@ -178,16 +185,19 @@ def train_cardinality_model(
178
185
  update_progress=lambda **kwargs: None,
179
186
  )
180
187
 
188
+ _LOG.info("[NonContext Cardinality] Analyze data")
181
189
  engine.analyze(
182
190
  workspace_dir=cardinality_workspace_dir,
183
191
  update_progress=lambda **kwargs: None,
184
192
  )
185
193
 
194
+ _LOG.info("[NonContext Cardinality] Encode data")
186
195
  engine.encode(
187
196
  workspace_dir=cardinality_workspace_dir,
188
197
  update_progress=lambda **kwargs: None,
189
198
  )
190
199
 
200
+ _LOG.info("[NonContext Cardinality] Train model | model=MOSTLY_AI/Medium")
191
201
  engine.train(
192
202
  model="MOSTLY_AI/Medium",
193
203
  workspace_dir=cardinality_workspace_dir,
@@ -236,8 +246,7 @@ def train_non_context_models_for_single_relation(
236
246
  tgt_empty_or_key_only = tgt_data.empty or len(tgt_data.columns) <= 1
237
247
  if parent_empty_or_key_only or tgt_empty_or_key_only:
238
248
  _LOG.info(
239
- f"Skipping FK model training for {tgt_table_name}.{tgt_parent_key} -> {parent_table_name}.{parent_primary_key}: "
240
- f"parent or target data is empty or contains only key columns."
249
+ f"[NonContext] Skip FK model training | relation={tgt_table_name}.{tgt_parent_key}->{parent_table_name}.{parent_primary_key} | reason=empty_or_key_only"
241
250
  )
242
251
  return
243
252
 
@@ -247,17 +256,28 @@ def train_non_context_models_for_single_relation(
247
256
  children_counts = tgt_data[tgt_parent_key].value_counts()
248
257
  children_counts_mapped = parent_data[parent_primary_key].map(children_counts).fillna(0).astype(int)
249
258
  parent_data_with_counts = parent_data.assign(**{CHILDREN_COUNT_COLUMN_NAME: children_counts_mapped})
259
+ max_count = children_counts_mapped.max() if len(children_counts_mapped) > 0 else 0
260
+ avg_count = children_counts_mapped.mean() if len(children_counts_mapped) > 0 else 0
261
+ _LOG.info(
262
+ f"[NonContext] Prepare parent data with children counts | max_children={max_count} | avg_children={avg_count:.2f}"
263
+ )
250
264
 
251
- _LOG.info(f"Training FK matching model for {tgt_table_name}.{tgt_parent_key}")
265
+ _LOG.info(
266
+ f"[NonContext Matching] Train FK matching model | relation={tgt_table_name}.{tgt_parent_key}->{parent_table_name}.{parent_primary_key}"
267
+ )
252
268
  train_fk_matching_model(
253
269
  parent_data=parent_data_with_counts,
254
270
  tgt_data=tgt_data,
255
271
  parent_primary_key=parent_primary_key,
256
272
  tgt_parent_key=tgt_parent_key,
273
+ parent_encoding_types=parent_table.encoding_types,
274
+ tgt_encoding_types=tgt_table.encoding_types,
257
275
  fk_model_workspace_dir=fk_model_workspace_dir,
258
276
  )
259
277
 
260
- _LOG.info(f"Training cardinality model for {tgt_table_name}.{tgt_parent_key}")
278
+ _LOG.info(
279
+ f"[NonContext Cardinality] Train cardinality model | relation={tgt_table_name}.{tgt_parent_key}->{parent_table_name}.{parent_primary_key}"
280
+ )
261
281
  train_cardinality_model(
262
282
  parent_data=parent_data_with_counts,
263
283
  parent_primary_key=parent_primary_key,
@@ -265,8 +285,8 @@ def train_non_context_models_for_single_relation(
265
285
  )
266
286
 
267
287
  _LOG.info(
268
- f"Trained FK matching and cardinality models for {tgt_table_name}.{tgt_parent_key} -> {parent_table_name}.{parent_primary_key} | "
269
- f"time: {time.time() - t0:.2f}s | models saved: {fk_model_workspace_dir}"
288
+ f"[NonContext] All models trained | relation={tgt_table_name}.{tgt_parent_key}->{parent_table_name}.{parent_primary_key} | "
289
+ f"time={time.time() - t0:.2f}s | workspace={fk_model_workspace_dir}"
270
290
  )
271
291
 
272
292
 
@@ -306,7 +326,9 @@ def execute_step_finalize_training(
306
326
  update_progress=progress.update,
307
327
  )
308
328
  except Exception as e:
309
- _LOG.error(f"FK model training failed for table {tgt_table_name}: {e}\n{traceback.format_exc()}")
329
+ _LOG.error(
330
+ f"[NonContext] FK model training failed | table={tgt_table_name} | error={e}\n{traceback.format_exc()}"
331
+ )
310
332
  continue
311
333
  finally:
312
334
  clean_up_non_context_models_dirs(fk_models_workspace_dir=fk_models_workspace_dir)
@@ -343,4 +343,4 @@ class _MostlySyntheticProbesClient(_MostlyBaseClient):
343
343
  path=[],
344
344
  json=config,
345
345
  )
346
- return {dct["name"]: pd.DataFrame(dct["rows"]) for dct in dicts}
346
+ return {dct["name"]: pd.DataFrame(dct["rows"]).convert_dtypes() for dct in dicts}
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  # generated by datamodel-codegen:
16
- # timestamp: 2025-11-07T15:38:13+00:00
16
+ # timestamp: 2025-11-13T13:21:07+00:00
17
17
 
18
18
  from __future__ import annotations
19
19
 
@@ -2448,7 +2448,7 @@ class Connector(CustomBaseModel):
2448
2448
  df = c.query("SELECT count(*) FROM schema.table") # for DB connectors
2449
2449
  df = c.query("SELECT count(*) FROM read_csv_auto('s3://bucket/path/to/file.csv')") # query a single CSV file from S3 storage
2450
2450
  df = c.query("SELECT count(*) FROM read_parquet('gs://bucket/path/to/folder/*.parquet')") # query a folder with PQT files from GCP storage
2451
- df = c.query("SELECT count(*) FROM read_json('az://bucket/path/to/file.json')") # query a single JSON file from AZURE storage
2451
+ df = c.query("SELECT count(*) FROM read_json_auto('az://bucket/path/to/file.json')") # query a single JSON file from AZURE storage
2452
2452
  ```
2453
2453
  """
2454
2454
  return self.client._query(connector_id=self.id, sql=sql)
@@ -3492,6 +3492,16 @@ class CurrentUser(CustomBaseModel):
3492
3492
  None,
3493
3493
  description="The list of secret key names for this user (secret values are never exposed via API)",
3494
3494
  )
3495
+ created_at: AwareDatetime | None = Field(
3496
+ None,
3497
+ alias="createdAt",
3498
+ description="The UTC date and time when the user has been created.",
3499
+ )
3500
+ last_activity_at: AwareDatetime | None = Field(
3501
+ None,
3502
+ alias="lastActivityAt",
3503
+ description="The UTC date and time of users last activity",
3504
+ )
3495
3505
 
3496
3506
 
3497
3507
  class Generator(CustomBaseModel):
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mostlyai"
3
- version = "5.6.0"
3
+ version = "5.7.0"
4
4
  description = "Synthetic Data SDK"
5
5
  authors = [{ name = "MOSTLY AI", email = "dev@mostly.ai" }]
6
6
  requires-python = ">=3.10,<3.14"
@@ -50,7 +50,7 @@ dependencies = [
50
50
  local = [
51
51
  # "mostlyai-engine @ git+https://github.com/mostly-ai/mostlyai-engine.git@main", # for development
52
52
  # "mostlyai-qa @ git+https://github.com/mostly-ai/mostlyai-qa.git@main", # for development
53
- "mostlyai-engine==2.0.0", # for release
53
+ "mostlyai-engine==2.0.1", # for release
54
54
  "mostlyai-qa==1.9.8", # for release
55
55
  "fastapi>=0.115.6,<0.116",
56
56
  "uvicorn>=0.34.0,<0.35",
@@ -76,7 +76,7 @@ local = [
76
76
  local-gpu = [
77
77
  # "mostlyai-engine[gpu] @ git+https://github.com/mostly-ai/mostlyai-engine.git@main", # for development
78
78
  # "mostlyai-qa @ git+https://github.com/mostly-ai/mostlyai-qa.git@main", # for development
79
- "mostlyai-engine[gpu]==2.0.0", # for release
79
+ "mostlyai-engine[gpu]==2.0.1", # for release
80
80
  "mostlyai-qa==1.9.8", # for release
81
81
  "fastapi>=0.115.6,<0.116",
82
82
  "uvicorn>=0.34.0,<0.35",
File without changes
File without changes
File without changes
File without changes