NucliaDB Models
raw JSON → 6.13.0.post6240 verified Sat May 09 auth: no python
Data models and validation for NucliaDB, the AI-powered search database. Version 6.13.0.post6240 supports Python 3.10-3.12. Released as part of the nucliadb project, with frequent releases following nucliadb's release cadence.
pip install nucliadb-models Common errors
error ModuleNotFoundError: No module named 'nucliadb.models' ↓
cause Old import pattern with dots instead of underscores.
fix
Install nucliadb-models and import using underscores:
from nucliadb_models import Resource error pydantic_core._pydantic_core.ValidationError: 1 validation error for Resource ↓
cause Passing unknown fields or invalid field types.
fix
Check the model schema and provide only defined fields with correct types.
error ImportError: cannot import name 'Field' from 'nucliadb_models' ↓
cause Field class was moved/removed.
fix
Import specific field types like
TextField from nucliadb_models.text instead. Warnings
breaking In v6.0.0, the package was renamed from nucliadb-models to nucliadb_models. All imports must use underscores. ↓
fix Use `from nucliadb_models import ...` instead of `from nucliadb.models import ...`
deprecated The `Field` class from nucliadb_models.field is deprecated in favor of direct field classes like `TextField`, `FileField`. ↓
fix Replace `from nucliadb_models.field import Field` with specific field imports like `from nucliadb_models.text import TextField`
gotcha Model validation is strict: unknown fields raise a ValidationError by default. This differs from older pydantic v1 behavior. ↓
fix Use `model_extra = 'allow'` in config if you need to allow extra fields.
Imports
- Resource
from nucliadb_models.resource import Resource - TextField
from nucliadb_models.text import TextField - KnowledgeBoxObj
from nucliadb_models.knowledgebox import KnowledgeBoxObj
Quickstart
from nucliadb_models.resource import Resource
from nucliadb_models.text import TextField
resource = Resource(
slug="example",
texts={"en": TextField(body="Hello world")}
)
print(resource.model_dump_json(indent=2))