Registry / data / docarray

docarray

JSON →
library0.41.0pypypi✓ verified 85d ago

DocArray is a Python library that provides a data structure for multimodal data. It is designed to work efficiently with unstructured data like text, images, and audio, often used in machine learning and vector database contexts. The current version is 0.41.0, with frequent patch and minor releases, typically on a monthly to bi-monthly cadence.

pip install docarray
INSTALL
IMPORT
SIG · DOCARRAY
D
docarray
datapythonv0.41.0
Install
17.8s avg
Import
2172ms
Disk
941MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.41.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
2/4 runs
✓ 18.43s
py 3.11
2/4 runs
✓ 17.25s
py 3.12
2/4 runs
✓ 15.95s
py 3.13
2/4 runs
✓ 16.55s
py 3.9
2/4 runs
✓ 20.9s
941MB installed
● package 941MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BaseDoc
from docarray import BaseDoc
from docarray import Document
The `Document` class is part of DocArray's legacy API (pre-0.30.0) and should not be used for new projects. `BaseDoc` is the current base class for custom documents.
DocList
from docarray import DocList
DocVec
from docarray import DocVec
NdArray
from docarray.typing import NdArray

Define custom document schemas using `BaseDoc` and type hints (including `NdArray` for numerical arrays/embeddings), then create instances of single documents or collections using `DocList`.

from docarray import BaseDoc, DocList from docarray.typing import NdArray import numpy as np # 1. Define your custom document schema using BaseDoc class MyDocument(BaseDoc): text: str image_embedding: NdArray[128] # Define an embedding field with fixed dimensions # 2. Create a single document instance doc = MyDocument(text='hello world', image_embedding=np.random.rand(128)) print(f"Created document with text: {doc.text}") # 3. Create a collection of documents using DocList docs = DocList[MyDocument]([ MyDocument(text='document one', image_embedding=np.random.rand(128)), MyDocument(text='document two', image_embedding=np.random.rand(128)), ]) print(f"DocList contains {len(docs)} documents.") # 4. Access individual documents and their fields print(f"First document's text: {docs[0].text}") print(f"Second document's embedding shape: {docs[1].image_embedding.shape}")
Debug
Known issues
breakingThe `docarray.Document` class is a legacy API that has been deprecated since v0.30.0. Using it with newer DocArray features or for new projects will lead to missing functionality or errors. The current API uses `docarray.BaseDoc` for document definitions and `docarray.DocList` for collections.
fix
Migrate your document definitions from `docarray.Document` to `docarray.BaseDoc` and use `docarray.DocList` for document collections. Refer to the official DocArray migration guide.
affects: >=0.30.0
breakingThe `to_json()` method for `DocList` and `DocVec` changed its return type from a dictionary (`dict`) to a JSON-formatted string (`str`) to ensure consistency across serialization methods.
fix
If your application expects a `dict` from `to_json()`, you must now explicitly parse the returned string. Example: `import json; data_dict = json.loads(doclist_instance.to_json())`.
affects: >=0.38.0
gotchaDocArray supports both Pydantic v1 and v2. However, if you upgrade your project's Pydantic dependency to v2, you may need to adapt your `BaseDoc` definitions to align with Pydantic v2's API changes (e.g., for `Field` usage, `default_factory`).
fix
Consult Pydantic's official migration guide for changes between v1 and v2. DocArray itself remains compatible, but your schema definitions might require adjustments.
affects: >=0.39.0
gotchaA bug in `from_dataframe` when used with `numpy>=1.26.1` caused issues due to changes in NumPy's versioning semantics. This was patched in a subsequent release.
fix
Ensure you are using `docarray>=0.39.1` if you rely on the `from_dataframe` method and have `numpy>=1.26.1` installed.
affects: =0.39.0
Errors
Common errors & fixes
ImportError: cannot import name 'Document' from 'docarray'
You are attempting to import the legacy `Document` class which is no longer part of the primary `docarray` namespace for new projects. It has been superseded by `BaseDoc`.
fix
Replace `from docarray import Document` with `from docarray import BaseDoc` when defining your document schemas.
AttributeError: 'BaseDoc' object has no attribute 'tags'
Features like `.tags` or `.chunks` were specific to the legacy `Document` class. `BaseDoc` objects are Pydantic models, so custom fields are defined directly.
fix
If you need a 'tags' field, define it explicitly in your `BaseDoc` schema: `class MyDoc(BaseDoc): tags: List[str]`.
TypeError: Object of type DocList is not JSON serializable
Attempting to directly serialize a `DocList` instance using `json.dumps()` without first converting it to a JSON-compatible format like a string or dictionary.
fix
Use the built-in `to_json()` method of `DocList` to get a JSON string, then process it. Example: `json_string = my_doclist.to_json()`.
pydantic.error_wrappers.ValidationError: 1 validation error for MyDocument
Your `BaseDoc` model validation failed, often due to providing a value of the wrong type or shape for a field, e.g., passing a list when an `NdArray` is expected.
fix
Check the detailed error message for the specific field causing the validation error. Ensure data types and shapes match your `BaseDoc` schema definitions (e.g., `NdArray[128]` expects a NumPy array of shape (128,)).
Upgrade
Version history
0.41.0latest on PyPI · released Mar 21, 2025
Audit
Dependencies
pydanticrequiredCore dependency for defining document schemas. Supports Pydantic v1 and v2.
numpyrequiredCore dependency, especially for NdArray types.
torchoptionalRequired for `TorchArray`, included in the `full` extra.
tensorflowoptionalRequired for `TensorFlowTensor`, included in the `full` extra.
jaxoptionalRequired for `JaxArray`, included in the `full` extra.
Agent activity
45 hits · last 30 days
node
40
OpenAI (training)
1
Resources