From d2bfe2401839bce08aac94a2332a6edf134a6391 Mon Sep 17 00:00:00 2001 From: Johannes Messner Date: Fri, 2 Dec 2022 11:12:02 +0100 Subject: [PATCH 1/4] feat: native len for milvus Signed-off-by: Johannes Messner --- docarray/array/storage/milvus/seqlike.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docarray/array/storage/milvus/seqlike.py b/docarray/array/storage/milvus/seqlike.py index 1711c5b8080..d1ce651c0c6 100644 --- a/docarray/array/storage/milvus/seqlike.py +++ b/docarray/array/storage/milvus/seqlike.py @@ -1,6 +1,6 @@ from typing import Iterable, Iterator, Union, TYPE_CHECKING from docarray.array.storage.base.seqlike import BaseSequenceLikeMixin -from docarray.array.storage.milvus.backend import _batch_list +from docarray.array.storage.milvus.backend import _batch_list, _always_true_expr from docarray import Document @@ -56,3 +56,11 @@ def _extend(self, values: Iterable['Document'], **kwargs): payload = self._docs_to_milvus_payload(docs_batch) self._collection.insert(payload, **kwargs) self._offset2ids.extend([doc.id for doc in docs_batch]) + + def __len__(self): + with self.loaded_collection(): + res = self._collection.query( + expr=_always_true_expr('document_id'), + output_fields=['document_id'], + ) + return len(res) From e8422c8a2f8990fcf2689d6506bcb220a457e3a6 Mon Sep 17 00:00:00 2001 From: Johannes Messner Date: Fri, 2 Dec 2022 11:15:32 +0100 Subject: [PATCH 2/4] fix: make implementing len non-optional Signed-off-by: Johannes Messner --- docarray/array/storage/base/seqlike.py | 2 +- docs/advanced/document-store/extend.md | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docarray/array/storage/base/seqlike.py b/docarray/array/storage/base/seqlike.py index 5e46cafe607..ce89b82a3bf 100644 --- a/docarray/array/storage/base/seqlike.py +++ b/docarray/array/storage/base/seqlike.py @@ -50,7 +50,7 @@ def __eq__(self, other): ... def __len__(self): - return len(self._offset2ids) + ... def __iter__(self) -> Iterator['Document']: for _id in self._offset2ids: diff --git a/docs/advanced/document-store/extend.md b/docs/advanced/document-store/extend.md index a65d5ac32bb..591d2ce8832 100644 --- a/docs/advanced/document-store/extend.md +++ b/docs/advanced/document-store/extend.md @@ -145,6 +145,9 @@ class SequenceLikeMixin(BaseSequenceLikeMixin): def __add__(self, other: Union['Document', Iterable['Document']]): ... + def __len__(self): + ... + def insert(self, index: int, value: 'Document'): # Optional. By default, this will add a new item and update offset2id # if you want to customize this, make sure to handle offset2id @@ -158,10 +161,6 @@ class SequenceLikeMixin(BaseSequenceLikeMixin): # Optional. Override this if you have better implementation than appending one by one ... - def __len__(self): - # Optional. By default, this will rely on offset2id to get the length - ... - def __iter__(self) -> Iterator['Document']: # Optional. By default, this will rely on offset2id to iterate ... From 3fbdf197b03027d28205e75f4d52fdcf154eef12 Mon Sep 17 00:00:00 2001 From: Johannes Messner Date: Mon, 6 Feb 2023 16:08:14 +0100 Subject: [PATCH 3/4] docs: add explanation of scipy install Signed-off-by: Johannes Messner --- docs/datatypes/text/index.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/datatypes/text/index.md b/docs/datatypes/text/index.md index e6a510911ea..da4d95d9a15 100644 --- a/docs/datatypes/text/index.md +++ b/docs/datatypes/text/index.md @@ -175,6 +175,16 @@ this is a much longer sentence Let's search for `"she entered the room"` in *Pride and Prejudice*: +````{admonition} SciPy +:class: note + +The example below uses SciPy to speed up computations. To install scipy you can run `pip install scipy`, or install +it together with other optional dependencies using `pip install "docarray[full]"`. + +Alternatively, you can run the example below without SciPy by setting `use_scipy=False` in the `.match()` method. +```` + + ```python from docarray import Document, DocumentArray From 926aef283083c716e2227d5a4a6fa8e3efb60cc0 Mon Sep 17 00:00:00 2001 From: Johannes Messner <44071807+JohannesMessner@users.noreply.github.com> Date: Tue, 7 Feb 2023 09:55:57 +0100 Subject: [PATCH 4/4] docs: update docs/datatypes/text/index.md Co-authored-by: Alex Cureton-Griffiths Signed-off-by: Johannes Messner <44071807+JohannesMessner@users.noreply.github.com> --- docs/datatypes/text/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/datatypes/text/index.md b/docs/datatypes/text/index.md index da4d95d9a15..5200e75e6ca 100644 --- a/docs/datatypes/text/index.md +++ b/docs/datatypes/text/index.md @@ -178,7 +178,7 @@ Let's search for `"she entered the room"` in *Pride and Prejudice*: ````{admonition} SciPy :class: note -The example below uses SciPy to speed up computations. To install scipy you can run `pip install scipy`, or install +The example below uses SciPy to speed up computations. To install SciPy you can run `pip install scipy`, or install it together with other optional dependencies using `pip install "docarray[full]"`. Alternatively, you can run the example below without SciPy by setting `use_scipy=False` in the `.match()` method.