| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 177b5b3 commit 63a43d9
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,49 +12,56 @@ | |||
| 12 | 12 | <a href="https://discord.gg/WaMp6PVPgR"><img src="https://dcbadge.vercel.app/api/server/WaMp6PVPgR?theme=default-inverted&style=flat-square"></a> | |
| 13 | 13 | </p> | |
| 14 | 14 | ||
| 15 | - > ⬆️ **DocArray v2**: This readme is for the second version of DocArray (starting at 0.30). If you want to use the older | ||
| 16 | - > version (prior to 0.30) check out the [docarray-v1-fixes](https://github.com/docarray/docarray/tree/docarray-v1-fixes) branch | ||
| 15 | + > **Note** | ||
| 16 | + > The README you're currently viewing is for DocArray>0.30, which introduces some significant changes from DocArray 0.21. If you wish to continue using the older DocArray <=0.21, ensure you install it via `pip install docarray==0.21`. Refer to its [codebase](https://github.com/docarray/docarray/tree/v0.21.0), [documentation](https://docarray.jina.ai), and [its hot-fixes branch](https://github.com/docarray/docarray/tree/docarray-v1-fixes) for more information. | ||
| 17 | 17 | ||
| 18 | - DocArray is a library for **representing, sending and storing multi-modal data**, perfect for **Machine Learning applications**. | ||
| 19 | 18 | ||
| 20 | - With DocArray you can: | ||
| 19 | + DocArray is a Python library expertly crafted for the [representation](#represent), [transmission](#send), [storage](#store), and [retrieval](#retrieve) of multimodal data. Tailored for the development of multimodal AI applications, its design guarantees seamless integration with the extensive Python and machine learning ecosystems. As of January 2022, DocArray is openly distributed under the [Apache License 2.0](https://github.com/docarray/docarray/blob/main/LICENSE) and currently enjoys the status of a sandbox project within the [LF AI & Data Foundation](https://lfaidata.foundation/). | ||
| 21 | 20 | ||
| 22 | - 1. [**Represent data**](#represent) | ||
| 23 | - 2. [**Send data**](#send) | ||
| 24 | - 3. [**Store data**](#store) | ||
| 25 | 21 | ||
| 26 | - DocArray handles your data while integrating seamlessly with the rest of your **Python and ML ecosystem**: | ||
| 27 | 22 | ||
| 28 | - - :fire: Native compatibility for **[NumPy](https://github.com/numpy/numpy)**, **[PyTorch](https://github.com/pytorch/pytorch)** and **[TensorFlow](https://github.com/tensorflow/tensorflow)**, including for **model training use cases** | ||
| 29 | - - :zap: Built on **[Pydantic](https://github.com/pydantic/pydantic)** and out-of-the-box compatible with **[FastAPI](https://github.com/tiangolo/fastapi/)** and **[Jina](https://github.com/jina-ai/jina/)** | ||
| 30 | - - :package: Support for vector databases like **[Weaviate](https://weaviate.io/), [Qdrant](https://qdrant.tech/), [ElasticSearch](https://www.elastic.co/de/elasticsearch/)** and **[HNSWLib](https://github.com/nmslib/hnswlib)** | ||
| 31 | - - :chains: Send data as JSON over **HTTP** or as **[Protobuf](https://protobuf.dev/)** over **[gRPC](https://grpc.io/)** | ||
| 23 | + - :fire: Offers native support for **[NumPy](https://github.com/numpy/numpy)**, **[PyTorch](https://github.com/pytorch/pytorch)**, and **[TensorFlow](https://github.com/tensorflow/tensorflow)**, catering specifically to **model training scenarios**. | ||
| 24 | + - :zap: Based on **[Pydantic](https://github.com/pydantic/pydantic)**, and instantly compatible with web and microservice frameworks like **[FastAPI](https://github.com/tiangolo/fastapi/)** and **[Jina](https://github.com/jina-ai/jina/)**. | ||
| 25 | + - :package: Provides support for vector databases such as **[Weaviate](https://weaviate.io/), [Qdrant](https://qdrant.tech/), [ElasticSearch](https://www.elastic.co/de/elasticsearch/)**, and **[HNSWLib](https://github.com/nmslib/hnswlib)**. | ||
| 26 | + - :chains: Allows data transmission as JSON over **HTTP** or as **[Protobuf](https://protobuf.dev/)** over **[gRPC](https://grpc.io/)**. | ||
| 32 | 27 | ||
| 33 | - > :bulb: **Where are you coming from?** Based on your use case and background, there are different ways to understand DocArray: | ||
| 34 | - > | ||
| 35 | - > - [Coming from pure PyTorch or TensorFlow](#coming-from-pytorch) | ||
| 36 | - > - [Coming from Pydantic](#coming-from-pydantic) | ||
| 37 | - > - [Coming from FastAPI](#coming-from-fastapi) | ||
| 38 | - > - [Coming from a vector database](#coming-from-vector-database) | ||
| 39 | - > - [Coming from Langchain](#coming-from-langchain) | ||
| 28 | + ## Installation | ||
| 29 | + | ||
| 30 | + To install DocArray from the CLI, run the following command: | ||
| 31 | + | ||
| 32 | + ```shell | ||
| 33 | + pip install -U docarray | ||
| 34 | + ``` | ||
| 35 | + | ||
| 36 | + > **Note** | ||
| 37 | + > To use DocArray <=0.21, make sure you install via `pip install docarray==0.21` and check out its [codebase](https://github.com/docarray/docarray/tree/v0.21.0) and [docs](https://docarray.jina.ai) and [its hot-fixes branch](https://github.com/docarray/docarray/tree/docarray-v1-fixes). | ||
| 38 | + | ||
| 39 | + ## Get Started | ||
| 40 | + New to DocArray? Depending on your use case and background, there are multiple ways to learn about DocArray: | ||
| 41 | + | ||
| 42 | + - [Coming from pure PyTorch or TensorFlow](#coming-from-pytorch) | ||
| 43 | + - [Coming from Pydantic](#coming-from-pydantic) | ||
| 44 | + - [Coming from FastAPI](#coming-from-fastapi) | ||
| 45 | + - [Coming from a vector database](#coming-from-vector-database) | ||
| 46 | + - [Coming from Langchain](#coming-from-langchain) | ||
| 40 | 47 | ||
| 41 | - DocArray has been distributed under the open-source [Apache License 2.0](https://github.com/docarray/docarray/blob/main/LICENSE) since January 2022. It is currently a sandbox project under [LF AI & Data Foundation](https://lfaidata.foundation/). | ||
| 42 | 48 | ||
| 43 | 49 | ## Represent | |
| 44 | 50 | ||
| 45 | - DocArray allows you to **represent your data**, in an ML-native way. | ||
| 51 | + DocArray empowers you to **represent your data** in a manner that is inherently attuned to machine learning. | ||
| 46 | 52 | ||
| 47 | - This is useful for different use cases: | ||
| 53 | + This is particularly beneficial for various scenarios: | ||
| 48 | 54 | ||
| 49 | - - :running: You are **training a model**: There are tensors of different shapes and sizes flying around, representing different _things_, and you want to keep a straight head about them. | ||
| 50 | - - :cloud: You are **serving a model**: For example through FastAPI, and you want to specify your API endpoints. | ||
| 51 | - - :card_index_dividers: You are **parsing data**: For later use in your ML or data science applications. | ||
| 55 | + - :running: You are **training a model**: You're dealing with tensors of varying shapes and sizes, each signifying different elements. You desire a method to logically organize them. | ||
| 56 | + - :cloud: You are **serving a model**: Let's say through FastAPI, and you wish to define your API endpoints precisely. | ||
| 57 | + - :card_index_dividers: You are **parsing data**: Perhaps for future deployment in your machine learning or data science projects. | ||
| 52 | 58 | ||
| 53 | - > :bulb: **Coming from Pydantic?** You should be happy to hear | ||
| 54 | - > that DocArray is built on top of, and is fully compatible with, Pydantic! | ||
| 55 | - > Also, we have a [dedicated section](#coming-from-pydantic) just for you! | ||
| 59 | + > :bulb: **Familiar with Pydantic?** You'll be pleased to learn | ||
| 60 | + > that DocArray is not only constructed atop Pydantic but also maintains complete compatibility with it! | ||
| 61 | + > Furthermore, we have a [specific section](#coming-from-pydantic) dedicated to your needs! | ||
| 62 | + | ||
| 63 | + In essence, DocArray facilitates data representation in a way that mirrors Python dataclasses, with machine learning being an integral component: | ||
| 56 | 64 | ||
| 57 | - Put simply, DocArray lets you represent your data in a dataclass-like way, with ML as a first class citizen: | ||
| 58 | 65 | ||
| 59 | 66 | ```python | |
| 60 | 67 | from docarray import BaseDoc | |
@@ -256,21 +263,22 @@ assert isinstance(dl_2, DocList) | |||
| 256 | 263 | ||
| 257 | 264 | ## Send | |
| 258 | 265 | ||
| 259 | - DocArray allows you to **send your data** in an ML-native way. | ||
| 266 | + DocArray facilitates the **transmission of your data** in a manner inherently compatible with machine learning. | ||
| 267 | + | ||
| 268 | + This includes native support for **Protobuf and gRPC**, along with **HTTP** and serialization to JSON, JSONSchema, Base64, and Bytes. | ||
| 260 | 269 | ||
| 261 | - This means there is native support for **Protobuf and gRPC**, on top of **HTTP** and serialization to JSON, JSONSchema, Base64, and Bytes. | ||
| 270 | + This feature proves beneficial for several scenarios: | ||
| 262 | 271 | ||
| 263 | - This is useful for different use cases: | ||
| 272 | + - :cloud: You are **serving a model**, perhaps through frameworks like **[Jina](https://github.com/jina-ai/jina/)** or **[FastAPI](https://github.com/tiangolo/fastapi/)** | ||
| 273 | + - :spider_web: You are **distributing your model** across multiple machines and need an efficient means of transmitting your data between nodes | ||
| 274 | + - :gear: You are architecting a **microservice** environment and require a method for data transmission between microservices | ||
| 264 | 275 | ||
| 265 | - - :cloud: You are **serving a model**, for example through **[Jina](https://github.com/jina-ai/jina/)** or **[FastAPI](https://github.com/tiangolo/fastapi/)** | ||
| 266 | - - :spider_web: You are **distributing your model** across machines and need to send your data between nodes | ||
| 267 | - - :gear: You are building a **microservice** architecture and need to send your data between microservices | ||
| 276 | + > :bulb: **Are you familiar with FastAPI?** You'll be delighted to learn | ||
| 277 | + > that DocArray maintains full compatibility with FastAPI! | ||
| 278 | + > Plus, we have a [dedicated section](#coming-from-fastapi) specifically for you! | ||
| 268 | 279 | ||
| 269 | - > :bulb: **Coming from FastAPI?** You should be happy to hear | ||
| 270 | - > that DocArray is fully compatible with FastAPI! | ||
| 271 | - > Also, we have a [dedicated section](#coming-from-fastapi) just for you! | ||
| 280 | + When it comes to data transmission, serialization is a crucial step. Let's delve into how DocArray streamlines this process: | ||
| 272 | 281 | ||
| 273 | - Whenever you want to send your data, you need to serialize it, so let's take a look at how that works with DocArray: | ||
| 274 | 282 | ||
| 275 | 283 | ```python | |
| 276 | 284 | from docarray import BaseDoc | |
@@ -305,18 +313,14 @@ Of course, serialization is not all you need. So check out how DocArray integrat | |||
| 305 | 313 | ||
| 306 | 314 | ## Store | |
| 307 | 315 | ||
| 308 | - Once you've modelled your data, and maybe sent it around, usually you want to **store it** somewhere. | ||
| 309 | - DocArray has you covered! | ||
| 316 | + After modeling and possibly distributing your data, you'll typically want to **store it** somewhere. That's where DocArray steps in! | ||
| 310 | 317 | ||
| 311 | - **Document Stores** let you, well, store your Documents, locally or remotely, all with the same user interface: | ||
| 318 | + **Document Stores** provide a seamless way to, as the name suggests, store your Documents. Be it locally or remotely, you can do it all through the same user interface: | ||
| 312 | 319 | ||
| 313 | - - :cd: **On disk** as a file in your local file system | ||
| 320 | + - :cd: **On disk**, as a file in your local filesystem | ||
| 314 | 321 | - :bucket: On **[AWS S3](https://aws.amazon.com/de/s3/)** | |
| 315 | 322 | - :cloud: On **[Jina AI Cloud](https://cloud.jina.ai/)** | |
| 316 | 323 | ||
| 317 | - <details markdown="1"> | ||
| 318 | - <summary>See Document Store usage</summary> | ||
| 319 | - | ||
| 320 | 324 | The Document Store interface lets you push and pull Documents to and from multiple data sources, all with the same user interface. | |
| 321 | 325 | ||
| 322 | 326 | For example, let's see how that works with on-disk storage: | |
@@ -334,7 +338,8 @@ docs.push('file://simple_docs') | |||
| 334 | 338 | ||
| 335 | 339 | docs_pull = DocList[SimpleDoc].pull('file://simple_docs') | |
| 336 | 340 | ``` | |
| 337 | - </details> | ||
| 341 | + | ||
| 342 | + ## Retrieve | ||
| 338 | 343 | ||
| 339 | 344 | **Document Indexes** let you index your Documents in a **vector database** for efficient similarity-based retrieval. | |
| 340 | 345 | ||
@@ -346,9 +351,6 @@ This is useful for: | |||
| 346 | 351 | ||
| 347 | 352 | Currently, Document Indexes support **[Weaviate](https://weaviate.io/)**, **[Qdrant](https://qdrant.tech/)**, **[ElasticSearch](https://www.elastic.co/)**, and **[HNSWLib](https://github.com/nmslib/hnswlib)**, with more to come! | |
| 348 | 353 | ||
| 349 | - <details markdown="1"> | ||
| 350 | - <summary>See Document Index usage</summary> | ||
| 351 | - | ||
| 352 | 354 | The Document Index interface lets you index and retrieve Documents from multiple vector databases, all with the same user interface. | |
| 353 | 355 | ||
| 354 | 356 | It supports ANN vector search, text search, filtering, and hybrid search. | |
@@ -391,18 +393,21 @@ query = dl[0] | |||
| 391 | 393 | results, scores = index.find(query, limit=10, search_field='embedding') | |
| 392 | 394 | ``` | |
| 393 | 395 | ||
| 394 | - </details> | ||
| 396 | + | ||
| 397 | + --- | ||
| 398 | + | ||
| 399 | + ## Learn DocArray | ||
| 395 | 400 | ||
| 396 | 401 | Depending on your background and use case, there are different ways for you to understand DocArray. | |
| 397 | 402 | ||
| 398 | - ## Coming from old DocArray | ||
| 403 | + ### Coming from DocArray <=0.21 | ||
| 399 | 404 | ||
| 400 | 405 | <details markdown="1"> | |
| 401 | 406 | <summary>Click to expand</summary> | |
| 402 | 407 | ||
| 403 | 408 | If you are using DocArray version 0.30.0 or lower, you will be familiar with its [dataclass API](https://docarray.jina.ai/fundamentals/dataclass/). | |
| 404 | 409 | ||
| 405 | - _DocArray v2 is that idea, taken seriously._ Every document is created through a dataclass-like interface, | ||
| 410 | + _DocArray >=0.30 is that idea, taken seriously._ Every document is created through a dataclass-like interface, | ||
| 406 | 411 | courtesy of [Pydantic](https://pydantic-docs.helpmanual.io/usage/models/). | |
| 407 | 412 | ||
| 408 | 413 | This gives the following advantages: | |
@@ -420,7 +425,7 @@ For now, Document Indexes support **[Weaviate](https://weaviate.io/)**, **[Qdran | |||
| 420 | 425 | ||
| 421 | 426 | </details> | |
| 422 | 427 | ||
| 423 | - ## Coming from Pydantic | ||
| 428 | + ### Coming from Pydantic | ||
| 424 | 429 | ||
| 425 | 430 | <details markdown="1"> | |
| 426 | 431 | <summary>Click to expand</summary> | |
@@ -497,7 +502,7 @@ except Exception as e: | |||
| 497 | 502 | ||
| 498 | 503 | </details> | |
| 499 | 504 | ||
| 500 | - ## Coming from PyTorch | ||
| 505 | + ### Coming from PyTorch | ||
| 501 | 506 | ||
| 502 | 507 | <details markdown="1"> | |
| 503 | 508 | <summary>Click to expand</summary> | |
@@ -511,7 +516,7 @@ It offers you several advantages: | |||
| 511 | 516 | - **Go directly to deployment**, by re-using your data model as a [FastAPI](https://fastapi.tiangolo.com/) or [Jina](https://github.com/jina-ai/jina) API schema | |
| 512 | 517 | - Connect model components between **microservices**, using Protobuf and gRPC | |
| 513 | 518 | ||
| 514 | - DocArray can be used directly inside ML models to handle and represent multi-modal data. | ||
| 519 | + DocArray can be used directly inside ML models to handle and represent multimodaldata. | ||
| 515 | 520 | This allows you to reason about your data using DocArray's abstractions deep inside of `nn.Module`, | |
| 516 | 521 | and provides a FastAPI-compatible schema that eases the transition between model training and model serving. | |
| 517 | 522 | ||
@@ -609,7 +614,7 @@ schema definition (see [below](#coming-from-fastapi)). Everything is handled in | |||
| 609 | 614 | </details> | |
| 610 | 615 | ||
| 611 | 616 | ||
| 612 | - ## Coming from TensorFlow | ||
| 617 | + ### Coming from TensorFlow | ||
| 613 | 618 | ||
| 614 | 619 | <details markdown="1"> | |
| 615 | 620 | <summary>Click to expand</summary> | |
@@ -657,7 +662,7 @@ class MyPodcastModel(tf.keras.Model): | |||
| 657 | 662 | ||
| 658 | 663 | </details> | |
| 659 | 664 | ||
| 660 | - ## Coming from FastAPI | ||
| 665 | + ### Coming from FastAPI | ||
| 661 | 666 | ||
| 662 | 667 | <details markdown="1"> | |
| 663 | 668 | <summary>Click to expand</summary> | |
@@ -680,6 +685,7 @@ from docarray import BaseDoc | |||
| 680 | 685 | from docarray.documents import ImageDoc | |
| 681 | 686 | from docarray.typing import NdArray | |
| 682 | 687 | ||
| 688 | + | ||
| 683 | 689 | class InputDoc(BaseDoc): | |
| 684 | 690 | img: ImageDoc | |
| 685 | 691 | text: str | |
@@ -692,29 +698,32 @@ class OutputDoc(BaseDoc): | |||
| 692 | 698 | ||
| 693 | 699 | app = FastAPI() | |
| 694 | 700 | ||
| 701 | + | ||
| 695 | 702 | def model_img(img: ImageTensor) -> NdArray: | |
| 696 | 703 | return np.zeros((100, 1)) | |
| 697 | 704 | ||
| 705 | + | ||
| 698 | 706 | def model_text(text: str) -> NdArray: | |
| 699 | 707 | return np.zeros((100, 1)) | |
| 700 | 708 | ||
| 709 | + | ||
| 701 | 710 | @app.post("/embed/", response_model=OutputDoc, response_class=DocArrayResponse) | |
| 702 | 711 | async def create_item(doc: InputDoc) -> OutputDoc: | |
| 703 | 712 | doc = OutputDoc( | |
| 704 | 713 | embedding_clip=model_img(doc.img.tensor), embedding_bert=model_text(doc.text) | |
| 705 | 714 | ) | |
| 706 | 715 | return doc | |
| 707 | 716 | ||
| 717 | + | ||
| 708 | 718 | async with AsyncClient(app=app, base_url="http://test") as ac: | |
| 709 | 719 | response = await ac.post("/embed/", data=input_doc.json()) | |
| 710 | - | ||
| 711 | 720 | ``` | |
| 712 | 721 | ||
| 713 | 722 | Just like a vanilla Pydantic model! | |
| 714 | 723 | ||
| 715 | 724 | </details> | |
| 716 | 725 | ||
| 717 | - ## Coming from a vector database | ||
| 726 | + ### Coming from a vector database | ||
| 718 | 727 | ||
| 719 | 728 | <details markdown="1"> | |
| 720 | 729 | <summary>Click to expand</summary> | |
@@ -770,14 +779,14 @@ Currently, DocArray supports the following vector databases: | |||
| 770 | 779 | ||
| 771 | 780 | An integration of [OpenSearch](https://opensearch.org/) is currently in progress. | |
| 772 | 781 | ||
| 773 | - Legacy versions of DocArray also support [Redis](https://redis.io/) and [Milvus](https://milvus.io/), but these are not yet supported in the current version. | ||
| 782 | + DocArray <=0.21 also support [Redis](https://redis.io/) and [Milvus](https://milvus.io/), but these are not yet supported in the current version. | ||
| 774 | 783 | ||
| 775 | 784 | 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! | |
| 776 | 785 | ||
| 777 | 786 | </details> | |
| 778 | 787 | ||
| 779 | 788 | ||
| 780 | - ## Coming from Langchain | ||
| 789 | + ### Coming from Langchain | ||
| 781 | 790 | ||
| 782 | 791 | <details markdown="1"> | |
| 783 | 792 | <summary>Click to expand</summary> | |
@@ -835,7 +844,6 @@ db = InMemoryExactNNIndex[MovieDoc](docs) | |||
| 835 | 844 | ||
| 836 | 845 | 3. Finally, initialize a retriever and integrate it into your chain! | |
| 837 | 846 | ```python | |
| 838 | - | ||
| 839 | 847 | from langchain.chat_models import ChatOpenAI | |
| 840 | 848 | from langchain.chains import ConversationalRetrievalChain | |
| 841 | 849 | from langchain.retrievers import DocArrayRetriever | |
@@ -859,20 +867,13 @@ Both are user-friendly and are best suited to small to medium-sized datasets. | |||
| 859 | 867 | ||
| 860 | 868 | </details> | |
| 861 | 869 | ||
| 862 | - ## Installation | ||
| 863 | - | ||
| 864 | - To install DocArray from the CLI, run the following command: | ||
| 865 | - | ||
| 866 | - ```shell | ||
| 867 | - pip install -U docarray | ||
| 868 | - ``` | ||
| 869 | 870 | ||
| 870 | 871 | ## See also | |
| 871 | 872 | ||
| 872 | 873 | - [Documentation](https://docs.docarray.org) | |
| 874 | + - [DocArray<=0.21 documentation](https://docarray.jina.ai/) | ||
| 873 | 875 | - [Join our Discord server](https://discord.gg/WaMp6PVPgR) | |
| 874 | 876 | - [Donation to Linux Foundation AI&Data blog post](https://jina.ai/news/donate-docarray-lf-for-inclusive-standard-multimodal-data-model/) | |
| 875 | - - ["Legacy" DocArray github page](https://github.com/docarray/docarray/tree/docarray-v1-fixes) | ||
| 876 | - - ["Legacy" DocArray documentation](https://docarray.jina.ai/) | ||
| 877 | + | ||
| 877 | 878 | ||
| 878 | 879 | > DocArray is a trademark of LF AI Projects, LLC | |
| Back | FazBrowse Home | New Git URL |
0 commit comments