From d836e326de76ac6bd4472a3e98c96ffb9246aaed Mon Sep 17 00:00:00 2001 From: Joan Fontanals Martinez Date: Thu, 3 Aug 2023 07:44:21 +0200 Subject: [PATCH 1/2] docs: update readme --- README.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 17cdd535d4..ebf3607cb1 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ New to DocArray? Depending on your use case and background, there are multiple w - [Coming from pure PyTorch or TensorFlow](#coming-from-pytorch) - [Coming from Pydantic](#coming-from-pydantic) - [Coming from FastAPI](#coming-from-fastapi) +- [Coming from Jina](#coming-from-jina) - [Coming from a vector database](#coming-from-a-vector-database) - [Coming from Langchain](#coming-from-langchain) @@ -681,7 +682,7 @@ from fastapi import FastAPI from docarray.base_doc import DocArrayResponse from docarray import BaseDoc from docarray.documents import ImageDoc -from docarray.typing import NdArray +from docarray.typing import NdArray, ImageTensor class InputDoc(BaseDoc): @@ -712,6 +713,7 @@ async def create_item(doc: InputDoc) -> OutputDoc: ) return doc +input_doc = InputDoc(text='', img=ImageDoc(tensor=np.random.random((3, 224, 224)))) async with AsyncClient(app=app, base_url="http://test") as ac: response = await ac.post("/embed/", data=input_doc.json()) @@ -721,6 +723,74 @@ Just like a vanilla Pydantic model! +### Coming from Jina + +
+ Click to expand + +Jina has adopted docarray as their library for representing and serializing Documents. + +Jina allows to serve models and services that are built with `docarray` allowing you to serve and scale these applications +making full use of `docarray`'s serialization capabilites. + +how easily documents slot into your FastAPI app: + +```python +import numpy as np +from jina import Deployment, Executor, requests +from docarray import BaseDoc, DocList +from docarray.documents import ImageDoc +from docarray.typing import NdArray, ImageTensor + + +class InputDoc(BaseDoc): + img: ImageDoc + text: str + + +class OutputDoc(BaseDoc): + embedding_clip: NdArray + embedding_bert: NdArray + + +def model_img(img: ImageTensor) -> NdArray: + return np.zeros((100, 1)) + + +def model_text(text: str) -> NdArray: + return np.zeros((100, 1)) + + +class MyEmbeddingExecutor(Executor): + @requests(on='/embed') + def encode(self, docs: DocList[InputDoc], **kwargs) -> DocList[OutputDoc]: + ret = DocList[OutputDoc]() + for doc in docs: + output = OutputDoc( + embedding_clip=model_img(doc.img.tensor), + embedding_bert=model_text(doc.text), + ) + ret.append(output) + return ret + + +with Deployment( + protocols=['grpc', 'http'], ports=[12345, 12346], uses=MyEmbeddingExecutor +) as dep: + resp = dep.post( + on='/embed', + inputs=DocList[InputDoc]( + [InputDoc(text='', img=ImageDoc(tensor=np.random.random((3, 224, 224))))] + ), + return_type=DocList[OutputDoc], + ) + print(resp) +``` + +Just like a vanilla Pydantic model! + +
+ ### Coming from a vector database
@@ -774,13 +844,12 @@ Currently, DocArray supports the following vector databases: - [Qdrant](https://qdrant.tech/) - [Elasticsearch](https://www.elastic.co/elasticsearch/) v8 and v7 - [Redis](https://redis.io/) +- [Milvus](https://milvus.io) - ExactNNMemorySearch as a local alternative with exact kNN search. - [HNSWlib](https://github.com/nmslib/hnswlib) as a local-first ANN alternative An integration of [OpenSearch](https://opensearch.org/) is currently in progress. -DocArray <=0.21 also support [Milvus](https://milvus.io/), but this is not yet supported in the current version. - 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!
From 985e824f956caacad9cc1fcb25f36cc3ae8746cf Mon Sep 17 00:00:00 2001 From: Joan Fontanals Martinez Date: Thu, 3 Aug 2023 10:18:48 +0200 Subject: [PATCH 2/2] chore: adapt to changes requested --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ebf3607cb1..96f2d5faa1 100644 --- a/README.md +++ b/README.md @@ -730,10 +730,8 @@ Just like a vanilla Pydantic model! Jina has adopted docarray as their library for representing and serializing Documents. -Jina allows to serve models and services that are built with `docarray` allowing you to serve and scale these applications -making full use of `docarray`'s serialization capabilites. - -how easily documents slot into your FastAPI app: +Jina allows to serve models and services that are built with DocArray allowing you to serve and scale these applications +making full use of DocArray's serialization capabilites. ```python import numpy as np @@ -787,8 +785,6 @@ with Deployment( print(resp) ``` -Just like a vanilla Pydantic model! - ### Coming from a vector database