diff --git a/docarray/base_doc/doc.py b/docarray/base_doc/doc.py index 017afdc9c9..c53cd7431e 100644 --- a/docarray/base_doc/doc.py +++ b/docarray/base_doc/doc.py @@ -61,39 +61,14 @@ ExcludeType = Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] -class BaseDoc(BaseModel, IOMixin, UpdateMixin, BaseNode): +class BaseDocWithoutId(BaseModel, IOMixin, UpdateMixin, BaseNode): """ - BaseDoc is the base class for all Documents. This class should be subclassed - to create new Document types with a specific schema. - - The schema of a Document is defined by the fields of the class. - - Example: - ```python - from docarray import BaseDoc - from docarray.typing import NdArray, ImageUrl - import numpy as np - - - class MyDoc(BaseDoc): - embedding: NdArray[512] - image: ImageUrl - - - doc = MyDoc(embedding=np.zeros(512), image='https://example.com/image.jpg') - ``` - - - BaseDoc is a subclass of [pydantic.BaseModel]( - https://docs.pydantic.dev/usage/models/) and can be used in a similar way. + BaseDocWoId is the class behind BaseDoc, it should not be used directly unless you know what you are doing. + It is basically a BaseDoc without the ID field. + !!! warning + This class cannot be used with DocumentIndex. Only BaseDoc is compatible """ - id: Optional[ID] = Field( - description='The ID of the BaseDoc. This is useful for indexing in vector stores. If not set by user, it will automatically be assigned a random value', - default_factory=lambda: ID(os.urandom(16).hex()), - example=os.urandom(16).hex(), - ) - if is_pydantic_v2: class Config: @@ -545,7 +520,7 @@ def parse_raw( :param allow_pickle: allow pickle protocol :return: a document """ - return super(BaseDoc, cls).parse_raw( + return super(BaseDocWithoutId, cls).parse_raw( b, content_type=content_type, encoding=encoding, @@ -582,3 +557,37 @@ def _exclude_docarray( ) to_json = BaseModel.model_dump_json if is_pydantic_v2 else json + + +class BaseDoc(BaseDocWithoutId): + """ + BaseDoc is the base class for all Documents. This class should be subclassed + to create new Document types with a specific schema. + + The schema of a Document is defined by the fields of the class. + + Example: + ```python + from docarray import BaseDoc + from docarray.typing import NdArray, ImageUrl + import numpy as np + + + class MyDoc(BaseDoc): + embedding: NdArray[512] + image: ImageUrl + + + doc = MyDoc(embedding=np.zeros(512), image='https://example.com/image.jpg') + ``` + + + BaseDoc is a subclass of [pydantic.BaseModel]( + https://docs.pydantic.dev/usage/models/) and can be used in a similar way. + """ + + id: Optional[ID] = Field( + description='The ID of the BaseDoc. This is useful for indexing in vector stores. If not set by user, it will automatically be assigned a random value', + default_factory=lambda: ID(os.urandom(16).hex()), + example=os.urandom(16).hex(), + ) diff --git a/poetry.lock b/poetry.lock index 5016150349..ebb2ea3c6a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1089,21 +1089,18 @@ dev = ["flake8", "markdown", "twine", "wheel"] [[package]] name = "griffe" -version = "0.25.5" +version = "0.36.2" description = "Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "griffe-0.25.5-py3-none-any.whl", hash = "sha256:1fb9edff48e66d4873014a2ebf21aca5f271d0006a4c937826e3cf592ffb3706"}, - {file = "griffe-0.25.5.tar.gz", hash = "sha256:11ea3403ef0560a1cbcf7f302eb5d21cf4c1d8ed3f8a16a75aa9f6f458caf3f1"}, + {file = "griffe-0.36.2-py3-none-any.whl", hash = "sha256:ba71895a3f5f606b18dcd950e8a1f8e7332a37f90f24caeb002546593f2e0eee"}, + {file = "griffe-0.36.2.tar.gz", hash = "sha256:333ade7932bb9096781d83092602625dfbfe220e87a039d2801259a1bd41d1c2"}, ] [package.dependencies] colorama = ">=0.4" -[package.extras] -async = ["aiofiles (>=0.7,<1.0)"] - [[package]] name = "grpcio" version = "1.53.0" @@ -2211,16 +2208,17 @@ mkdocs = ">=1.1.0,<2" [[package]] name = "mkdocstrings" -version = "0.20.0" +version = "0.23.0" description = "Automatic documentation from sources, for MkDocs." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "mkdocstrings-0.20.0-py3-none-any.whl", hash = "sha256:f17fc2c4f760ec302b069075ef9e31045aa6372ca91d2f35ded3adba8e25a472"}, - {file = "mkdocstrings-0.20.0.tar.gz", hash = "sha256:c757f4f646d4f939491d6bc9256bfe33e36c5f8026392f49eaa351d241c838e5"}, + {file = "mkdocstrings-0.23.0-py3-none-any.whl", hash = "sha256:051fa4014dfcd9ed90254ae91de2dbb4f24e166347dae7be9a997fe16316c65e"}, + {file = "mkdocstrings-0.23.0.tar.gz", hash = "sha256:d9c6a37ffbe7c14a7a54ef1258c70b8d394e6a33a1c80832bce40b9567138d1c"}, ] [package.dependencies] +importlib-metadata = {version = ">=4.6", markers = "python_version < \"3.10\""} Jinja2 = ">=2.11.1" Markdown = ">=3.3" MarkupSafe = ">=1.1" @@ -2228,6 +2226,7 @@ mkdocs = ">=1.2" mkdocs-autorefs = ">=0.3.1" mkdocstrings-python = {version = ">=0.5.2", optional = true, markers = "extra == \"python\""} pymdown-extensions = ">=6.3" +typing-extensions = {version = ">=4.1", markers = "python_version < \"3.10\""} [package.extras] crystal = ["mkdocstrings-crystal (>=0.3.4)"] @@ -2236,18 +2235,18 @@ python-legacy = ["mkdocstrings-python-legacy (>=0.2.1)"] [[package]] name = "mkdocstrings-python" -version = "0.8.3" +version = "1.7.0" description = "A Python handler for mkdocstrings." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "mkdocstrings-python-0.8.3.tar.gz", hash = "sha256:9ae473f6dc599339b09eee17e4d2b05d6ac0ec29860f3fc9b7512d940fc61adf"}, - {file = "mkdocstrings_python-0.8.3-py3-none-any.whl", hash = "sha256:4e6e1cd6f37a785de0946ced6eb846eb2f5d891ac1cc2c7b832943d3529087a7"}, + {file = "mkdocstrings_python-1.7.0-py3-none-any.whl", hash = "sha256:85c5f009a5a0ebb6076b7818c82a2bb0eebd0b54662628fa8b25ee14a6207951"}, + {file = "mkdocstrings_python-1.7.0.tar.gz", hash = "sha256:5dac2712bd38a3ff0812b8650a68b232601d1474091b380a8b5bc102c8c0d80a"}, ] [package.dependencies] -griffe = ">=0.24" -mkdocstrings = ">=0.19" +griffe = ">=0.35" +mkdocstrings = ">=0.20" [[package]] name = "mktestdocs" @@ -5002,4 +5001,4 @@ web = ["fastapi"] [metadata] lock-version = "2.0" python-versions = ">=3.8,<4.0" -content-hash = "dd5fa026dfdc6512c2f898a4b1f22737bb351f436ba035e12b7bd953cb56444f" +content-hash = "76f26e1728fcb194a46799bccdec97ffcb5778bbb1a73eabb7aa9ee18fbced6e" diff --git a/pyproject.toml b/pyproject.toml index 07bf7fd949..6d1103534b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,7 +105,8 @@ pytest-asyncio = ">=0.20.2" [tool.poetry.group.docs.dependencies] -mkdocstrings = {extras = ["python"], version = ">=0.20.0"} +mkdocstrings = {extras = ["python"], version = ">=0.23.0"} +mkdocstrings-python= ">=1.7.0" mkdocs-material= ">=9.1.2" mkdocs-awesome-pages-plugin = ">=2.8.0" mktestdocs= ">=0.2.0" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy