| 1 | # Pydantic |
| 2 | |
| 3 | [Pydantic](https://docs.pydantic.dev/latest/) is a data validation library in Python. |
| 4 | LanceDB integrates with Pydantic for schema inference, data ingestion, and query result casting. |
| 5 | |
| 6 | ## Schema |
| 7 | |
| 8 | LanceDB supports to create Apache Arrow Schema from a |
| 9 | [Pydantic BaseModel](https://docs.pydantic.dev/latest/api/main/#pydantic.main.BaseModel) |
| 10 | via [pydantic_to_schema()](python.md#lancedb.pydantic.pydantic_to_schema) method. |
| 11 | |
| 12 | ::: lancedb.pydantic.pydantic_to_schema |
| 13 | |
| 14 | ## Vector Field |
| 15 | |
| 16 | LanceDB provides a [`Vector(dim)`](python.md#lancedb.pydantic.Vector) method to define a |
| 17 | vector Field in a Pydantic Model. |
| 18 | |
| 19 | ::: lancedb.pydantic.Vector |
| 20 | |
| 21 | ## Type Conversion |
| 22 | |
| 23 | LanceDB automatically convert Pydantic fields to |
| 24 | [Apache Arrow DataType](https://arrow.apache.org/docs/python/generated/pyarrow.DataType.html#pyarrow.DataType). |
| 25 | |
| 26 | Current supported type conversions: |
| 27 | |
| 28 | | Pydantic Field Type | PyArrow Data Type | |
| 29 | | ------------------- | ----------------- | |
| 30 | | `int` | `pyarrow.int64` | |
| 31 | | `float` | `pyarrow.float64` | |
| 32 | | `bool` | `pyarrow.bool` | |
| 33 | | `str` | `pyarrow.utf8()` | |
| 34 | | `list` | `pyarrow.List` | |
| 35 | | `BaseModel` | `pyarrow.Struct` | |
| 36 | | `Vector(n)` | `pyarrow.FixedSizeList(float32, n)` | |