Jina-Serve

repository·master·Indexed 12 days ago

https://github.com/jina-ai/serve

A framework for building, scaling, and deploying AI services. It supports high-performance communication via gRPC, HTTP, and WebSockets, and is optimized for ML data types using DocArray. The framework consists of three layers: Data (BaseDoc and DocList), Serving (Executors and Gateways), and Orchestration (Deployments and Flows).

Tokens
102.5K
Snippets
340
Records
433
Agent score
98%

What's inside Jina-Serve

  1. Manage Jina AI resources via Jina AI Cloud

    master

    Jina AI Cloud serves as the central portal and single entrypoint for managing your entire Jina AI ecosystem. You can perform CRUD (Create, Read, Update, Delete) operations, manage access control, handle personal access tokens, and manage subscriptions for the following resources:

    • Data: Includes docarray stores and Finetuner artifacts.
    • Executors: The individual units of computation in your services.
    • Flows: The orchestrated pipelines that connect Executors.
    • Apps: Managed via the Jina Apps platform.
  2. What is a Jina Executor?

    master

    An jina.Executor is a self-contained microservice exposed via gRPC or HTTP. It is a Python class that processes Documents (using docarray.BaseDoc and docarray.DocList as data structures).

    Key principles:

    1. Subclassing: Always subclass directly from jina.Executor.
    2. Methods: An Executor can contain any number of functions.
    3. Endpoints: Functions decorated with @requests are exposed as services. These can be regular functions or coroutines (async def) and can handle single Documents or batches.
    4. State (Beta): Functions decorated with @write (placed above the @requests decoration) are considered to update the Executor's internal state.
  3. What is a Jina Flow?

    master

    A jina.Flow is an orchestration layer that connects multiple jina.Executors into a processing pipeline. Documents flow through this pipeline to be processed by the Executors.

    Key characteristics:

    • Orchestration: It acts as an interface to configure and launch a microservice architecture.
    • Gateway: Every Flow automatically launches a Gateway service, which exposes the underlying services through an API (HTTP, gRPC, or WebSockets).
    • Scalability: Flows allow you to scale individual Executors independently.
    • Composition: A Flow is essentially a set of Deployments.
  4. What is a Deployment and why use it?

    master

    A jina.Deployment is an orchestration component that manages a single jina.Executor (or a set of replicated Executors) to accomplish a task. While Executors do the heavy lifting of processing Documents, the Deployment acts as the interface to configure and launch your microservice architecture.

    Key benefits:

    • Scaling: Deployments allow you to scale Executors independently based on your requirements.
    • Orchestration: They enable easy integration with cloud-native orchestrators like Kubernetes to manage your services.
  5. What is a Gateway in Jina-serve

    master
    A jina.Flow includes a Gateway component that acts as the entry point for all client requests. It is responsible for receiving requests over the network, routing them to the appropriate parts of the Flow, and handling responses back to the client. The Gateway supports multiple protocols including gRPC, HTTP, WebSocket, and GraphQL. While it is automatically configured upon Flow initialization, you can explicitly customize it using Flow.config_gateway() in Python or via a YAML configuration.
  6. What is Executor Hub

    master

    Executor Hub is a service that allows you to containerize, reuse, and share jina.Executor instances. It functions similarly to a Docker registry, enabling you to:

    • Pull prebuilt Executors: Use existing services to reduce development complexity.
    • Push custom Executors: Share your own Executors privately or publicly.
    • Streamline containerization: Turn your jina.Executor into a ready-for-the-cloud containerized service automatically.
  7. What is Dynamic Batching and when to use it

    master

    Dynamic batching allows Jina to accumulate incoming requests and group them into a single batch before sending them to a jina.Executor.

    This is primarily used for inference tasks where model inference is more efficient when processed in batches (e.g., utilizing GPU resources).

    How it works: Incoming requests with the same request parameters are queued together. The batch is dispatched to the Executor when either:

    1. The number of accumulated Documents reaches the preferred_batch_size.
    2. The timeout duration is exceeded.

    Note: While it can work with parametrized requests, it is best suited for endpoints that receive consistent parameters.

  8. Understand the telemetry data collected

    master

    Jina-serve collects specific metadata to understand usage patterns and improve features. The collected data includes:

    • Versions of jina-serve and its dependencies;
    • A hashed unique user identifier (uid);
    • A hashed unique session identifier (session-id);
    • Boolean events marking the start of components like a Flow, Gateway, Runtime, or Client.
  9. How DocArray versioning affects Jina-serve

    master

    Jina-serve automatically detects the installed version of DocArray and adapts its internal methods and APIs accordingly. However, developers must write their Executors and Clients differently depending on whether they are using docarray < 0.30 or docarray >= 0.30.

    • DocArray < 0.30: Uses a fixed Document schema. The user must adapt their data to this predefined schema.
    • DocArray >= 0.30: Uses a flexible schema built on top of Pydantic. Users define their own schemas by subclassing BaseDoc, allowing the data to adapt to the user's needs rather than forcing a specific structure.
  10. Understand Executor details and API documentation in the Hub

    master

    The Executor Hub Detail Page provides comprehensive information about a specific jina.Executor. The information is organized into several tabs to help you integrate the Executor into your pipelines:

    • Readme: Provides a high-level overview, internal workings, and basic usage instructions.
    • Arguments: Displays the Executor's detailed API. This is automatically generated from the Executor's Python docstrings, ensuring the documentation stays in sync with the actual code.
    • Tags: Lists available versions or variants (e.g., latest, latest-gpu) and provides code snippets to illustrate how to use those specific tags.
    • Dependencies: Lists the Python dependencies required to run the Executor.

    Additionally, the sidebar on the detail page provides specific deployment methods, such as Docker images or source code, to help you implement the Executor in your environment.