surreal-orm-lite 0.36.2__tar.gz → 0.36.3__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 (50) hide show
  1. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/CHANGELOG.md +43 -0
  2. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/PKG-INFO +9 -1
  3. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/README.md +8 -0
  4. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/pyproject.toml +1 -1
  5. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/__init__.py +1 -1
  6. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/model_base.py +12 -10
  7. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/search.py +5 -5
  8. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/vector.py +85 -16
  9. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/.gitignore +0 -0
  10. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/LICENSE +0 -0
  11. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/Makefile +0 -0
  12. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/_sdk.py +0 -0
  13. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/aggregations.py +0 -0
  14. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/auth.py +0 -0
  15. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/cache.py +0 -0
  16. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/changefeed.py +0 -0
  17. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/concurrency.py +0 -0
  18. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/connection_config.py +0 -0
  19. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/connection_manager.py +0 -0
  20. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/constants.py +0 -0
  21. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/decoding.py +0 -0
  22. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/define_parser.py +0 -0
  23. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/edge.py +0 -0
  24. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/embedded.py +0 -0
  25. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/encoding.py +0 -0
  26. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/enum.py +0 -0
  27. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/exceptions.py +0 -0
  28. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/functions.py +0 -0
  29. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/geo.py +0 -0
  30. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/introspection.py +0 -0
  31. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/live.py +0 -0
  32. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/model_auth.py +0 -0
  33. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/model_ddl.py +0 -0
  34. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/model_generator.py +0 -0
  35. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/py.typed +0 -0
  36. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/q.py +0 -0
  37. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/query_set.py +0 -0
  38. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/routing.py +0 -0
  39. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/schema.py +0 -0
  40. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/schema_state.py +0 -0
  41. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/signals.py +0 -0
  42. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/subquery.py +0 -0
  43. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/surql_literal.py +0 -0
  44. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/testing/__init__.py +0 -0
  45. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/testing/database.py +0 -0
  46. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/testing/fixtures.py +0 -0
  47. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/time_travel.py +0 -0
  48. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/transaction.py +0 -0
  49. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/types.py +0 -0
  50. {surreal_orm_lite-0.36.2 → surreal_orm_lite-0.36.3}/src/surreal_orm_lite/utils.py +0 -0
@@ -5,6 +5,49 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.36.3] - 2026-10-24
9
+
10
+ Follow-up to the review of v0.36.0 (#316): a vector field declared with `| None` keeps its
11
+ `Vector` marker, so the checks v0.36.0 added for vector fields apply to it too. No new public API.
12
+
13
+ ### Fixed
14
+
15
+ - **A vector field written `VectorField[d] | None`, `Optional[VectorField[d]]` or
16
+ `Annotated[list[float], Vector(d)] | None` is read as a vector field** (#318). In these
17
+ spellings the marker sits inside a union member, not in the field's metadata, so since v0.36.0
18
+ `get_vector_info()` returned `None` and `is_vector_field()` `False` for them. The `class`
19
+ statement then skipped the vector-index check: an `Index(..., hnsw=True)` of another dimension
20
+ or storage type than the field was accepted, while `define_table()` still wrote
21
+ `option<array<float, d>>`, so the column and the index disagreed without an error; and
22
+ `similar_to()` took the expected length of the query vector from the index, not the field.
23
+ `get_vector_info()` and `is_vector_field()` now read the field's annotation when its metadata
24
+ holds no marker, as `define_table()` does: these spellings give the same column, the same
25
+ index checks at the `class` statement, the same dimension check in `similar_to()` and the same
26
+ `(dimension, storage type)` as `VectorField[d]`. Vectors held in a container
27
+ (`list[VectorField[d]]`) are still not a vector field.
28
+
29
+ ### Changed
30
+
31
+ - **A field with no single vector dimension is refused at the `class` statement** (#318): a
32
+ `Vector` marker next to a type other than `None` in a union (`VectorField[3] | str`), or two
33
+ different `Vector` markers on one field (`Annotated[VectorField[3], Vector(4)]`). The
34
+ `ValueError` names the model and the field and says to write `VectorField[d]` alone (it is
35
+ already optional) or `Annotated[list[float] | None, Vector(d)]`; the check runs on every model,
36
+ whether or not it declares indexes. Until v0.36.2 such a model was accepted (the first of two
37
+ markers decided the checks, a union with another type was not a vector field).
38
+ `get_vector_info()` and `is_vector_field()` raise the same `ValueError` for such a field or
39
+ annotation. Every spelling that v0.36.2 read as a vector field gives the same result.
40
+
41
+ ### Notes
42
+
43
+ - **Docs**: README section 37 (Vector search) says `VectorField[d]` is already optional and
44
+ needs no `| None`: written with it, the field needs `= None`, since Pydantic ignores a default
45
+ inside a union member (with an `UnsupportedFieldAttributeWarning`) and the field is otherwise
46
+ required. It also says how the union spellings are read.
47
+ - The fix is in the ORM's model checks: the behaviour is the same on SurrealDB 2.x and 3.x and on
48
+ the embedded engine. Server pins unchanged: tested against SurrealDB 3.3.4 and 2.7.0, plus
49
+ 3.1.5 for backward compatibility.
50
+
8
51
  ## [0.36.2] - 2026-10-23
9
52
 
10
53
  Follow-ups to the review of v0.35.3 (#312): an index that `remove_index(tx=…)` removed earlier in
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: surreal-orm-lite
3
- Version: 0.36.2
3
+ Version: 0.36.3
4
4
  Summary: Lightweight Django-style ORM for SurrealDB using the official Python SDK. Async support with Pydantic validation.
5
5
  Project-URL: Homepage, https://github.com/EulogySnowfall/SurrealDB-ORM-lite
6
6
  Project-URL: Documentation, https://github.com/EulogySnowfall/SurrealDB-ORM-lite
@@ -6299,6 +6299,14 @@ print(get_vector_info(Document.model_fields["embedding"]), is_vector_field(Passa
6299
6299
  # (3, 'F32') False
6300
6300
  ```
6301
6301
 
6302
+ `VectorField[d]` is already optional, so it needs no `| None`. Written `VectorField[d] | None` or
6303
+ `Optional[VectorField[d]]`, its `None` default sits inside a union member, where Pydantic ignores it with an
6304
+ `UnsupportedFieldAttributeWarning`: write `= None`, or the field is required. The ORM reads these spellings, and
6305
+ `Annotated[list[float], Vector(d)] | None`, like the plain ones: the same column, the same checks of the vector index
6306
+ when the class is defined, the same dimension for `similar_to()`, the same answer from `get_vector_info()`. A union
6307
+ that holds a vector next to a type other than `None`, or two different `Vector` markers, has no single dimension: the
6308
+ class statement refuses it, naming the field.
6309
+
6302
6310
  #### Find the nearest
6303
6311
 
6304
6312
  `similar_to(field, vector, limit=10, *, ef=None, dist=None)` keeps the `limit` records whose `field` vector is nearest
@@ -6248,6 +6248,14 @@ print(get_vector_info(Document.model_fields["embedding"]), is_vector_field(Passa
6248
6248
  # (3, 'F32') False
6249
6249
  ```
6250
6250
 
6251
+ `VectorField[d]` is already optional, so it needs no `| None`. Written `VectorField[d] | None` or
6252
+ `Optional[VectorField[d]]`, its `None` default sits inside a union member, where Pydantic ignores it with an
6253
+ `UnsupportedFieldAttributeWarning`: write `= None`, or the field is required. The ORM reads these spellings, and
6254
+ `Annotated[list[float], Vector(d)] | None`, like the plain ones: the same column, the same checks of the vector index
6255
+ when the class is defined, the same dimension for `similar_to()`, the same answer from `get_vector_info()`. A union
6256
+ that holds a vector next to a type other than `None`, or two different `Vector` markers, has no single dimension: the
6257
+ class statement refuses it, naming the field.
6258
+
6251
6259
  #### Find the nearest
6252
6260
 
6253
6261
  `similar_to(field, vector, limit=10, *, ef=None, dist=None)` keeps the `limit` records whose `field` vector is nearest
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "surreal-orm-lite"
3
- version = "0.36.2"
3
+ version = "0.36.3"
4
4
  description = "Lightweight Django-style ORM for SurrealDB using the official Python SDK. Async support with Pydantic validation."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,4 +1,4 @@
1
- __version__ = "0.36.2"
1
+ __version__ = "0.36.3"
2
2
 
3
3
  from ._sdk import BoundExcluded, BoundIncluded
4
4
  from .aggregations import Aggregation, Avg, Count, Max, Min, Sum
@@ -114,7 +114,7 @@ from .utils import (
114
114
  validate_thing,
115
115
  warn_on_multiple_statements,
116
116
  )
117
- from .vector import get_vector_info
117
+ from .vector import declared_vectors
118
118
 
119
119
  if TYPE_CHECKING:
120
120
  from .edge import BaseSurrealEdge
@@ -877,12 +877,16 @@ class BaseSurrealModel(BaseModel):
877
877
  names — an inherited value is checked again, the messages naming the subclass. So is the
878
878
  ``view_query`` key (v0.32.0): ``None``, or one ``SELECT`` (``schema.check_view_query()``)
879
879
  on a model that is not an edge, does not mix in ``AuthenticatedUserMixin`` and declares no
880
- computed field (``schema.check_view_config()``) — inherited values included. So is, right
881
- after it, the ``indexes`` key (v0.35.0, ``search.check_indexes_config()``): ``None``, or a
880
+ computed field (``schema.check_view_config()``) — inherited values included. So are, right
881
+ after it and on every model, the ``Vector`` markers of the fields (``vector.declared_vectors()``):
882
+ a field holding two different markers, or a marker next to a type other than ``None`` in a
883
+ union, is refused, naming it — inherited fields included, the message naming the subclass. So
884
+ is then the ``indexes`` key (v0.35.0, ``search.check_indexes_config()``): ``None``, or a
882
885
  ``list`` or ``tuple`` of ``Index`` with distinct names, none on a view, one full-text index
883
886
  per column and one ``Analyzer`` definition per analyzer name, one vector index per column
884
- and, on a vector field, of its dimension and storage type (v0.36.0) — inherited values
885
- included, the messages naming the subclass. So are the ``table_type``, ``relation_in``,
887
+ and, on a vector field of any spelling — a union with ``None`` included —, of its dimension
888
+ and storage type (v0.36.0) — inherited values included, the messages naming the subclass.
889
+ So are the ``table_type``, ``relation_in``,
886
890
  ``relation_out`` and ``enforced`` keys (v0.33.0), when any of them is not ``None``: a
887
891
  ``TableType`` (``RELATION`` on an edge only), and the relation keys on an edge model only
888
892
  (``schema.check_relation_config()``). So are, on every model and after the relation keys,
@@ -915,13 +919,11 @@ class BaseSurrealModel(BaseModel):
915
919
  user=issubclass(cls, AuthenticatedUserMixin),
916
920
  computed=tuple(cls.__surreal_computed__),
917
921
  )
922
+ # Every model, with or without indexes: a field whose Vector markers are ambiguous is refused here.
923
+ declared = declared_vectors(cls.__name__, cls.model_fields)
918
924
  indexes = cls.model_config.get("indexes")
919
925
  if indexes is not None:
920
- vectors = {
921
- cls.to_db_field(name): info
922
- for name, field in cls.model_fields.items()
923
- if (info := get_vector_info(field)) is not None
924
- }
926
+ vectors = {cls.to_db_field(name): info for name, info in declared.items()}
925
927
  check_indexes_config(cls, indexes, view=cls._is_view(), column=cls.to_db_field, vectors=vectors)
926
928
  relation = {key: cls.model_config.get(key) for key in ("table_type", "relation_in", "relation_out", "enforced")}
927
929
  if any(value is not None for value in relation.values()):
@@ -833,11 +833,11 @@ def check_indexes_config(
833
833
  by *column* — the model's ``to_db_field`` — so an aliased field counts under its column (SurrealDB would use either
834
834
  for ``search()``, with different scores); two different ``Analyzer`` objects share a name (an analyzer belongs to
835
835
  the database: one definition per name); two vector indexes cover one column, counted the same way (SurrealDB would
836
- use either for ``similar_to()``); a vector index on a vector field — *vectors* maps the column of each, either
837
- spelling, to its ``(dimension, storage type)`` — whose dimension or storage type differs from the field's, the
838
- index's effective type compared (``F32`` when it declares none, ``Index._hnsw_options()``). A vector index on a
839
- column that is not a vector field is not checked against it. Each ``Index`` was checked when it was built. The
840
- messages name *model*.
836
+ use either for ``similar_to()``); a vector index on a vector field — *vectors* maps the column of each, any
837
+ spelling (a union with ``None`` included), to its ``(dimension, storage type)`` — whose dimension or storage type
838
+ differs from the field's, the index's effective type compared (``F32`` when it declares none,
839
+ ``Index._hnsw_options()``). A vector index on a column that is not a vector field is not checked against it. Each
840
+ ``Index`` was checked when it was built. The messages name *model*.
841
841
 
842
842
  :raises TypeError: *value* is not a ``list`` or a ``tuple``, or holds something other than an ``Index``.
843
843
  :raises ValueError: two indexes share a name; a view declares an index; two full-text indexes cover one column;
@@ -8,7 +8,11 @@ storage type is given (``F64``, ``F32``, ``I64``, ``I32`` or ``I16``, in any cas
8
8
  Pydantic reads the ``Vector`` marker exactly as ``VectorField[1536]``'s. Both spellings are one field: the same
9
9
  validation, the same column type (``option<array<float, 1536>>``), the same schema. ``get_vector_info()`` and
10
10
  ``is_vector_field()`` — the full ORM's helpers, under their names — read the marker of either spelling from a model
11
- field or an annotation.
11
+ field or an annotation, and of their unions with ``None`` (``VectorField[1536] | None``,
12
+ ``Annotated[list[float], Vector(1536)] | None``), as ``define_table()`` reads them; never from inside a container
13
+ (``list[VectorField[3]]``). A field or an annotation holding two different markers, or a marker next to a type other
14
+ than ``None``, has no single dimension: the helpers refuse it, and a model's ``class`` statement refuses such a field
15
+ (``declared_vectors()``).
12
16
 
13
17
  A value is ``None`` or a ``list``/``tuple`` of exactly ``d`` real numbers — ``int``, ``float``, any ``numbers.Real``,
14
18
  a ``decimal.Decimal`` (SurrealDB's decimals read back as ``Decimal``) —, never a ``bool`` nor a ``str``, each finite
@@ -50,7 +54,8 @@ from collections.abc import Mapping, Sequence
50
54
  from dataclasses import dataclass
51
55
  from decimal import Decimal
52
56
  from numbers import Real
53
- from typing import Annotated, Any, NoReturn, Self, TypedDict, get_args, get_origin
57
+ from types import NoneType, UnionType
58
+ from typing import Annotated, Any, NoReturn, Self, TypedDict, Union, get_args, get_origin
54
59
 
55
60
  from pydantic import Field, GetCoreSchemaHandler, GetJsonSchemaHandler
56
61
  from pydantic.fields import FieldInfo
@@ -292,38 +297,102 @@ class VectorField:
292
297
  return _ANNOTATED[list[float] | None, Vector(*checked), Field(default=None)]
293
298
 
294
299
 
295
- def _marker(annotation_or_field: Any) -> Vector | None:
296
- """The first ``Vector`` of a ``FieldInfo``'s metadata or of an ``Annotated`` annotation's, else ``None``."""
300
+ def _held(annotation: Any, metadata: Sequence[Any] = ()) -> tuple[tuple[Vector, ...], bool]:
301
+ """The distinct ``Vector`` markers that declare a field of *annotation* (with the field's own *metadata*), in order,
302
+ and whether the field also takes a type other than ``None`` next to them.
303
+
304
+ The ``Annotated`` layers are unwrapped and their metadata added to *metadata*: when it holds a ``Vector``, those
305
+ markers decide, whatever the type under them (a ``Vector`` validates the value itself). Otherwise ``None`` gives
306
+ neither; a union gives the markers and other types of its members, each read the same way; any other type is
307
+ another type — a container holding vectors (``list[VectorField[3]]``) included, whose arguments are never read.
308
+ This is the reading ``model_ddl`` gives the column its kind by, so the column and the checks agree.
309
+ """
310
+ while get_origin(annotation) is Annotated:
311
+ metadata = (*metadata, *annotation.__metadata__)
312
+ annotation = annotation.__origin__
313
+ markers = tuple(dict.fromkeys(item for item in metadata if isinstance(item, Vector)))
314
+ if markers:
315
+ return markers, False
316
+ if annotation is None or annotation is NoneType:
317
+ return (), False
318
+ origin = get_origin(annotation)
319
+ if origin is not Union and origin is not UnionType:
320
+ return (), True
321
+ members = [_held(member) for member in get_args(annotation)]
322
+ markers = tuple(dict.fromkeys(marker for held, _ in members for marker in held))
323
+ return markers, any(other for _, other in members)
324
+
325
+
326
+ def ambiguous_marker_refused(subject: str, markers: Sequence[Vector], other: bool) -> str:
327
+ """The refusal of *subject* — a field, or an annotation —, which holds several different *markers*, or a marker and
328
+ a type other than ``None`` (*other*): a vector field of no single dimension and storage type."""
329
+ held = repr(markers[-1]) if len(markers) == 1 else f"{', '.join(map(repr, markers[:-1]))} and {markers[-1]!r}"
330
+ if other:
331
+ held += " next to a type other than None"
332
+ return (
333
+ f"{subject} holds {held}; a vector field holds one Vector marker, and None at most. Write VectorField[d] alone "
334
+ "(it is already optional) or Annotated[list[float] | None, Vector(d)]."
335
+ )
336
+
337
+
338
+ def _marker(annotation_or_field: Any, *, subject: str | None = None) -> Vector | None:
339
+ """The ``Vector`` marker of a ``FieldInfo`` or of an annotation (``_held()``), ``None`` when it holds none.
340
+
341
+ Several different markers, or a marker next to a type other than ``None`` in a union, raise ``ValueError`` naming
342
+ *subject* (by default "The field" or "The annotation").
343
+ """
297
344
  if isinstance(annotation_or_field, FieldInfo):
298
- metadata: Sequence[Any] = annotation_or_field.metadata
299
- elif get_origin(annotation_or_field) is Annotated:
300
- metadata = annotation_or_field.__metadata__
345
+ markers, other = _held(annotation_or_field.annotation, annotation_or_field.metadata)
346
+ default = "The field"
301
347
  else:
348
+ markers, other = _held(annotation_or_field)
349
+ default = "The annotation"
350
+ if not markers:
302
351
  return None
303
- for item in metadata:
304
- if isinstance(item, Vector):
305
- return item
306
- if isinstance(annotation_or_field, FieldInfo):
307
- return None
308
- return _marker(get_args(annotation_or_field)[0])
352
+ if len(markers) > 1 or other:
353
+ raise ValueError(ambiguous_marker_refused(subject or default, markers, other))
354
+ return markers[0]
309
355
 
310
356
 
311
357
  def get_vector_info(annotation_or_field: Any) -> tuple[int, str] | None:
312
358
  """The ``(dimension, storage type)`` of a vector field, or ``None`` when it is not one (the full ORM's helper).
313
359
 
314
360
  Takes a model field (``Model.model_fields["embedding"]``, a Pydantic ``FieldInfo``) or an annotation
315
- (``VectorField[3]``, ``Annotated[list[float] | None, Vector(3)]``): both spellings give ``(3, "F32")``. Anything
316
- without a ``Vector`` marker — ``list[float]``, another field — gives ``None``.
361
+ (``VectorField[3]``, ``Annotated[list[float] | None, Vector(3)]``): both spellings give ``(3, "F32")``, and so do
362
+ their unions with ``None`` (``VectorField[3] | None``, ``Optional[VectorField[3]]``,
363
+ ``Annotated[list[float], Vector(3)] | None``), read as ``define_table()`` reads them. Anything without a ``Vector``
364
+ marker — ``list[float]``, another field, vectors held in a container such as ``list[VectorField[3]]`` — gives
365
+ ``None``.
366
+
367
+ :raises ValueError: the field or annotation holds two different ``Vector`` markers, or a marker next to a type
368
+ other than ``None`` in a union (``VectorField[3] | str``): its dimension and storage type are not one. A
369
+ model's ``class`` statement refuses such a field already, naming it.
317
370
  """
318
371
  marker = _marker(annotation_or_field)
319
372
  return None if marker is None else (marker.dimension, marker.vector_type)
320
373
 
321
374
 
322
375
  def is_vector_field(annotation_or_field: Any) -> bool:
323
- """Whether a model field or an annotation is a vector field, either spelling (the full ORM's helper)."""
376
+ """Whether a model field or an annotation is a vector field, any spelling — a union with ``None`` included — (the
377
+ full ORM's helper). Refuses what ``get_vector_info()`` refuses, with its ``ValueError``."""
324
378
  return _marker(annotation_or_field) is not None
325
379
 
326
380
 
381
+ def declared_vectors(owner: str, fields: Mapping[str, FieldInfo]) -> dict[str, tuple[int, str]]:
382
+ """The ``(dimension, storage type)`` of each vector field among a model's *fields*, by field name, as
383
+ ``get_vector_info()`` reads them: what the model's ``class`` statement checks (issue #318).
384
+
385
+ A field whose ``Vector`` markers are ambiguous raises ``ValueError`` naming the model *owner* and the field, so the
386
+ ``class`` statement refuses it whether or not the model declares indexes.
387
+ """
388
+ declared: dict[str, tuple[int, str]] = {}
389
+ for name, field in fields.items():
390
+ marker = _marker(field, subject=f"{owner}: field {name!r}")
391
+ if marker is not None:
392
+ declared[name] = (marker.dimension, marker.vector_type)
393
+ return declared
394
+
395
+
327
396
  # --- the checks -----------------------------------------------------------------------------------------------------
328
397
 
329
398