Skip to content

Commit d230b19

Browse files
committed
chore(pydantic): add optional dependency for testing, docs minor cleanup
1 parent d309076 commit d230b19

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

docs/docs/core/data_types.mdx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ These options define a structured type with named fields, but they differ slight
113113
- **Dataclass**: A flexible class-based structure, mutable by default, defined using the `@dataclass` decorator.
114114
- **NamedTuple**: An immutable tuple-based structure, defined using `typing.NamedTuple`.
115115
- **Pydantic model**: A modern data validation and parsing structure, defined by inheriting from `pydantic.BaseModel`.
116+
Make sure you installed the `pydantic` package when using Pydantic model.
116117

117118
For example:
118119

119120
```python
120121
from dataclasses import dataclass
121122
from typing import NamedTuple
123+
from pydantic import BaseModel
122124
import datetime
123125

124126
# Using dataclass
@@ -134,17 +136,11 @@ class PersonTuple(NamedTuple):
134136
last_name: str
135137
dob: datetime.date
136138

137-
# Using Pydantic (optional dependency)
138-
try:
139-
from pydantic import BaseModel
140-
141-
class PersonModel(BaseModel):
142-
first_name: str
143-
last_name: str
144-
dob: datetime.date
145-
except ImportError:
146-
# Pydantic is optional
147-
pass
139+
# Using Pydantic
140+
class PersonModel(BaseModel):
141+
first_name: str
142+
last_name: str
143+
dob: datetime.date
148144
```
149145

150146
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)).

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ lancedb = ["lancedb>=0.25.0"]
7070

7171
# We need to repeat the dependency above to make it available for the `all` feature.
7272
# Indirect dependencies such as "cocoindex[embeddings]" will not work for local development.
73-
all = ["sentence-transformers>=3.3.1", "colpali-engine", "lancedb>=0.25.0"]
73+
all = [
74+
"sentence-transformers>=3.3.1",
75+
"colpali-engine",
76+
"lancedb>=0.25.0",
77+
"pydantic>=2.11.9",
78+
]
7479

7580
[tool.mypy]
7681
python_version = "3.11"

0 commit comments

Comments
 (0)