Skip to content

Commit a39c4f9

Browse files
author
Joan Fontanals
authored
docs: update readme (#1744)
1 parent bd3d8f0 commit a39c4f9

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

README.md

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ New to DocArray? Depending on your use case and background, there are multiple w
4242
- [Coming from pure PyTorch or TensorFlow](#coming-from-pytorch)
4343
- [Coming from Pydantic](#coming-from-pydantic)
4444
- [Coming from FastAPI](#coming-from-fastapi)
45+
- [Coming from Jina](#coming-from-jina)
4546
- [Coming from a vector database](#coming-from-a-vector-database)
4647
- [Coming from Langchain](#coming-from-langchain)
4748

@@ -681,7 +682,7 @@ from fastapi import FastAPI
681682
from docarray.base_doc import DocArrayResponse
682683
from docarray import BaseDoc
683684
from docarray.documents import ImageDoc
684-
from docarray.typing import NdArray
685+
from docarray.typing import NdArray, ImageTensor
685686

686687

687688
class InputDoc(BaseDoc):
@@ -712,6 +713,7 @@ async def create_item(doc: InputDoc) -> OutputDoc:
712713
)
713714
return doc
714715

716+
input_doc = InputDoc(text='', img=ImageDoc(tensor=np.random.random((3, 224, 224))))
715717

716718
async with AsyncClient(app=app, base_url="http://test") as ac:
717719
response = await ac.post("/embed/", data=input_doc.json())
@@ -721,6 +723,70 @@ Just like a vanilla Pydantic model!
721723

722724
</details>
723725

726+
### Coming from Jina
727+
728+
<details markdown="1">
729+
<summary>Click to expand</summary>
730+
731+
Jina has adopted docarray as their library for representing and serializing Documents.
732+
733+
Jina allows to serve models and services that are built with DocArray allowing you to serve and scale these applications
734+
making full use of DocArray's serialization capabilites.
735+
736+
```python
737+
import numpy as np
738+
from jina import Deployment, Executor, requests
739+
from docarray import BaseDoc, DocList
740+
from docarray.documents import ImageDoc
741+
from docarray.typing import NdArray, ImageTensor
742+
743+
744+
class InputDoc(BaseDoc):
745+
img: ImageDoc
746+
text: str
747+
748+
749+
class OutputDoc(BaseDoc):
750+
embedding_clip: NdArray
751+
embedding_bert: NdArray
752+
753+
754+
def model_img(img: ImageTensor) -> NdArray:
755+
return np.zeros((100, 1))
756+
757+
758+
def model_text(text: str) -> NdArray:
759+
return np.zeros((100, 1))
760+
761+
762+
class MyEmbeddingExecutor(Executor):
763+
@requests(on='/embed')
764+
def encode(self, docs: DocList[InputDoc], **kwargs) -> DocList[OutputDoc]:
765+
ret = DocList[OutputDoc]()
766+
for doc in docs:
767+
output = OutputDoc(
768+
embedding_clip=model_img(doc.img.tensor),
769+
embedding_bert=model_text(doc.text),
770+
)
771+
ret.append(output)
772+
return ret
773+
774+
775+
with Deployment(
776+
protocols=['grpc', 'http'], ports=[12345, 12346], uses=MyEmbeddingExecutor
777+
) as dep:
778+
resp = dep.post(
779+
on='/embed',
780+
inputs=DocList[InputDoc](
781+
[InputDoc(text='', img=ImageDoc(tensor=np.random.random((3, 224, 224))))]
782+
),
783+
return_type=DocList[OutputDoc],
784+
)
785+
print(resp)
786+
```
787+
788+
</details>
789+
724790
### Coming from a vector database
725791

726792
<details markdown="1">
@@ -774,13 +840,12 @@ Currently, DocArray supports the following vector databases:
774840
- [Qdrant](https://qdrant.tech/)
775841
- [Elasticsearch](https://www.elastic.co/elasticsearch/) v8 and v7
776842
- [Redis](https://redis.io/)
843+
- [Milvus](https://milvus.io)
777844
- ExactNNMemorySearch as a local alternative with exact kNN search.
778845
- [HNSWlib](https://github.com/nmslib/hnswlib) as a local-first ANN alternative
779846

780847
An integration of [OpenSearch](https://opensearch.org/) is currently in progress.
781848

782-
DocArray <=0.21 also support [Milvus](https://milvus.io/), but this is not yet supported in the current version.
783-
784849
Of course this is only one of the things that DocArray can do, so we encourage you to check out the rest of this readme!
785850

786851
</details>

0 commit comments

Comments
 (0)