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 services and pipelines then serve, scale and deploy them to a production-ready environment like Kubernetes or Jina AI Cloud. Jina 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 in Jina AI neural search ecosystem

Documentation

Install

pip install jina

Find more install options on Apple Silicon/Windows.

Get Started

Basic Concepts

Jina has three 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

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.14.2.dev1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.7 MB view details)

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

jina-3.14.2.dev1-cp311-cp311-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

jina-3.14.2.dev1-cp311-cp311-macosx_10_9_x86_64.whl (15.7 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

jina-3.14.2.dev1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.7 MB view details)

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

jina-3.14.2.dev1-cp310-cp310-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

jina-3.14.2.dev1-cp310-cp310-macosx_10_9_x86_64.whl (15.7 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

jina-3.14.2.dev1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.7 MB view details)

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

jina-3.14.2.dev1-cp39-cp39-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

jina-3.14.2.dev1-cp39-cp39-macosx_10_9_x86_64.whl (15.7 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

jina-3.14.2.dev1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.7 MB view details)

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

jina-3.14.2.dev1-cp38-cp38-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

jina-3.14.2.dev1-cp38-cp38-macosx_10_9_x86_64.whl (15.7 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

jina-3.14.2.dev1-cp37-cp37m-macosx_10_9_x86_64.whl (15.7 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file jina-3.14.2.dev1-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.14.2.dev1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b997290fa2a5fa9bc7d99d6c5f814952ab9ac382370058cb40aac7c52e7e0e63
MD5 f78591400172231e6746ebc674179967
BLAKE2b-256 438d282c10c56238cb4226987075cea0bd149be386a6a98b8e2d1b89aca1ba0f

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ce1920fd232bb6a754bfbd865f71bd9546b077cad6422d21e7506b5ae0ea1ab
MD5 89e6a42653b4929dc2d578ca239ed2d1
BLAKE2b-256 dcb7f44dc93180c06a9150a78428aaca68682a083350bf980654c11d1bfe1a00

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 35d45c01941fa78f3b0a6fc5f89c33f297adab2e61674579438145e7f0edb024
MD5 5238bcbc7a2aac6df21273dacb7a8921
BLAKE2b-256 f0fd0524001d449a18161f2fea55d82de0b6e1f1e091356753686548b8b8677e

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-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.14.2.dev1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9431f091f8cf6034a3c9bcb54f0f1e0ff7d83076d886f0b0e408ee4daefb343a
MD5 e8e6c0bd30fa181afe0e6e7ec53b79e8
BLAKE2b-256 6f38be6f10740862e1363b3be2a448ccf2b76736b2ac202918a87a48bb187cf3

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5118b91ee83e4d1beba0c2b4d35a0b35d3655c79648592a8605722441be0d1bf
MD5 f6c369210056e9903f1750495a46bbdd
BLAKE2b-256 6d6edec920af6221382cbd272842c39505e539a47bb773b0c3e4e0f6784af204

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0c2bf6a4960129fb54e8e1d758e3654e5bc8950c0b2368e1e6937d7ce269dd49
MD5 f048edd5bc118625020c3069b60a8470
BLAKE2b-256 c39ce2b9c2d64ec69da2f434a1ccd3b396a677b4fbfc12096aaf81900d92738c

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-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.14.2.dev1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94bf17dc89f7642f140773445120c168be69aa7d034e21698825d8a30cd89821
MD5 642cf65d8ece63a745145493e8b7d867
BLAKE2b-256 178258f3f25d0cba5b1bb70b49e0ef54f002c392d157345dffc96d659acc353d

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 11a40ef167a2e726917d4e1732bb7b9fe580a3604bb126247e7782788b8243e6
MD5 7f04cb1e895f14fff50fe7f9d74bffb4
BLAKE2b-256 cb4e1d8d619cc6c966462034e76c42b8c79f41e7a57ddf719349b1ebf2674a66

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e1fffb6e0d7403d9d16a92bcf6e0fc2b85d02aefa13856ad405c6f670d91a36a
MD5 b91c852388008917c1556a7c70c34d18
BLAKE2b-256 1e5c7fef4e3a3a3a9ff87ba660bcbc522f2d5cd754550a9305da4ed2db02a1dd

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-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.14.2.dev1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2778121b08542a299de66979bf9a39b540d8e12c9a7e51f5b766b0899bbeadff
MD5 38167e21aa511802572b860a7af1ad50
BLAKE2b-256 8318a6b287f129d2f4ac876c4f660c7fe8e1ad93809ea14409fc111690e503bd

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4dd7c8344ca689f2681e732e8b8a4833dc75de14eda2ea75f0026596aa2ef50
MD5 70cfcd21a66f3479d7259dcecdabc9df
BLAKE2b-256 f97d5cf30cad1fd87349bb4225c4a61ee9f389e930a7400096ba89ea9e7325c3

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 46e6a517919cf0da09c009e88aa2ae28f0329a3148706197091650d6d0d98e40
MD5 8a8426ca1db5219a9cab3496c1ffed2d
BLAKE2b-256 d91ddef954257df40dd3e81cd35b82597f0e4325888b258d794088e046bf092f

See more details on using hashes here.

File details

Details for the file jina-3.14.2.dev1-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jina-3.14.2.dev1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 23e690ed4584bd801658517dbc58c3b7d0a002139f21a2f9c8fa6ef0ae83b526
MD5 34e881645c975b1c66ae0728146b3f91
BLAKE2b-256 c103a75e034995b5f00accbcfbadb42493e593c648f34f758f19e727e134e7fb

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