mdmodels 0.3.1__tar.gz → 0.4.1__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 (162) hide show
  1. {mdmodels-0.3.1 → mdmodels-0.4.1}/.github/workflows/lint.yml +1 -0
  2. {mdmodels-0.3.1 → mdmodels-0.4.1}/PKG-INFO +3 -3
  3. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/integrations/cli.mdx +6 -1
  4. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/config.py +27 -4
  5. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/library.py +17 -3
  6. mdmodels-0.4.1/mdmodels/mcp/create.py +114 -0
  7. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/relations.py +6 -1
  8. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/config.py +19 -0
  9. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/vector.py +13 -3
  10. {mdmodels-0.3.1 → mdmodels-0.4.1}/pyproject.toml +6 -2
  11. mdmodels-0.4.1/tests/unit/test_embedding_config.py +173 -0
  12. {mdmodels-0.3.1 → mdmodels-0.4.1}/uv.lock +45 -45
  13. mdmodels-0.3.1/mdmodels/mcp/create.py +0 -100
  14. {mdmodels-0.3.1 → mdmodels-0.4.1}/.github/scripts/start_ollama.sh +0 -0
  15. {mdmodels-0.3.1 → mdmodels-0.4.1}/.github/workflows/publish.yml +0 -0
  16. {mdmodels-0.3.1 → mdmodels-0.4.1}/.github/workflows/test-publish.yml +0 -0
  17. {mdmodels-0.3.1 → mdmodels-0.4.1}/.github/workflows/test.yml +0 -0
  18. {mdmodels-0.3.1 → mdmodels-0.4.1}/.gitignore +0 -0
  19. {mdmodels-0.3.1 → mdmodels-0.4.1}/Dockerfile +0 -0
  20. {mdmodels-0.3.1 → mdmodels-0.4.1}/README.md +0 -0
  21. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/.gitignore +0 -0
  22. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/README.md +0 -0
  23. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/astro.config.mjs +0 -0
  24. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/package-lock.json +0 -0
  25. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/package.json +0 -0
  26. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/public/favicon.svg +0 -0
  27. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/assets/houston.webp +0 -0
  28. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/assets/logo.svg +0 -0
  29. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/config.ts +0 -0
  30. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/converting-formats.mdx +0 -0
  31. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/creating-data.mdx +0 -0
  32. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/index.mdx +0 -0
  33. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/library.mdx +0 -0
  34. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/multiple-models.mdx +0 -0
  35. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/parsing.mdx +0 -0
  36. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/querying.mdx +0 -0
  37. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/serialization.mdx +0 -0
  38. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/basic/validation.mdx +0 -0
  39. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/databases/graphdb.mdx +0 -0
  40. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/databases/sql.mdx +0 -0
  41. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/databases/vector.mdx +0 -0
  42. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/installation.mdx +0 -0
  43. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/integrations/fastapi.mdx +0 -0
  44. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/integrations/fastmcp.mdx +0 -0
  45. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content/docs/integrations/graphql.mdx +0 -0
  46. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/content.config.ts +0 -0
  47. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/src/styles/styles.css +0 -0
  48. {mdmodels-0.3.1 → mdmodels-0.4.1}/docs/tsconfig.json +0 -0
  49. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/basic/BasicExample.ipynb +0 -0
  50. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/basic/model.jl +0 -0
  51. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/basic/model.md +0 -0
  52. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/basic/model.rs +0 -0
  53. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/basic/model.xsd +0 -0
  54. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/basic/uml_diagram.md +0 -0
  55. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/graph/Neo4JExample.ipynb +0 -0
  56. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/graph/model.md +0 -0
  57. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/graph/startn4j.sh +0 -0
  58. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/sql/basic/SQLDatabaseExample.ipynb +0 -0
  59. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/sql/basic/model.md +0 -0
  60. {mdmodels-0.3.1 → mdmodels-0.4.1}/examples/sql/basic/projects.json +0 -0
  61. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/__init__.py +0 -0
  62. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/adder_method.py +0 -0
  63. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/cli.py +0 -0
  64. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/create.py +0 -0
  65. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/datamodel.py +0 -0
  66. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/git_utils.py +0 -0
  67. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graph/__init__.py +0 -0
  68. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graph/basenode.py +0 -0
  69. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graph/connector.py +0 -0
  70. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graph/create.py +0 -0
  71. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graph/relation.py +0 -0
  72. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graphql/__init__.py +0 -0
  73. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/graphql/create.py +0 -0
  74. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/llm/__init__.py +0 -0
  75. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/llm/handler.py +0 -0
  76. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/__init__.py +0 -0
  77. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/auth.py +0 -0
  78. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/config.py +0 -0
  79. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/__init__.py +0 -0
  80. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/annotation.py +0 -0
  81. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/constants.py +0 -0
  82. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/create.py +0 -0
  83. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/embedding.py +0 -0
  84. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/middleware.py +0 -0
  85. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/naming.py +0 -0
  86. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/ownership.py +0 -0
  87. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/relationships_types.py +0 -0
  88. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/runtime.py +0 -0
  89. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/__init__.py +0 -0
  90. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/_assets.py +0 -0
  91. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/aggregate.py +0 -0
  92. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/annotate.py +0 -0
  93. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/assets/data_entry_form.html +0 -0
  94. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/assets/downloader.html +0 -0
  95. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/assets/plot_viewer.html +0 -0
  96. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/assets/tabular_upload.html +0 -0
  97. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/download.py +0 -0
  98. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/form.py +0 -0
  99. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/form_store.py +0 -0
  100. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/plot.py +0 -0
  101. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/relationships.py +0 -0
  102. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/schema.py +0 -0
  103. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/select.py +0 -0
  104. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/tabular.py +0 -0
  105. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/upsert.py +0 -0
  106. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/sql/tools/vector_search.py +0 -0
  107. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/mcp/types.py +0 -0
  108. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/meta.py +0 -0
  109. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/path.py +0 -0
  110. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/reference.py +0 -0
  111. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/rest/__init__.py +0 -0
  112. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/rest/config.py +0 -0
  113. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/rest/create.py +0 -0
  114. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/rest/search.py +0 -0
  115. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/__init__.py +0 -0
  116. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/aggregation.py +0 -0
  117. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/base.py +0 -0
  118. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/childref.py +0 -0
  119. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/connector.py +0 -0
  120. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/create.py +0 -0
  121. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/filter.py +0 -0
  122. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/groupby.py +0 -0
  123. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/insert.py +0 -0
  124. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/linked_type.py +0 -0
  125. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/migrations.py +0 -0
  126. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/upsert.py +0 -0
  127. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/sql/utils.py +0 -0
  128. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/templates.py +0 -0
  129. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/units/__init__.py +0 -0
  130. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/units/annotation.py +0 -0
  131. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/units/converter.py +0 -0
  132. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/units/mappings.py +0 -0
  133. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/units/unit_definition.py +0 -0
  134. {mdmodels-0.3.1 → mdmodels-0.4.1}/mdmodels/utils.py +0 -0
  135. {mdmodels-0.3.1 → mdmodels-0.4.1}/run-tests.sh +0 -0
  136. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/__init__.py +0 -0
  137. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/expected_json.json +0 -0
  138. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/expected_units.json +0 -0
  139. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/expected_units_complex.json +0 -0
  140. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/expected_wrapped_xml.xml +0 -0
  141. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/expected_xml.xml +0 -0
  142. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model.md +0 -0
  143. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_database.md +0 -0
  144. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_graph.md +0 -0
  145. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_json_schema.json +0 -0
  146. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_multiple_types.md +0 -0
  147. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_recursion.md +0 -0
  148. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_units.md +0 -0
  149. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/fixtures/model_wrapped_xml.md +0 -0
  150. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/__init__.py +0 -0
  151. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/conftest.py +0 -0
  152. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/test_conversion.py +0 -0
  153. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/test_db.py +0 -0
  154. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/test_from_json_schema.py +0 -0
  155. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/test_graph.py +0 -0
  156. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/test_llm.py +0 -0
  157. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/integration/test_parse.py +0 -0
  158. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/unit/__init__.py +0 -0
  159. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/unit/test_create.py +0 -0
  160. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/unit/test_datamodel.py +0 -0
  161. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/unit/test_git_utils.py +0 -0
  162. {mdmodels-0.3.1 → mdmodels-0.4.1}/tests/unit/test_unit_definition.py +0 -0
@@ -19,6 +19,7 @@ jobs:
19
19
  - uses: actions/checkout@v4
20
20
  - uses: astral-sh/ruff-action@v2
21
21
  with:
22
+ version: "0.17.0"
22
23
  src: >-
23
24
  mdmodels/
24
25
  tests/
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: mdmodels
3
- Version: 0.3.1
3
+ Version: 0.4.1
4
4
  Summary: Python package for the MDModels Rust crate
5
5
  Author-email: Jan Range <range.jan@web.de>
6
6
  License-Expression: MIT
@@ -11,7 +11,7 @@ Requires-Dist: dotenv>=0.9.9
11
11
  Requires-Dist: dotted-dict<2,>=1.1.3
12
12
  Requires-Dist: fastexcel>=0.19.0
13
13
  Requires-Dist: httpx<0.29,>=0.28
14
- Requires-Dist: mdmodels-core<0.3,>=0.2.9
14
+ Requires-Dist: mdmodels-core<0.4,>=0.3.1
15
15
  Requires-Dist: nest-asyncio<2,>=1.6.0
16
16
  Requires-Dist: pandas>=2.2.3
17
17
  Requires-Dist: polars>=1.39.3
@@ -290,7 +290,7 @@ Embedding settings can be added under `[sql.tables.<TableName>.embedding]`:
290
290
 
291
291
  - `column` (`string`, required when embedding is used)
292
292
  - `model` (`string`, required)
293
- - `provider` (`openai | huggingface`, required)
293
+ - `provider` (`openai | huggingface | fastembed`, required)
294
294
  - `dimension` (`int`, optional)
295
295
 
296
296
  Provider-specific subsections:
@@ -303,6 +303,11 @@ Provider-specific subsections:
303
303
  - `device` (`string`, optional)
304
304
  - `batch_size` (`int`, default `32`)
305
305
  - `normalize_embeddings` (`bool`, default `true`)
306
+ - `trust_remote_code` (`bool`, default `false`)
307
+
308
+ - `[sql.tables.<TableName>.embedding.fastembed]`
309
+ - `cache_dir` (`string`, optional)
310
+ - `batch_size` (`int`, optional)
306
311
 
307
312
  ## `rest` Section
308
313
 
@@ -24,6 +24,7 @@ SQLDatabaseType = Literal[
24
24
  EmbeddingProvider = Literal[
25
25
  "openai",
26
26
  "huggingface",
27
+ "fastembed",
27
28
  ]
28
29
  AuthMethod = Literal["oidc"]
29
30
 
@@ -64,6 +65,14 @@ class HuggingFaceEmbeddingConfig(BaseModel):
64
65
  device: Optional[str] = None
65
66
  batch_size: int = 32
66
67
  normalize_embeddings: bool = True
68
+ trust_remote_code: bool = False
69
+
70
+
71
+ class FastembedEmbeddingConfig(BaseModel):
72
+ """Provider-specific FastEmbed embedding settings."""
73
+
74
+ cache_dir: Optional[str] = None
75
+ batch_size: Optional[int] = None
67
76
 
68
77
 
69
78
  class SQLEmbeddingConfig(BaseModel):
@@ -75,16 +84,30 @@ class SQLEmbeddingConfig(BaseModel):
75
84
  dimension: Optional[int] = None
76
85
  openai: Optional[OpenAIEmbeddingConfig] = None
77
86
  huggingface: Optional[HuggingFaceEmbeddingConfig] = None
87
+ fastembed: Optional[FastembedEmbeddingConfig] = None
78
88
 
79
89
  @model_validator(mode="after")
80
90
  def validate_provider_settings(self) -> "SQLEmbeddingConfig":
81
- if self.provider == "openai" and self.huggingface is not None:
91
+ if self.provider == "openai" and (
92
+ self.huggingface is not None or self.fastembed is not None
93
+ ):
94
+ raise ValueError(
95
+ "embedding.huggingface and embedding.fastembed are not allowed "
96
+ "when embedding.provider='openai'"
97
+ )
98
+ if self.provider == "huggingface" and (
99
+ self.openai is not None or self.fastembed is not None
100
+ ):
82
101
  raise ValueError(
83
- "embedding.huggingface is not allowed when embedding.provider='openai'"
102
+ "embedding.openai and embedding.fastembed are not allowed "
103
+ "when embedding.provider='huggingface'"
84
104
  )
85
- if self.provider == "huggingface" and self.openai is not None:
105
+ if self.provider == "fastembed" and (
106
+ self.openai is not None or self.huggingface is not None
107
+ ):
86
108
  raise ValueError(
87
- "embedding.openai is not allowed when embedding.provider='huggingface'"
109
+ "embedding.openai and embedding.huggingface are not allowed "
110
+ "when embedding.provider='fastembed'"
88
111
  )
89
112
  return self
90
113
 
@@ -328,11 +328,17 @@ class Library(DottedDict, Generic[T]):
328
328
  Returns:
329
329
  Library[SQLModel]: A library containing SQLModel classes
330
330
  """
331
- from sqlmodel import SQLModel
332
-
331
+
332
+ try:
333
+ from sqlmodel import SQLModel
334
+ except ImportError:
335
+ raise ImportError(
336
+ "SQLModel is not installed. Please install it with `pip install mdmodels[postgres]`."
337
+ )
338
+
339
+ from .sql import generate_sqlmodel
333
340
  from mdmodels import DataModel
334
341
 
335
- from .sql import generate_sqlmodel
336
342
 
337
343
  # assert self.type == "DataModel", "Library must contain DataModel instances"
338
344
 
@@ -352,6 +358,14 @@ class Library(DottedDict, Generic[T]):
352
358
  Returns:
353
359
  Library[BaseNode]: A library containing BaseNode classes
354
360
  """
361
+
362
+ try:
363
+ import neomodel # noqa: F401 (availability check)
364
+ except ImportError:
365
+ raise ImportError(
366
+ "NeoModel is not installed. Please install it with `pip install mdmodels[neo4j]`."
367
+ )
368
+
355
369
  from .datamodel import DataModel
356
370
  from .graph import generate_neomodel
357
371
 
@@ -0,0 +1,114 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Dict, Optional
4
+
5
+ from fastmcp import FastMCP
6
+
7
+ from mdmodels.config import AuthMethod
8
+ from mdmodels.mcp.config import MCPConfig
9
+ from mdmodels.sql.connector import DatabaseConnector
10
+
11
+ from .sql import create_sql_mcp_tools
12
+
13
+
14
+ def create_mcp_tools(
15
+ *,
16
+ app: FastMCP,
17
+ db: DatabaseConnector,
18
+ config: Optional[Dict[str, MCPConfig]] = None,
19
+ all_create: bool = False,
20
+ auth: Optional[AuthMethod] = None,
21
+ ) -> None:
22
+ """Register the MCP tools for a model on a FastMCP application.
23
+
24
+ Main entry point for exposing a database built from an MD-Models model to
25
+ LLM agents. Only SQL databases (`DatabaseConnector`) are supported. The tools
26
+ are implemented in `mdmodels/mcp/sql/tools/` and registered by
27
+ `mdmodels.mcp.sql.create.create_sql_mcp_tools`.
28
+
29
+ Registered tools:
30
+
31
+ **Schema**
32
+ - `Get_Table_Schema`: return the Markdown data model with all fields, types,
33
+ relationships and nesting.
34
+ - `Get_Table_Relationships`: return the foreign-key mappings of a table.
35
+
36
+ **Writing**
37
+ - `Upsert_<Object>`: one tool per object, for every object if `all_create`
38
+ is True and otherwise for the tables with `allow_create` in `config`.
39
+ Writes a nested record across the corresponding tables in one
40
+ transaction, or updates an existing record when its `row_pk` is given.
41
+ Nested fields may reference existing rows by key. Attributes are checked
42
+ for their declared types.
43
+ - `Annotate_Entries`, `Get_Annotations`: free-text annotations on rows of
44
+ any table.
45
+
46
+ **Reading**
47
+ - `Select_Table`: select rows from one table with optional filters and a
48
+ row limit.
49
+ - `Aggregate_Table`: count, sum, avg, min, max, stddev or variance over a
50
+ table, with optional filters.
51
+ - `Download_Entry`: fetch one entry by primary key as a JSON tree that can
52
+ be copied or downloaded.
53
+ - `Vector_Search`: semantic search over tables with embeddings. Registered
54
+ only when a table has an embedding column.
55
+
56
+ **Interactive apps**
57
+ - `Plot_Table`: query a table with optional filters, optionally grouped by
58
+ a column of a related table, and render the rows as an interactive chart.
59
+ - `Data_Entry`: render a typed form whose fields, labels, types and bounds
60
+ are specified by the agent. The form is not derived from the schema; the
61
+ agent maps the submitted values to columns when it calls an
62
+ `Upsert_<Object>` tool.
63
+ - `Submit_Data_Entry`: callback of the form. Checks the submitted values
64
+ against the form specification and returns them to the agent.
65
+
66
+ For the four-object `Experiment` model with `all_create=True` and no
67
+ embeddings, this registers 14 tools.
68
+
69
+ Args:
70
+ app: FastMCP application to register the tools on.
71
+ db: Database connector built from the model.
72
+ config: Per-table settings keyed by table name (`MCPConfig`):
73
+ `allow_create` registers the upsert tool for that table,
74
+ `description` replaces the upsert tool's description, and `shared`
75
+ exempts the table from ownership scoping.
76
+ all_create: Register an `Upsert_<Object>` tool for every object,
77
+ regardless of `allow_create`.
78
+ auth: Authentication method. With `"oidc"`, ownership tables are
79
+ created and tables not marked `shared` are scoped to the
80
+ authenticated user.
81
+
82
+ Raises:
83
+ ValueError: If `db` is not a `DatabaseConnector`.
84
+
85
+ Example:
86
+ ```python
87
+ from fastmcp import FastMCP
88
+ from mdmodels import DataModel
89
+ from mdmodels.mcp import create_mcp_tools
90
+ from mdmodels.sql import DatabaseConnector
91
+
92
+ library = DataModel.from_markdown("model.md")
93
+ db = DatabaseConnector(library=library, database="example.db")
94
+ db.create_tables()
95
+
96
+ app = FastMCP("my-database-tools")
97
+ create_mcp_tools(app=app, db=db, all_create=True)
98
+ ```
99
+ """
100
+
101
+ config = config or {}
102
+
103
+ if isinstance(db, DatabaseConnector):
104
+ create_sql_mcp_tools(
105
+ app=app,
106
+ db=db,
107
+ config=config,
108
+ all_create=all_create,
109
+ auth=auth,
110
+ )
111
+ else:
112
+ raise ValueError(
113
+ f"{type(db)} is not supported yet. Please use 'DatabaseConnector' instead."
114
+ )
@@ -4,7 +4,6 @@ from collections import deque
4
4
  from functools import lru_cache
5
5
  from typing import Any, Iterable, Literal, Type, TypedDict, get_origin
6
6
 
7
- from sqlalchemy.orm import RelationshipProperty
8
7
  from pydantic import BaseModel
9
8
 
10
9
  from mdmodels.utils import extract_dtype
@@ -26,6 +25,12 @@ class JoinEdge(TypedDict):
26
25
 
27
26
 
28
27
  def _is_relationship_attr(attr: Any) -> bool:
28
+ # SQLAlchemy is only installed with the SQL extras; without it there are no relationships.
29
+ try:
30
+ from sqlalchemy.orm import RelationshipProperty
31
+ except ImportError:
32
+ return False
33
+
29
34
  prop = getattr(attr, "property", None)
30
35
  return isinstance(prop, RelationshipProperty)
31
36
 
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, Dict, List, Literal, Optional
5
5
  from pydantic import BaseModel, Field, model_validator
6
6
 
7
7
  from mdmodels.sql.vector import (
8
+ FastembedTextEmbedding,
8
9
  OpenAITextEmbedding,
9
10
  SentenceTransformerEmbedding,
10
11
  TextEmbedding,
@@ -256,6 +257,24 @@ class TableConfig(BaseModel):
256
257
  normalize_embeddings=(
257
258
  huggingface_cfg.normalize_embeddings if huggingface_cfg else True
258
259
  ),
260
+ trust_remote_code=(
261
+ huggingface_cfg.trust_remote_code if huggingface_cfg else False
262
+ ),
263
+ )
264
+
265
+ if embedding.dimension is not None and embedding.dimension != model.dimension:
266
+ raise ValueError(
267
+ f"Configured embedding.dimension={embedding.dimension} does not "
268
+ f"match model dimension={model.dimension} for '{embedding.model}'"
269
+ )
270
+ return model
271
+
272
+ if embedding.provider == "fastembed":
273
+ fastembed_cfg = embedding.fastembed
274
+ model = FastembedTextEmbedding(
275
+ model_name=embedding.model,
276
+ cache_dir=fastembed_cfg.cache_dir if fastembed_cfg else None,
277
+ batch_size=fastembed_cfg.batch_size if fastembed_cfg else None,
259
278
  )
260
279
 
261
280
  if embedding.dimension is not None and embedding.dimension != model.dimension:
@@ -141,6 +141,7 @@ class SentenceTransformerEmbedding(TextEmbedding):
141
141
  device: The device to run the model on (CPU, CUDA, etc.).
142
142
  batch_size: The batch size for processing multiple texts.
143
143
  normalize_embeddings: Whether to normalize the embedding vectors.
144
+ trust_remote_code: Whether to allow execution of remote model code.
144
145
  model: The loaded SentenceTransformer model instance.
145
146
  _dimension_cache: Cached dimension value for the model.
146
147
  """
@@ -153,6 +154,7 @@ class SentenceTransformerEmbedding(TextEmbedding):
153
154
  device: str | None = None
154
155
  batch_size: int = 32
155
156
  normalize_embeddings: bool = True
157
+ trust_remote_code: bool = False
156
158
  model: Any = None
157
159
  _dimension_cache: int | None = None
158
160
 
@@ -163,6 +165,7 @@ class SentenceTransformerEmbedding(TextEmbedding):
163
165
  device: str | None = None,
164
166
  batch_size: int = 32,
165
167
  normalize_embeddings: bool = True,
168
+ trust_remote_code: bool = False,
166
169
  **kwargs: Any,
167
170
  ) -> None:
168
171
  """Initialize the SentenceTransformer embedding model.
@@ -172,6 +175,8 @@ class SentenceTransformerEmbedding(TextEmbedding):
172
175
  device: The device to run the model on.
173
176
  batch_size: The batch size for processing.
174
177
  normalize_embeddings: Whether to normalize embeddings.
178
+ trust_remote_code: Whether to allow remote code execution for model
179
+ loading when required by the selected model.
175
180
  **kwargs: Additional keyword arguments.
176
181
 
177
182
  Raises:
@@ -188,7 +193,11 @@ class SentenceTransformerEmbedding(TextEmbedding):
188
193
  "mdmodels[vector] extra."
189
194
  ) from exc
190
195
 
191
- model = SentenceTransformer(model_name, device=device)
196
+ model = SentenceTransformer(
197
+ model_name,
198
+ device=device,
199
+ trust_remote_code=trust_remote_code,
200
+ )
192
201
  dimension = model.get_sentence_embedding_dimension()
193
202
  if dimension is None:
194
203
  raise ValueError(f"Model {model_name} does not have a dimension")
@@ -201,10 +210,11 @@ class SentenceTransformerEmbedding(TextEmbedding):
201
210
  device=device, # type: ignore[arg-type]
202
211
  batch_size=batch_size, # type: ignore[arg-type]
203
212
  normalize_embeddings=normalize_embeddings, # type: ignore[arg-type]
213
+ trust_remote_code=trust_remote_code, # type: ignore[arg-type]
204
214
  model=model, # type: ignore[arg-type]
205
- _dimension_cache=dimension, # type: ignore[arg-type]
206
215
  **kwargs,
207
216
  )
217
+ self._dimension_cache = dimension
208
218
 
209
219
  def embed(self, text: str) -> EmbeddingVector:
210
220
  """Embed a single text string using SentenceTransformer.
@@ -328,13 +338,13 @@ class FastembedTextEmbedding(TextEmbedding):
328
338
  cache_dir=cache_dir, # type: ignore[arg-type]
329
339
  batch_size=batch_size, # type: ignore[arg-type]
330
340
  model=model, # type: ignore[arg-type]
331
- _dimension_cache=dimension, # type: ignore[arg-type]
332
341
  **{
333
342
  k: v
334
343
  for k, v in kwargs.items()
335
344
  if k not in ["model_name", "cache_dir", "batch_size"]
336
345
  },
337
346
  )
347
+ self._dimension_cache = dimension
338
348
 
339
349
  def _ensure_dimension(self) -> None:
340
350
  """Infer and cache the embedding dimension lazily.
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "mdmodels"
3
- version = "0.3.1"
3
+ version = "0.4.1"
4
4
  description = "Python package for the MDModels Rust crate"
5
5
  authors = [{ name = "Jan Range", email = "range.jan@web.de" }]
6
6
  requires-python = ">=3.11"
7
7
  readme = "README.md"
8
8
  license = "MIT"
9
9
  dependencies = [
10
- "mdmodels-core>=0.2.9,<0.3",
10
+ "mdmodels-core>=0.3.1,<0.4",
11
11
  "pydantic-xml>=2.12.1,<3",
12
12
  "bigtree>=0.21.1,<0.22",
13
13
  "validators>=0.34.0,<0.35",
@@ -77,3 +77,7 @@ url = "https://test.pypi.org/simple/"
77
77
 
78
78
  [tool.uv]
79
79
  prerelease = "explicit"
80
+
81
+ [tool.ruff.lint]
82
+ # Ruff 0.16 widened its default rule set; keep the rules this code is linted against.
83
+ select = ["E4", "E7", "E9", "F"]
@@ -0,0 +1,173 @@
1
+ import sys
2
+ import types
3
+
4
+ import pytest
5
+
6
+ from mdmodels.config import AppConfig, OpenAIEmbeddingConfig, SQLEmbeddingConfig
7
+ from mdmodels.sql.config import TableConfig
8
+ from mdmodels.sql.vector import SentenceTransformerEmbedding, TextEmbedding
9
+
10
+
11
+ class DummyTextEmbedding(TextEmbedding):
12
+ model_name: str
13
+ cache_dir: str | None = None
14
+ batch_size: int | None = None
15
+ trust_remote_code: bool = False
16
+
17
+ def embed(self, text: str):
18
+ return [0.0] * self.dimension
19
+
20
+ def embed_batch(self, texts):
21
+ return [[0.0] * self.dimension for _ in texts]
22
+
23
+
24
+ def test_sentence_transformer_embedding_accepts_dimension_cache_and_custom_code(
25
+ monkeypatch,
26
+ ):
27
+ class FakeSentenceTransformer:
28
+ init_kwargs = {}
29
+
30
+ def __init__(self, model_name, device=None, trust_remote_code=False):
31
+ FakeSentenceTransformer.init_kwargs = {
32
+ "model_name": model_name,
33
+ "device": device,
34
+ "trust_remote_code": trust_remote_code,
35
+ }
36
+
37
+ def get_sentence_embedding_dimension(self):
38
+ return 768
39
+
40
+ monkeypatch.setitem(
41
+ sys.modules,
42
+ "sentence_transformers",
43
+ types.SimpleNamespace(SentenceTransformer=FakeSentenceTransformer),
44
+ )
45
+
46
+ embedding = SentenceTransformerEmbedding(
47
+ model_name="sentence-transformers/all-MiniLM-L6-v2",
48
+ trust_remote_code=True,
49
+ )
50
+
51
+ assert embedding.dimension == 768
52
+ assert FakeSentenceTransformer.init_kwargs["trust_remote_code"] is True
53
+
54
+
55
+ def test_sql_embedding_config_rejects_mixed_fastembed_provider_sections():
56
+ with pytest.raises(
57
+ ValueError,
58
+ match="embedding\\.openai and embedding\\.huggingface are not allowed",
59
+ ):
60
+ SQLEmbeddingConfig(
61
+ column="description",
62
+ model="BAAI/bge-small-en-v1.5",
63
+ provider="fastembed",
64
+ openai=OpenAIEmbeddingConfig(),
65
+ )
66
+
67
+
68
+ def test_table_config_builds_fastembed_model(monkeypatch):
69
+ captured = {}
70
+
71
+ def fake_fastembed(model_name, cache_dir=None, batch_size=None):
72
+ captured.update(
73
+ {
74
+ "model_name": model_name,
75
+ "cache_dir": cache_dir,
76
+ "batch_size": batch_size,
77
+ }
78
+ )
79
+ return DummyTextEmbedding(
80
+ dimension=768,
81
+ model_name=model_name,
82
+ cache_dir=cache_dir,
83
+ batch_size=batch_size,
84
+ )
85
+
86
+ monkeypatch.setattr("mdmodels.sql.config.FastembedTextEmbedding", fake_fastembed)
87
+
88
+ config = AppConfig.model_validate(
89
+ {
90
+ "model": {"path": "specifications/model.md"},
91
+ "sql": {
92
+ "type": "pgvector",
93
+ "tables": {
94
+ "StrendaBiocatalysis": {
95
+ "embedding": {
96
+ "column": "description",
97
+ "provider": "fastembed",
98
+ "model": "jinaai/jina-embeddings-v2-base-code",
99
+ "dimension": 768,
100
+ "fastembed": {
101
+ "cache_dir": "/tmp/emb-cache",
102
+ "batch_size": 16,
103
+ },
104
+ }
105
+ }
106
+ },
107
+ },
108
+ }
109
+ )
110
+
111
+ table_config = TableConfig.from_config(config, "StrendaBiocatalysis")
112
+ assert isinstance(table_config.embed_model, DummyTextEmbedding)
113
+ assert captured == {
114
+ "model_name": "jinaai/jina-embeddings-v2-base-code",
115
+ "cache_dir": "/tmp/emb-cache",
116
+ "batch_size": 16,
117
+ }
118
+
119
+
120
+ def test_table_config_passes_trust_remote_code_to_huggingface(monkeypatch):
121
+ captured = {}
122
+
123
+ def fake_sentence_transformer(
124
+ model_name,
125
+ device=None,
126
+ batch_size=32,
127
+ normalize_embeddings=True,
128
+ trust_remote_code=False,
129
+ ):
130
+ captured.update(
131
+ {
132
+ "model_name": model_name,
133
+ "device": device,
134
+ "batch_size": batch_size,
135
+ "normalize_embeddings": normalize_embeddings,
136
+ "trust_remote_code": trust_remote_code,
137
+ }
138
+ )
139
+ return DummyTextEmbedding(
140
+ dimension=768,
141
+ model_name=model_name,
142
+ trust_remote_code=trust_remote_code,
143
+ )
144
+
145
+ monkeypatch.setattr(
146
+ "mdmodels.sql.config.SentenceTransformerEmbedding", fake_sentence_transformer
147
+ )
148
+
149
+ config = AppConfig.model_validate(
150
+ {
151
+ "model": {"path": "specifications/model.md"},
152
+ "sql": {
153
+ "type": "pgvector",
154
+ "tables": {
155
+ "StrendaBiocatalysis": {
156
+ "embedding": {
157
+ "column": "description",
158
+ "provider": "huggingface",
159
+ "model": "jinaai/jina-embeddings-v2-base-code",
160
+ "dimension": 768,
161
+ "huggingface": {
162
+ "trust_remote_code": True,
163
+ },
164
+ }
165
+ }
166
+ },
167
+ },
168
+ }
169
+ )
170
+
171
+ table_config = TableConfig.from_config(config, "StrendaBiocatalysis")
172
+ assert isinstance(table_config.embed_model, DummyTextEmbedding)
173
+ assert captured["trust_remote_code"] is True