Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/build_docs_on_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ jobs:
run: |
npm i -g netlify-cli
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install wheel
python -m pip install poetry
cd ..
python -m poetry config virtualenvs.create false && python -m poetry install --no-interaction --no-ansi --all-extras

cd docs
export NUM_RELEASES=2 # only 2 last tags to save build time
bash makedoc.sh
netlify deploy --dir=_build/dirhtml --alias="docarray-v2" --message="Deploying docs to docarray v2"
bash makedocs.sh
cd ..
netlify deploy --dir=site --alias="docarray-v2" --message="Deploying docs to docarray v2"
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN1 }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
working-directory: docs
10 changes: 3 additions & 7 deletions .github/workflows/ci_only_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,16 @@ jobs:
run: |
npm i -g netlify-cli
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m pip install wheel
python -m pip install poetry
cd ..
python -m poetry config virtualenvs.create false && python -m poetry install --no-interaction --no-ansi --all-extras

cd docs
export NUM_RELEASES=2 # only 2 last tags to save build time
bash makedoc.sh
netlify deploy --dir=_build/dirhtml --alias="ft-${{ env.BRANCH_NAME }}" --message="Deploying docs to ${{ env.BRANCH_NAME }} branch"
bash makedocs.sh
cd ..
netlify deploy --dir=site --alias="ft-${{ env.BRANCH_NAME }}" --message="Deploying docs to ${{ env.BRANCH_NAME }} branch"
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN1 }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
working-directory: docs
- name: Find the prev comment if exists
uses: peter-evans/find-comment@v1
id: fc
Expand Down
7 changes: 2 additions & 5 deletions docarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
__version__ = '0.30.0a3'

from docarray.array.array.array import DocumentArray
from docarray.array import DocumentArray, DocumentArrayStacked
from docarray.base_document.document import BaseDocument

__all__ = [
'BaseDocument',
'DocumentArray',
]
__all__ = ['BaseDocument', 'DocumentArray', 'DocumentArrayStacked']
37 changes: 19 additions & 18 deletions docarray/array/array/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,38 @@ class DocumentArray(
"""
DocumentArray is a container of Documents.

:param docs: iterable of Document
:param tensor_type: Class used to wrap the tensors of the Documents when stacked

A DocumentArray is a list of Documents of any schema. However, many
DocumentArray features are only available if these Documents are
homogeneous and follow the same schema. To precise this schema you can use
the `DocumentArray[MyDocument]` syntax where MyDocument is a Document class
(i.e. schema). This creates a DocumentArray that can only contains Documents of
the type 'MyDocument'.

EXAMPLE USAGE
.. code-block:: python
from docarray import BaseDocument, DocumentArray
from docarray.typing import NdArray, ImageUrl
from typing import Optional
---

```python
from docarray import BaseDocument, DocumentArray
from docarray.typing import NdArray, ImageUrl
from typing import Optional


class Image(BaseDocument):
tensor: Optional[NdArray[100]]
url: ImageUrl

class Image(BaseDocument):
tensor: Optional[NdArray[100]]
url: ImageUrl

da = DocumentArray[Image](
Image(url='http://url.com/foo.png') for _ in range(10)
) # noqa: E510
```

da = DocumentArray[Image](
Image(url='http://url.com/foo.png') for _ in range(10)
) # noqa: E510
---


If your DocumentArray is homogeneous (i.e. follows the same schema), you can access
fields at the DocumentArray level (for example `da.tensor` or `da.url`).
You can also set fields, with `da.tensor = np.random.random([10, 100])`:


.. code-block:: python
print(da.url)
# [ImageUrl('http://url.com/foo.png', host_type='domain'), ...]
import numpy as np
Expand All @@ -106,18 +105,20 @@ class Image(BaseDocument):

You can index into a DocumentArray like a numpy array or torch tensor:

.. code-block:: python

da[0] # index by position
da[0:5:2] # index by slice
da[[0, 2, 3]] # index by list of indices
da[True, False, True, True, ...] # index by boolean mask

You can delete items from a DocumentArray like a Python List

.. code-block:: python
del da[0] # remove first element from DocumentArray
del da[0:5] # remove elements for 0 to 5 from DocumentArray

:param docs: iterable of Document
:param tensor_type: Class used to wrap the tensors of the Documents when stacked

"""

document_type: Type[BaseDocument] = AnyDocument
Expand Down
2 changes: 1 addition & 1 deletion docarray/array/array/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class Person(BaseDocument):

for row in df.itertuples():
access_path2val = row._asdict()
access_path2val.pop('Index', None)
access_path2val.pop('index', None)
doc_dict = _access_path_dict_to_nested_dict(access_path2val)
da.append(doc_type.parse_obj(doc_dict))

Expand Down
18 changes: 9 additions & 9 deletions docarray/doc_index/abstract_doc_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _FindResultBatched(NamedTuple):
def _raise_not_composable(name):
def _inner(self, *args, **kwargs):
raise NotImplementedError(
f'`{name}` is not usable through the query builder of this Document Index ({type(self)}). '
f'`{name}` is not usable through the query builder of this Document index ({type(self)}). '
f'But you can call `{type(self)}.{name}()` directly.'
)

Expand All @@ -58,7 +58,7 @@ def _inner(self, *args, **kwargs):
def _raise_not_supported(name):
def _inner(self, *args, **kwargs):
raise NotImplementedError(
f'`{name}` is not usable through the query builder of this Document Index ({type(self)}). '
f'`{name}` is not usable through the query builder of this Document index ({type(self)}). '
)

return _inner
Expand Down Expand Up @@ -148,7 +148,7 @@ def python_type_to_db_type(self, python_type: Type) -> Any:

@abstractmethod
def _index(self, column_to_data: Dict[str, Generator[Any, None, None]]):
"""Index a document into the store"""
"""index a document into the store"""
# `column_to_data` is a dictionary from column name to a generator
# that yields the data for that column.
# If you want to work directly on documents, you can implement index() instead
Expand All @@ -175,7 +175,7 @@ def _get_items(
"""Get Documents from the index, by `id`.
If no document is found, a KeyError is raised.

:param doc_ids: ids to get from the Document Index
:param doc_ids: ids to get from the Document index
:return: Sequence of Documents, sorted corresponding to the order of `doc_ids`. Duplicate `doc_ids` can be omitted in the output.
"""
...
Expand All @@ -187,8 +187,8 @@ def execute_query(self, query: Any, *args, **kwargs) -> Any:

Can take two kinds of inputs:
- A native query of the underlying database. This is meant as a passthrough so that you
can enjoy any functionality that is not available through the Document Index API.
- The output of this Document Index' `QueryBuilder.build()` method.
can enjoy any functionality that is not available through the Document index API.
- The output of this Document index' `QueryBuilder.build()` method.

:param query: the query to execute
:param args: positional arguments to pass to the query
Expand Down Expand Up @@ -309,7 +309,7 @@ def __getitem__(
"""Get one or multiple Documents into the index, by `id`.
If no document is found, a KeyError is raised.

:param key: id or ids to get from the Document Index
:param key: id or ids to get from the Document index
"""
# normalize input
if isinstance(key, str):
Expand Down Expand Up @@ -340,7 +340,7 @@ def __delitem__(self, key: Union[str, Sequence[str]]):
"""Delete one or multiple Documents from the index, by `id`.
If no document is found, a KeyError is raised.

:param key: id or ids to delete from the Document Index
:param key: id or ids to delete from the Document index
"""
if isinstance(key, str):
key = [key]
Expand All @@ -365,7 +365,7 @@ def configure(self, runtime_config=None, **kwargs):
self._runtime_config = runtime_config

def index(self, docs: Union[BaseDocument, Sequence[BaseDocument]], **kwargs):
"""Index Documents into the index.
"""index Documents into the index.

:param docs: Documents to index
"""
Expand Down
4 changes: 2 additions & 2 deletions docarray/doc_index/backends/hnswlib_doc_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _index(self, column_data_dic, **kwargs):
...

def index(self, docs: Union[BaseDocument, Sequence[BaseDocument]], **kwargs):
"""Index a document into the store"""
"""index a document into the store"""
if kwargs:
raise ValueError(f'{list(kwargs.keys())} are not valid keyword arguments')
doc_seq = docs if isinstance(docs, Sequence) else [docs]
Expand Down Expand Up @@ -325,7 +325,7 @@ def _to_numpy(self, val: Any) -> Any:

# HNSWLib helpers
def _create_index_class(self, col: '_ColumnInfo') -> hnswlib.Index:
"""Create an instance of hnswlib.Index without initializing it."""
"""Create an instance of hnswlib.index without initializing it."""
construct_params = dict(
(k, col.config[k]) for k in self._index_construct_params
)
Expand Down
19 changes: 0 additions & 19 deletions docs/Makefile

This file was deleted.

Binary file removed docs/_static/banner.png
Binary file not shown.
Loading