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 36bd7b370d40095e716847a3dba5d9ddc61d1952 Mon Sep 17 00:00:00 2001 From: Johannes Messner Date: Fri, 27 Jan 2023 13:30:07 +0100 Subject: [PATCH 3/4] docs: add calendar link to readme Signed-off-by: Johannes Messner --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 52fd698736c..2fae63ffa9c 100644 --- a/README.md +++ b/README.md @@ -404,8 +404,8 @@ Intrigued? That's only scratching the surface of what DocArray is capable of. [R -## Support +## Support & talk to us - Join our [Discord server](https://discord.gg/WaMp6PVPgR) and chat with other community members about ideas. - +- Join our [public meetings](https://calendar.google.com/calendar/u/2?cid=Y180NmJjYjQ3ZjEzN2QzOThjZjhjZmM2MzM0YTYyMjRkMjVhMjY1NTBlMGZkNjZkOGFmOWUyNjZiMDU4ODkyYmIxQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20) where we discuss the future of the project > DocArray is a trademark of LF AI Projects, LLC From 4bf3b176095f4d25f1467ab0b332db6b4f05f1f2 Mon Sep 17 00:00:00 2001 From: Johannes Messner <44071807+JohannesMessner@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:51:51 +0100 Subject: [PATCH 4/4] docs: apply suggestion Co-authored-by: Alex Cureton-Griffiths Signed-off-by: Johannes Messner <44071807+JohannesMessner@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fae63ffa9c..e23b81ba66f 100644 --- a/README.md +++ b/README.md @@ -406,6 +406,6 @@ Intrigued? That's only scratching the surface of what DocArray is capable of. [R ## Support & talk to us - Join our [Discord server](https://discord.gg/WaMp6PVPgR) and chat with other community members about ideas. -- Join our [public meetings](https://calendar.google.com/calendar/u/2?cid=Y180NmJjYjQ3ZjEzN2QzOThjZjhjZmM2MzM0YTYyMjRkMjVhMjY1NTBlMGZkNjZkOGFmOWUyNjZiMDU4ODkyYmIxQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20) where we discuss the future of the project +- Join our [public meetings](https://calendar.google.com/calendar/u/2?cid=Y180NmJjYjQ3ZjEzN2QzOThjZjhjZmM2MzM0YTYyMjRkMjVhMjY1NTBlMGZkNjZkOGFmOWUyNjZiMDU4ODkyYmIxQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20) where we discuss the future of the project. > DocArray is a trademark of LF AI Projects, LLC