Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions docs/docs/core/data_types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)).
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down