diff --git a/docs/docs/core/data_types.mdx b/docs/docs/core/data_types.mdx index fd523d8bd..4b285e4fa 100644 --- a/docs/docs/core/data_types.mdx +++ b/docs/docs/core/data_types.mdx @@ -113,12 +113,14 @@ These options define a structured type with named fields, but they differ slight - **Dataclass**: A flexible class-based structure, mutable by default, defined using the `@dataclass` decorator. - **NamedTuple**: An immutable tuple-based structure, defined using `typing.NamedTuple`. - **Pydantic model**: A modern data validation and parsing structure, defined by inheriting from `pydantic.BaseModel`. + Make sure you installed the `pydantic` package when using Pydantic model. For example: ```python from dataclasses import dataclass from typing import NamedTuple +from pydantic import BaseModel # requires `pydantic` package to be installed import datetime # Using dataclass @@ -134,17 +136,11 @@ class PersonTuple(NamedTuple): last_name: str dob: datetime.date -# Using Pydantic (optional dependency) -try: - from pydantic import BaseModel - - class PersonModel(BaseModel): - first_name: str - last_name: str - dob: datetime.date -except ImportError: - # Pydantic is optional - pass +# Using Pydantic +class PersonModel(BaseModel): + first_name: str + last_name: str + dob: datetime.date ``` All three examples (`Person`, `PersonTuple`, and `PersonModel`) are valid Struct types in CocoIndex, with identical schemas (three fields: `first_name` (Str), `last_name` (Str), `dob` (Date)). diff --git a/pyproject.toml b/pyproject.toml index 2f8423c39..bb877cd86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,10 +67,16 @@ dev = ["pytest", "pytest-asyncio", "ruff", "mypy", "pre-commit"] embeddings = ["sentence-transformers>=3.3.1"] colpali = ["colpali-engine"] lancedb = ["lancedb>=0.25.0"] +pydantic = ["pydantic>=2.11.9"] # We need to repeat the dependency above to make it available for the `all` feature. # Indirect dependencies such as "cocoindex[embeddings]" will not work for local development. -all = ["sentence-transformers>=3.3.1", "colpali-engine", "lancedb>=0.25.0"] +all = [ + "sentence-transformers>=3.3.1", + "colpali-engine", + "lancedb>=0.25.0", + "pydantic>=2.11.9", +] [tool.mypy] python_version = "3.11"