Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions mostlyai/sdk/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2680,11 +2680,9 @@ def add_model_configuration(cls, values):
else:
has_tabular_model = True
has_language_model = False
if values.foreign_keys:
# Always train tabular model for linked tables to model sequences
for fk in values.foreign_keys:
if fk.is_context:
has_tabular_model = True
# Always train tabular model for tables with a primary key or linked tables to model sequences
if values.primary_key or (values.foreign_keys and any(fk.is_context for fk in values.foreign_keys)):
has_tabular_model = True
# Remove model configurations that are not applicable for the model type
if values.tabular_model_configuration and not has_tabular_model:
values.tabular_model_configuration = None
Expand Down
13 changes: 13 additions & 0 deletions tests/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ def assert_model_configuration(s: SourceTableConfig, has_tabular_model: bool, ha
s = SourceTableConfig(**{"name": "tbl1", "primary_key": "id", "columns": [{"name": "id"}]})
assert_model_configuration(s, has_tabular_model=True, has_language_model=False)

# PK + language column (id: pk, name: lang_text)
s = SourceTableConfig(
**{
"name": "tbl1",
"primary_key": "id",
"columns": [
{"name": "id", "model_encoding_type": ModelEncodingType.tabular_categorical},
{"name": "name", "model_encoding_type": ModelEncodingType.language_text},
],
}
)
assert_model_configuration(s, has_tabular_model=True, has_language_model=True)

# PK + FK columns
s = SourceTableConfig(
**{
Expand Down
8 changes: 3 additions & 5 deletions tools/custom_template/pydantic_v2/BaseModel.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,9 @@ class {{ class_name }}({{ base_class }}):{% if comment is defined %} # {{ comme
else:
has_tabular_model = True
has_language_model = False
if values.foreign_keys:
# Always train tabular model for linked tables to model sequences
for fk in values.foreign_keys:
if fk.is_context:
has_tabular_model = True
# Always train tabular model for tables with a primary key or linked tables to model sequences
if values.primary_key or (values.foreign_keys and any(fk.is_context for fk in values.foreign_keys)):
has_tabular_model = True
# Remove model configurations that are not applicable for the model type
if values.tabular_model_configuration and not has_tabular_model:
values.tabular_model_configuration = None
Expand Down
8 changes: 3 additions & 5 deletions tools/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,9 @@ def add_model_configuration(cls, values):
else:
has_tabular_model = True
has_language_model = False
if values.foreign_keys:
# Always train tabular model for linked tables to model sequences
for fk in values.foreign_keys:
if fk.is_context:
has_tabular_model = True
# Always train tabular model for tables with a primary key or linked tables to model sequences
if values.primary_key or (values.foreign_keys and any(fk.is_context for fk in values.foreign_keys)):
has_tabular_model = True
# Remove model configurations that are not applicable for the model type
if values.tabular_model_configuration and not has_tabular_model:
values.tabular_model_configuration = None
Expand Down