From d230b194e551795f1d23db0182dec1aa9203e6e9 Mon Sep 17 00:00:00 2001 From: Jiangzhou He Date: Wed, 1 Oct 2025 08:58:05 -0700 Subject: [PATCH 1/3] chore(pydantic): add optional dependency for testing, docs minor cleanup --- docs/docs/core/data_types.mdx | 18 +++++++----------- pyproject.toml | 7 ++++++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/docs/core/data_types.mdx b/docs/docs/core/data_types.mdx index fd523d8bd..242e07d40 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 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..6bef9962b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,12 @@ lancedb = ["lancedb>=0.25.0"] # 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" From 0446338618f4bf6e27e99fb7f7bb8098669707af Mon Sep 17 00:00:00 2001 From: Jiangzhou He Date: Wed, 1 Oct 2025 09:01:00 -0700 Subject: [PATCH 2/3] docs: more comments --- docs/docs/core/data_types.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/core/data_types.mdx b/docs/docs/core/data_types.mdx index 242e07d40..4b285e4fa 100644 --- a/docs/docs/core/data_types.mdx +++ b/docs/docs/core/data_types.mdx @@ -120,7 +120,7 @@ For example: ```python from dataclasses import dataclass from typing import NamedTuple -from pydantic import BaseModel +from pydantic import BaseModel # requires `pydantic` package to be installed import datetime # Using dataclass From 8714a6e4c3ee97d9a55133d88222ad24dc5881c3 Mon Sep 17 00:00:00 2001 From: Jiangzhou He Date: Wed, 1 Oct 2025 09:03:59 -0700 Subject: [PATCH 3/3] chore: add `pydantic` as an optional dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 6bef9962b..bb877cd86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,6 +67,7 @@ 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.