Skip to main content

Multimodal AI services & pipelines with cloud-native stack: gRPC, Kubernetes, Docker, OpenTelemetry, Prometheus, Jaeger, etc.

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 PyPI - Downloads from official pypistats Github CD status

Jina lets you build multimodal AI services and pipelines that communicate via gRPC, HTTP and WebSockets, then scale them up and deploy to production. You can focus on your logic and algorithms, without worrying about the infrastructure complexity.

Jina provides a smooth Pythonic experience transitioning from local deployment to advanced orchestration frameworks like Docker-Compose, Kubernetes, or Jina AI Cloud. Jina makes advanced solution engineering and cloud-native technologies accessible to every developer.

  • Build applications for any data type, any mainstream deep learning framework, and any protocol.
  • Design high-performance microservices, with easy scaling, duplex client-server streaming, and async/non-blocking data processing over dynamic flows.
  • Docker container integration via Executor Hub, OpenTelemetry/Prometheus observability, and fast Kubernetes/Docker-Compose deployment.
  • CPU/GPU hosting via Jina AI Cloud.
Wait, how is Jina different from FastAPI? 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.

Documentation

Install

pip install jina

Find more install options on Apple Silicon/Windows.

Get Started

Basic Concepts

Jina has three fundamental layers:

  • Data layer: BaseDoc and DocList (from DocArray) is the input/output format in Jina.
  • Serving layer: An Executor is a Python class that transforms and processes Documents. Gateway is the service making sure connecting all Executors inside a Flow.
  • Orchestration layer: Deployment serves a single Executor, while a Flow serves Executors chained into a pipeline.

The full glossary is explained here.

Build AI Services

Let's build a fast, reliable and scalable gRPC-based AI service. In Jina we call this an Executor. Our simple Executor will wrap the StableLM LLM from Stability AI. 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.

Let's implement the service's logic:

executor.py
from jina import Executor, requests
from docarray import DocList, BaseDoc

from transformers import pipeline


class Prompt(BaseDoc):
    text: str


class Generation(BaseDoc):
    prompt: str
    text: str


class StableLM(Executor):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.generator = pipeline(
            'text-generation', model='stabilityai/stablelm-base-alpha-3b'
        )

    @requests
    def generate(self, docs: DocList[Prompt], **kwargs) -> DocList[Generation]:
        generations = DocList[Generation]()
        prompts = docs.text
        llm_outputs = self.generator(prompts)
        for prompt, output in zip(prompts, llm_outputs):
            generations.append(Generation(prompt=prompt, text=output))
        return generations

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

Python API: deployment.py YAML: deployment.yml
from jina import Deployment
from executor import StableLM

dep = Deployment(uses=StableLM, timeout_ready=-1, port=12345)

with dep:
    dep.block()
jtype: Deployment
with:
  uses: StableLM
  py_modules:
    - executor.py
  timeout_ready: -1
  port: 12345

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

Use Jina Client to make requests to the service:

from jina import Client
from docarray import DocList, BaseDoc


class Prompt(BaseDoc):
    text: str


class Generation(BaseDoc):
    prompt: str
    text: str


prompt = Prompt(
    text='suggest an interesting image generation prompt for a mona lisa variant'
)

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

print(response[0].text)
a steampunk version of the Mona Lisa, incorporating mechanical gears, brass elements, and Victorian era clothing details

Note In a notebook, you can't 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

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 StableLM language model with a Stable Diffusion image generation service. Chaining these services together into a Flow will give us a service that will generate images based on a prompt generated by the LLM.

text_to_image.py
import numpy as np
from jina import Executor, requests
from docarray import BaseDoc, DocList
from docarray.documents import ImageDoc


class Generation(BaseDoc):
    prompt: str
    text: str


class TextToImage(Executor):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        from diffusers import StableDiffusionPipeline
        import torch

        self.pipe = StableDiffusionPipeline.from_pretrained(
            "CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16
        ).to("cuda")

    @requests
    def generate_image(self, docs: DocList[Generation], **kwargs) -> DocList[ImageDoc]:
        images = self.pipe(
            docs.text
        ).images  # image here is in [PIL format](https://pillow.readthedocs.io/en/stable/)
        docs.tensor = np.array(images)

Build the Flow with either Python or YAML:

Python API: flow.py YAML: flow.yml
from jina import Flow
from executor import StableLM
from text_to_image import TextToImage

flow = (
    Flow(port=12345)
    .add(uses=StableLM, timeout_ready=-1)
    .add(uses=TextToImage, timeout_ready=-1)
)

with flow:
    flow.block()
jtype: Flow
with:
    port: 12345
executors:
  - uses: StableLM
    timeout_ready: -1
    py_modules:
      - executor.py
  - uses: TextToImage
    timeout_ready: -1
    py_modules:
      - text_to_image.py

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

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

from jina import Client
from docarray import DocList, BaseDoc
from docarray.documents import ImageDoc


class Prompt(BaseDoc):
    text: str


prompt = Prompt(
    text='suggest an interesting image generation prompt for a mona lisa variant'
)

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

response[0].display()

Easy scalability and concurrency

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.

Increase your application's throughput with scalability features out of the box, like replicas, shards and dynamic batching.

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:
  uses: TextToImage
  timeout_ready: -1
  py_modules:
    - text_to_image.py
jtype: Deployment
with:
  uses: TextToImage
  timeout_ready: -1
  py_modules:
    - text_to_image.py
  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.

Deploy to the cloud

Containerize your Executor

In order to deploy your solutions to the cloud, you need to containerize your services. Jina provides the Executor Hub, the perfect tool to streamline this process taking a lot of the troubles with you. It also lets you share these Executors publicly or privately.

You just need to structure your Executor in a folder:

TextToImage/
├── executor.py
├── config.yml
├── requirements.txt
config.yml requirements.txt
jtype: TextToImage
py_modules:
  - executor.py
metas:
  name: TextToImage
  description: Text to Image generation Executor based on StableDiffusion
  url:
  keywords: []
diffusers
accelerate
transformers

Then push the Executor to the Hub by doing: jina hub push TextToImage.

This will give you a URL that you can use in your Deployment and Flow to use the pushed Executors containers.

jtype: Flow
with:
    port: 12345
executors:
  - uses: jinai+docker://<user-id>/StableLM
  - uses: jinai+docker://<user-id>/TextToImage

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.

That's not all. We also support OpenTelemetry, Prometheus, and Jaeger.

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

Deploy to JCloud

You can also deploy a Flow to JCloud, where you can easily enjoy autoscaling, monitoring and more with a single command.

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

Warning

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.

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 Distribution

jina-3.19.1.tar.gz (357.2 kB view details)

Uploaded Source

Built Distributions

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

jina-3.19.1-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.19.1-cp311-cp311-macosx_11_0_arm64.whl (8.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

jina-3.19.1-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.19.1-cp310-cp310-macosx_11_0_arm64.whl (8.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

jina-3.19.1-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.19.1-cp39-cp39-macosx_11_0_arm64.whl (8.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.9macOS 10.9+ x86-64

jina-3.19.1-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.19.1-cp38-cp38-macosx_11_0_arm64.whl (8.2 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

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

Uploaded CPython 3.8macOS 10.9+ x86-64

jina-3.19.1-cp37-cp37m-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.7mmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file jina-3.19.1.tar.gz.

File metadata

  • Download URL: jina-3.19.1.tar.gz
  • Upload date:
  • Size: 357.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for jina-3.19.1.tar.gz
Algorithm Hash digest
SHA256 8003ff7c45050ae39c3d791e891028fac25136ab89cd3f0b3257ba9beccee2dc
MD5 631d7b9f036d1caa4b63840da5fa5999
BLAKE2b-256 a2bd3b5cba2405befbc2077c52d68a931f8b54cee47ea44adbec7d40aabbe03a

See more details on using hashes here.

File details

Details for the file jina-3.19.1-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.19.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5063783a2aabfeaf0463934af527c2c8609a039cfd9c763f5365226dddf4d47
MD5 8ac9b85a71b6c8bbc3462e7b0117436a
BLAKE2b-256 1715286fc7d7d2bd92924800545dcb8587131b4cef4624e1cdb9c14036114a57

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8defb73535a0c7ae78a499debf1391dcf5cf5ea7676e7b89311a13ec6e538e59
MD5 c0a32eb83d378eee5324a9ccf6c5527f
BLAKE2b-256 1462c701cbeeef0d38a0b1e78e3a9ad33cced463ca824aed07ab5d103c1caa88

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9be05951f46e105ca1ecf769685a062f57592a6354289cede70f8fbc90e7e257
MD5 a7a554fa645e9eb1b12819097ac9558d
BLAKE2b-256 24f183e4f34bd9890d0d195b34c0266ac56167494bf6e114ba2b2beb298416e4

See more details on using hashes here.

File details

Details for the file jina-3.19.1-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.19.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11bc1638985b2830261a908c52fdff4c364636193595477de55ae6162df05cf7
MD5 eee5221423ac6fdf8b05525fb51bc18c
BLAKE2b-256 39d76616ce0485c8d612db8aa90ce73ccf5b27795377272b175b7d99cec03556

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97c238c44819ad3e9aa0c0c79a8e062475c019f8c2cc5241b57c9850c44ccea4
MD5 d3e558ff5a87e6999439a408c3fb2175
BLAKE2b-256 334d86e1ef6065f3c045431d128f3d72443515d1e2e0c8d67d2604e37b55cc6a

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f522d7986d4e1bff9c4b665c8492a416a81787b8ac26603823f3c4d68b336730
MD5 671816e64d619ac98d6b8dc2c927c6a9
BLAKE2b-256 00a4310deba48df734a8dd00c340b6530bfa8ef8deb87e3ecb8ccd522628eb81

See more details on using hashes here.

File details

Details for the file jina-3.19.1-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.19.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca23425ee359aa89de4f5362239b7dd86668e6882a251db26a33979f9f2e2417
MD5 0f846d378170904e110e36fd01cc80b5
BLAKE2b-256 e334128b3cc172d68423525b8277fd971d986e65a9d2618973a28fb44ff74442

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f3b58ad1c3f29dee46f253db45e80f6976e8d8b50ebf35eaf32fdb906f2594ef
MD5 3562b55d385d2df068acb1e27c85e43a
BLAKE2b-256 ab0c1930dec5d0308f198ab75afc222f18e58f49f791e2dcadad9c5001748dfa

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 60c28265fe84ae2c35ece104c9fd657c0cf53de7b9dfca9acc7d339c6a1a4708
MD5 59838965cbb9e4d7a97cb5546a29ceba
BLAKE2b-256 56162e6af63734f9971f7b908bbed1787ffd016cf082bf423a33a6289b43a8a9

See more details on using hashes here.

File details

Details for the file jina-3.19.1-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.19.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3b2a7738bc247fe917ab2be379de6cc7a26688bdc3ff0984430031e59a2f3222
MD5 d17f0b6847c00dcb3e770de9e40c4a91
BLAKE2b-256 ec52287a0b90de10019fc6428b31119421fd1431029efedfa1aa57a6a06b75d6

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c1886250a3d67b2448fee558842f7e1c91f33cbc67e369aed58587eb009cac5
MD5 dfb9edd641beffa29812e3cc228070f5
BLAKE2b-256 bc460de2293cfa8ef93195377f91c2a65f93b9e2b5ff955f096913d9f5df43e4

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.19.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 53521bf9edf2cefb8ca532c81b0e83d3a2addd277610edca1f63bd8e59489883
MD5 e3d439e653ebd45ddaf86f4cfc013f17
BLAKE2b-256 4451306ad86dd22eca341c26286e7870fed3318d5a23680eb166b91ca548e43f

See more details on using hashes here.

File details

Details for the file jina-3.19.1-cp37-cp37m-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.19.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f108cf6cc6f01b0b99c1f87ea404c4b17d4b8bb1d320ef552bdf43e0d33a178
MD5 72381955fadc2f32357ba03e2c81ea4c
BLAKE2b-256 7046abbcfdf35429da2234477923c4b95364958a2e0177b7d2a92a6b80e0f8df

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