Skip to main content

Build multimodal AI services via cloud native technologies · Neural Search · Generative AI · MLOps

Project description

Jina logo: Build multimodal AI services via cloud native technologies · Neural Search · Generative AI · Cloud Native


Build multimodal AI services with cloud native technologies

PyPI Codecov branch PyPI - Downloads from official pypistats Github CD status

Jina is an MLOps framework to build multimodal AI microservice-based applications written in Python that can communicate via gRPC, HTTP and WebSocket protocols. It allows developers to build and serve services and pipelines while scaling and deploying them to a production while removing the complexity, letting them focus on the logic/algorithmic part, saving valuable time and resources for engineering teams.

Jina aims to provide a smooth Pythonic experience transitioning from local deployment to deploying to advanced orchestration frameworks such as Docker-Compose, Kubernetes, or Jina AI Cloud. It handles the infrastructure complexity, making advanced solution engineering and cloud-native technologies accessible to every developer.

Build and deploy a gRPC microserviceBuild and deploy a pipeline

Applications built with Jina enjoy the following features out of the box:

🌌 Universal

  • Build applications that deliver fresh insights from multiple data types such as text, image, audio, video, 3D mesh, PDF with LF's DocArray.
  • Support for all mainstream deep learning frameworks.
  • Polyglot gateway that supports gRPC, Websockets, HTTP, GraphQL protocols with TLS.

Performance

  • Intuitive design pattern for high-performance microservices.
  • Easy scaling: set replicas, sharding in one line.
  • Duplex streaming between client and server.
  • Async and non-blocking data processing over dynamic flows.

☁️ Cloud native

  • Seamless Docker container integration: sharing, exploring, sandboxing, versioning and dependency control via Executor Hub.
  • Full observability via OpenTelemetry, Prometheus and Grafana.
  • Fast deployment to Kubernetes and Docker Compose.

🍱 Ecosystem

  • Improved engineering efficiency thanks to the Jina AI ecosystem, so you can focus on innovating with the data applications you build.
  • Free CPU/GPU hosting via Jina AI Cloud.

Jina's value proposition may seem quite similar to that of FastAPI. However, there are several fundamental differences:

Data structure and communication protocols

  • FastAPI communication relies on Pydantic and Jina relies on DocArray allowing Jina to support multiple protocols to expose its services.

Advanced orchestration and scaling capabilities

  • Jina lets you deploy applications formed from multiple microservices that can be containerized and scaled independently.
  • Jina allows you to easily containerize and orchestrate your services, providing concurrency and scalability.

Journey to the cloud

  • Jina provides a smooth transition from local development (using DocArray) to local serving using (Jina's orchestration layer) to having production-ready services by using Kubernetes capacity to orchestrate the lifetime of containers.
  • By using Jina AI Cloud you have access to scalable and serverless deployments of your applications in one command.

Jina in Jina AI neural search ecosystem

Documentation

Install

pip install jina transformers sentencepiece

Find more install options on Apple Silicon/Windows.

Get Started

Basic Concepts

Jina has four fundamental concepts:

  • A Document (from DocArray) is the input/output format in Jina.
  • An Executor is a Python class that transforms and processes Documents.
  • A Deployment serves a single Executor, while a Flow serves Executors chained into a pipeline.

The full glossary is explained here.


Jina: Streamline AI & ML Product Delivery

Build AI Services

Open In Colab

Let's build a fast, reliable and scalable gRPC-based AI service. In Jina we call this an Executor. Our simple Executor will use Facebook's mBART-50 model to translate French to English. We'll then use a Deployment to serve it.

Note A Deployment serves just one Executor. To combine multiple Executors into a pipeline and serve that, use a Flow.

Note Run the code in Colab to install all dependencies.

Let's implement the service's logic:

translate_executor.py
from docarray import DocumentArray
from jina import Executor, requests
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM


class Translator(Executor):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.tokenizer = AutoTokenizer.from_pretrained(
            "facebook/mbart-large-50-many-to-many-mmt", src_lang="fr_XX"
        )
        self.model = AutoModelForSeq2SeqLM.from_pretrained(
            "facebook/mbart-large-50-many-to-many-mmt"
        )

    @requests
    def translate(self, docs: DocumentArray, **kwargs):
        for doc in docs:
            doc.text = self._translate(doc.text)

    def _translate(self, text):
        encoded_en = self.tokenizer(text, return_tensors="pt")
        generated_tokens = self.model.generate(
            **encoded_en, forced_bos_token_id=self.tokenizer.lang_code_to_id["en_XX"]
        )
        return self.tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[
            0
        ]

Then we deploy it with either the Python API or YAML:

Python API: deployment.py YAML: deployment.yml
from jina import Deployment
from translate_executor import Translator

with Deployment(uses=Translator, timeout_ready=-1) as dep:
    dep.block()
jtype: Deployment
with:
  uses: Translator
  py_modules:
    - translate_executor.py # name of the module containing Translator
  timeout_ready: -1

And run the YAML Deployment with the CLI: jina deployment --uses deployment.yml

──────────────────────────────────────── 🎉 Deployment is ready to serve! ─────────────────────────────────────────
╭────────────── 🔗 Endpoint ───────────────╮
│  ⛓      Protocol                   GRPC │
│  🏠        Local          0.0.0.0:12345  │
│  🔒      Private      172.28.0.12:12345  │
│  🌍       Public    35.230.97.208:12345  │
╰──────────────────────────────────────────╯

Use Jina Client to make requests to the service:

from docarray import Document
from jina import Client

french_text = Document(
    text='un astronaut est en train de faire une promenade dans un parc'
)

client = Client(port=12345)  # use port from output above
response = client.post(on='/', inputs=[french_text])

print(response[0].text)
an astronaut is walking in a park

Note In a notebook, one cannot use deployment.block() and then make requests to the client. Please refer to the colab link above for reproducible Jupyter Notebook code snippets.

Build a pipeline

Open In Colab

Sometimes you want to chain microservices together into a pipeline. That's where a Flow comes in.

A Flow is a DAG pipeline, composed of a set of steps, It orchestrates a set of Executors and a Gateway to offer an end-to-end service.

Note If you just want to serve a single Executor, you can use a Deployment.

For instance, let's combine our French translation service with a Stable Diffusion image generation service from Jina AI's Executor Hub. Chaining these services together into a Flow will give us a multilingual image generation service.

Build the Flow with either Python or YAML:

Python API: flow.py YAML: flow.yml
from jina import Flow

flow = (
    Flow()
    .add(uses=Translator, timeout_ready=-1)
    .add(
        uses='jinaai://jina-ai/TextToImage',
        timeout_ready=-1,
        install_requirements=True,
    )
)  # use the Executor from Executor hub

with flow:
    flow.block()
jtype: Flow
executors:
  - uses: Translator
    timeout_ready: -1
    py_modules:
      - translate_executor.py
  - uses: jinaai://jina-ai/TextToImage
    timeout_ready: -1
    install_requirements: true

Then run the YAML Flow with the CLI: jina flow --uses flow.yml

─────────────────────────────────────────── 🎉 Flow is ready to serve! ────────────────────────────────────────────
╭────────────── 🔗 Endpoint ───────────────╮
│  ⛓      Protocol                   GRPC  │
│  🏠        Local          0.0.0.0:12345  │
│  🔒      Private      172.28.0.12:12345  │
│  🌍       Public    35.240.201.66:12345  │
╰──────────────────────────────────────────╯

Then, use Jina Client to make requests to the Flow:

from jina import Client, Document

client = Client(port=12345)  # use port from output above

french_text = Document(
    text='un astronaut est en train de faire une promenade dans un parc'
)

response = client.post(on='/', inputs=[french_text])

response[0].display()

stable-diffusion-output.png

You can also deploy a Flow to JCloud.

First, turn the flow.yml file into a JCloud-compatible YAML by specifying resource requirements and using containerized Hub Executors.

Then, use jina cloud deploy command to deploy to the cloud:

wget https://raw.githubusercontent.com/jina-ai/jina/master/.github/getting-started/jcloud-flow.yml
jina cloud deploy jcloud-flow.yml

⚠️ Caution: Make sure to delete/clean up the Flow once you are done with this tutorial to save resources and credits.

Read more about deploying Flows to JCloud.

Check the getting-started project source code.


Jina: No Infrastructure Complexity, High Engineering Efficiency

Why not just use standard Python to build that microservice and pipeline? Jina accelerates time to market of your application by making it more scalable and cloud-native. Jina also handles the infrastructure complexity in production and other Day-2 operations so that you can focus on the data application itself.

Jina: Scalability and concurrency with ease

Easy scalability and concurrency

Jina comes with scalability features out of the box like replicas, shards and dynamic batching. This lets you easily increase your application's throughput.

Let's scale a Stable Diffusion Executor deployment with replicas and dynamic batching:

  • Create two replicas, with a GPU assigned for each.
  • Enable dynamic batching to process incoming parallel requests together with the same model inference.
Normal Deployment Scaled Deployment
jtype: Deployment
with:
  timeout_ready: -1
  uses: jinaai://jina-ai/TextToImage
  install_requirements: true
jtype: Deployment
with:
  timeout_ready: -1
  uses: jinaai://jina-ai/TextToImage
  install_requirements: true
  env:
   CUDA_VISIBLE_DEVICES: RR
  replicas: 2
  uses_dynamic_batching: # configure dynamic batching
    /default:
      preferred_batch_size: 10
      timeout: 200

Assuming your machine has two GPUs, using the scaled deployment YAML will give better throughput compared to the normal deployment.

These features apply to both Deployment YAML and Flow YAML. Thanks to the YAML syntax, you can inject deployment configurations regardless of Executor code.


Jina: Seamless Container Integration

Seamless container integration

Use Executor Hub to share your Executors or use public/private Executors, with no need to worry about dependencies.

To create an Executor:

jina hub new 

To push it to Executor Hub:

jina hub push .

To use a Hub Executor in your Flow:

Docker container Sandbox Source
YAML uses: jinaai+docker://<username>/MyExecutor uses: jinaai+sandbox://<username>/MyExecutor uses: jinaai://<username>/MyExecutor
Python .add(uses='jinaai+docker://<username>/MyExecutor') .add(uses='jinaai+sandbox://<username>/MyExecutor') .add(uses='jinaai://<username>/MyExecutor')

Executor Hub manages everything on the backend:

  • Automated builds on the cloud
  • Store, deploy, and deliver Executors cost-efficiently;
  • Automatically resolve version conflicts and dependencies;
  • Instant delivery of any Executor via Sandbox without pulling anything to local.

Jina: Seamless Container Integration

Get on the fast lane to cloud-native

Using Kubernetes with Jina is easy:

jina export kubernetes flow.yml ./my-k8s
kubectl apply -R -f my-k8s

And so is Docker Compose:

jina export docker-compose flow.yml docker-compose.yml
docker-compose up

Note You can also export Deployment YAML to Kubernetes and Docker Compose.

Likewise, tracing and monitoring with OpenTelemetry is straightforward:

from docarray import DocumentArray
from jina import Executor, requests


class Encoder(Executor):
    @requests
    def encode(self, docs: DocumentArray, **kwargs):
        with self.tracer.start_as_current_span(
            'encode', context=tracing_context
        ) as span:
            with self.monitor(
                'preprocessing_seconds', 'Time preprocessing the requests'
            ):
                docs.tensors = preprocessing(docs)
            with self.monitor(
                'model_inference_seconds', 'Time doing inference the requests'
            ):
                docs.embedding = model_inference(docs.tensors)

You can integrate Jaeger or any other distributed tracing tools to collect and visualize request-level and application level service operation attributes. This helps you analyze request-response lifecycle, application behavior and performance.

To use Grafana, download this JSON and import it into Grafana:

Jina: Seamless Container Integration

To trace requests with Jaeger:

Jina: Seamless Container Integration

What cloud-native technology is still challenging to you? Tell us and we'll handle the complexity and make it easy for you.

Support

Join Us

Jina is backed by Jina AI and licensed under Apache-2.0.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jina-3.15.1.dev158-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jina-3.15.1.dev158-cp311-cp311-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

jina-3.15.1.dev158-cp311-cp311-macosx_10_9_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

jina-3.15.1.dev158-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jina-3.15.1.dev158-cp310-cp310-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

jina-3.15.1.dev158-cp310-cp310-macosx_10_9_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

jina-3.15.1.dev158-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jina-3.15.1.dev158-cp39-cp39-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

jina-3.15.1.dev158-cp39-cp39-macosx_10_9_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

jina-3.15.1.dev158-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jina-3.15.1.dev158-cp38-cp38-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

jina-3.15.1.dev158-cp38-cp38-macosx_10_9_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

jina-3.15.1.dev158-cp37-cp37m-macosx_10_9_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file jina-3.15.1.dev158-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f169295015ccf4bea6405c25daa2dfada19101eddfce2ebbdad81d8ab450a3f8
MD5 6d28929dfdf9a154ec883532547ddbb3
BLAKE2b-256 bb5dbf348876f75b3d3f583bd665f8847f382b0daebd75f19f8ce2e3ced58032

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0884a24da7161e37feb17b81f18d2369a9a8f92178662bf7c917d1130792d709
MD5 fd5305e2fd30319969954d1cd9901bd2
BLAKE2b-256 cdb9c601bc6b6f6fd67d021b55c9246ef1b6f6540a714fbce99b91796ace9589

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8358ff61d8ad3fbeecc6b9cd3b9db877fcccf672e19c8d2ab90e0f7b467da9b9
MD5 ed3ca8bbfef6ffa485ff601b9d2bc8a7
BLAKE2b-256 90b51f1159d5d68d503bbe188d851933beefb0bacf0c3928a60ae8465fdb3a6c

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f432f6be4c54b6410faa822e226412d20ad94f457bbcba614c593e6e23afa52
MD5 03c9772912b310b58d3cd9ef1d1913d9
BLAKE2b-256 ea893c39c3e94110d3e3430247630f430a285dabc6a7f3617ccb80f06f69e177

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e409dbedd3ef2545d822983ed7627f92ab2b07d0977ab173b389146c8c50225
MD5 d9ad9b8793a24bc104f7186d5a49ec72
BLAKE2b-256 6e9e7f8ce01bc426bb3c9bc2ed575c38698c8e6642ec04c3aa59358a61149aac

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 48f53f7012f386fde88a878fb65c9f57e9086e33f9ba77627e8d5406fa9ca828
MD5 5fc5b186a7fb4aabc62a3478f9c2202a
BLAKE2b-256 8ed9a34e85d576baa132fcfdee8ef61fe9bf8a8e5608c2e12d74eeb44d171f03

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d48ef28bc9e0c9686dca96c193ca55601a737cf68af4e74fc20fa6c5e8c25a5
MD5 55e6cb000da4cda822c6359ab2cbdf0d
BLAKE2b-256 8da5a77bcb704c2b4209240763dcfc74885775dcba0ae3c16047c196badb5e4d

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 639831634ae66d91040d81db5c3775c064778668a712d67d190b08d74fa82e8d
MD5 f37bd45558ca4f76a3928af2b029f4a7
BLAKE2b-256 f1c10c538c958d2ea36d4d588c261e216fd161ca66d35f0ed581fbafb5c46dfd

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 653a04c28f3f31d54fe61b4ad2a02690bae8b34b385ff8be8fbc9ba3661bf46e
MD5 28d6e15e90fe71d6bba900c7c9a929fc
BLAKE2b-256 c466d6a7fd7f866f0efc89606ee7ed405bc20dbe1ed75ea51a403b58f53b32b6

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49dd276d55f6e5923b7ec7c2a272e08240fc7e38b1a1a40d81e74d901aba10d6
MD5 5a371eca60169d87c094c053cced23c3
BLAKE2b-256 5e86ca6fc2da2531e0a3dc80a5ab0e6617ad0fe88bf347c821814878541eabe4

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da6e7d03ffe1eb67f538c257ced8bdf5d666aa04756bfad7441831144dc941e4
MD5 75cec73dc3f492a9ec5df4bc03cd19a0
BLAKE2b-256 8e1e837b71f4eda8f295370bde432572c9aab6cbba0895893a9515186fbaacf8

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cbc0494e1a5a9567785234a0e9e4cf20eb71ce1dcca025f486469f6d3152d358
MD5 797dd422a8265acc8c66b9f82747945d
BLAKE2b-256 8c969ad58a31f2129e694b5a9e0475291fef4e2b443dbdd956746e4bd832dc3e

See more details on using hashes here.

File details

Details for the file jina-3.15.1.dev158-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.15.1.dev158-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ad1b07722f35b38c6d105afe1101cabc40e2145ffde4e719ce9504ff0f6e0a86
MD5 5ab484c799a44f43d00c94cf37fcc194
BLAKE2b-256 81df82eb2185b08e5c25babce29047ab2e6ee77053d8f4813b4c7cc1ca186ebb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page