From fde7a163598f44a605e800cda7738a22b14e0239 Mon Sep 17 00:00:00 2001 From: samsja Date: Mon, 25 Sep 2023 15:32:02 +0200 Subject: [PATCH 1/5] feat: add BaseDocWoId Signed-off-by: samsja --- docarray/base_doc/doc.py | 67 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/docarray/base_doc/doc.py b/docarray/base_doc/doc.py index 017afdc9c9..05027e4c0d 100644 --- a/docarray/base_doc/doc.py +++ b/docarray/base_doc/doc.py @@ -61,39 +61,12 @@ ExcludeType = Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] -class BaseDoc(BaseModel, IOMixin, UpdateMixin, BaseNode): +class BaseDocWoId(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 """ - 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: @@ -582,3 +555,37 @@ def _exclude_docarray( ) to_json = BaseModel.model_dump_json if is_pydantic_v2 else json + + +class BaseDoc(BaseDocWoId): + """ + 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(), + ) From f25dabc38e3683054c1177e220fee12e450cc610 Mon Sep 17 00:00:00 2001 From: samsja Date: Mon, 25 Sep 2023 15:38:18 +0200 Subject: [PATCH 2/5] fix: fix tests Signed-off-by: samsja --- docarray/base_doc/doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docarray/base_doc/doc.py b/docarray/base_doc/doc.py index 05027e4c0d..af40c9bba7 100644 --- a/docarray/base_doc/doc.py +++ b/docarray/base_doc/doc.py @@ -518,7 +518,7 @@ def parse_raw( :param allow_pickle: allow pickle protocol :return: a document """ - return super(BaseDoc, cls).parse_raw( + return super(BaseDocWoId, cls).parse_raw( b, content_type=content_type, encoding=encoding, From e444c8d41ce14fb67260a81fb3c716855e3d8ab6 Mon Sep 17 00:00:00 2001 From: samsja Date: Mon, 25 Sep 2023 16:17:18 +0200 Subject: [PATCH 3/5] refactor: raname to BaseDocWithoutId Signed-off-by: samsja --- docarray/base_doc/doc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docarray/base_doc/doc.py b/docarray/base_doc/doc.py index af40c9bba7..e8d8cfa494 100644 --- a/docarray/base_doc/doc.py +++ b/docarray/base_doc/doc.py @@ -61,7 +61,7 @@ ExcludeType = Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] -class BaseDocWoId(BaseModel, IOMixin, UpdateMixin, BaseNode): +class BaseDocWithoutId(BaseModel, IOMixin, UpdateMixin, BaseNode): """ 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 @@ -518,7 +518,7 @@ def parse_raw( :param allow_pickle: allow pickle protocol :return: a document """ - return super(BaseDocWoId, cls).parse_raw( + return super(BaseDocWithoutId, cls).parse_raw( b, content_type=content_type, encoding=encoding, @@ -557,7 +557,7 @@ def _exclude_docarray( to_json = BaseModel.model_dump_json if is_pydantic_v2 else json -class BaseDoc(BaseDocWoId): +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. From 218290def312d2e1292130cad7f9a4aeca35cc71 Mon Sep 17 00:00:00 2001 From: samsja Date: Tue, 26 Sep 2023 09:32:54 +0200 Subject: [PATCH 4/5] fix: add docstring Signed-off-by: samsja --- docarray/base_doc/doc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docarray/base_doc/doc.py b/docarray/base_doc/doc.py index e8d8cfa494..c53cd7431e 100644 --- a/docarray/base_doc/doc.py +++ b/docarray/base_doc/doc.py @@ -64,7 +64,9 @@ class BaseDocWithoutId(BaseModel, IOMixin, UpdateMixin, BaseNode): """ 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 + It is basically a BaseDoc without the ID field. + !!! warning + This class cannot be used with DocumentIndex. Only BaseDoc is compatible """ if is_pydantic_v2: From fe4d7e0ec7b844dec3d4d63314d93103865a90ab Mon Sep 17 00:00:00 2001 From: samsja Date: Tue, 26 Sep 2023 10:21:31 +0200 Subject: [PATCH 5/5] chore: update mkdocstring Signed-off-by: samsja --- poetry.lock | 35 +++++++++++++++++------------------ pyproject.toml | 3 ++- 2 files changed, 19 insertions(+), 19 deletions(-) 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