### Installing Jina-serve with pip Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/before-you-start.md This snippet demonstrates the standard command to install Jina-serve using pip, the Python package installer. It is the recommended method for most users to get started with Jina-serve. ```shell pip install jina ``` -------------------------------- ### Standard Install Jina-serve via PyPI Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs the standard version of Jina-serve using pip, enabling all major features. This is the recommended installation for most users. ```shell pip install -U jina ``` -------------------------------- ### Prerelease Install Jina-serve via PyPI Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs the prerelease version of Jina-serve using pip, which is continuously synced with the `master` branch of the GitHub repository, providing the latest features and fixes. ```shell pip install --pre jina ``` -------------------------------- ### Performant Minimum Install Jina-serve via PyPI Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs a performant minimum version of Jina-serve using pip, including `uvloop` and `lz4` for enhanced performance, in addition to the basic features. ```shell JINA_PIP_INSTALL_PERF=1 pip install jina ``` -------------------------------- ### Minimum Install Jina-serve via PyPI Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs a minimum version of Jina-serve using pip, enabling only basic features and excluding support for HTTP, WebSocket, Docker, and Hub. This is suitable for building and deploying Executors. ```shell JINA_PIP_INSTALL_CORE=1 pip install jina ``` -------------------------------- ### Prerelease Install Jina-serve via Docker Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Runs the prerelease version of Jina-serve as a Docker container, directly reflecting the `master` branch of the GitHub repository for the very latest updates. ```shell docker run jinaai/jina:master ``` -------------------------------- ### Full Development Dependencies Install Jina-serve via PyPI Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs Jina-serve with all development dependencies using pip, including tools like Pytest and CI components, useful for contributing to Jina-serve's development. ```shell pip install "jina[devel]" ``` -------------------------------- ### Standard Install Jina-serve via Docker Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Runs the latest standard version of Jina-serve as a Docker container, providing a self-contained environment with all major features. ```shell docker run jinaai/jina:latest ``` -------------------------------- ### Full Development Dependencies Install Jina-serve via Docker Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Runs the development version of Jina-serve as a Docker container, pre-configured with all necessary dependencies for developing Jina-serve itself. ```shell docker run jinaai/jina:latest-devel ``` -------------------------------- ### Performant Minimum Install Jina-serve via Docker Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Runs the performant minimum version of Jina-serve as a Docker container, which includes `uvloop` and `lz4` for enhanced runtime performance. ```shell docker run jinaai/jina:latest-perf ``` -------------------------------- ### Standard Install Jina-serve via Conda Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs the standard version of Jina-serve using Conda from the conda-forge channel, enabling all major features. This is the recommended installation for most users. ```shell conda install jina -c conda-forge ``` -------------------------------- ### Performant Minimum Install Jina-serve via Conda Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs a performant minimum version of Jina-serve using Conda from the conda-forge channel, bundling `uvloop` and `lz4` for improved performance. ```shell conda install jina-perf -c conda-forge ``` -------------------------------- ### Installing Jina-serve and Model Dependencies (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/deploy-model.md This shell command installs the necessary Python packages for the Jina-serve framework and the `diffusers` library, which is required for the Stable Diffusion model used in the Executor. These are fundamental prerequisites for running the example. ```Shell pip install jina pip install diffusers ``` -------------------------------- ### Minimum Install Jina-serve via Docker Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Runs the latest minimum version of Jina-serve as a Docker container, providing basic features without HTTP, WebSocket, Docker, or Hub support. This image is often used in the context of building and deploying Executors. ```shell docker run jinaai/jina:latest ``` -------------------------------- ### Identifying Unnecessary Wheel Builds during Jina-serve Installation Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/troubleshooting.md This snippet shows an example log output indicating that `numpy` wheels are being built from source during Jina-serve installation. This is a sign of an incorrect or inefficient installation, often due to an outdated `pip` version or an unsupported system/architecture. ```text Collecting numpy==2.0.* Downloading numpy-2.0.18.tar.gz (801 kB) |████████████████████████████████| 801 kB 1.1 MB/s Building wheels for collected packages: numpy Building wheel for numpy (setup.py) ... done Created wheel for numpy ... numpy-2.0.18-cp38-cp38-macosx_10_15_x86_64.whl ``` -------------------------------- ### Example Output of Kubernetes Pod Status Source: https://github.com/jina-ai/serve/blob/master/docs/cloud-nativeness/kubernetes.md This snippet provides an example output from the `kubectl get pods` command, confirming that the `encoder` Pod is `Running` and ready to serve requests. It displays the pod's name, readiness status, restarts, and age. ```text NAME READY STATUS RESTARTS AGE encoder-81a5b3cf9-ls2m3 1/1 Running 0 60m ``` -------------------------------- ### Minimum Install Jina-serve via Conda Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Installs a minimum version of Jina-serve using Conda from the conda-forge channel, providing basic features without HTTP, WebSocket, Docker, or Hub support. Ideal for Executor development. ```shell conda install jina-core -c conda-forge ``` -------------------------------- ### Jina CLI Autocomplete Second-Level Commands (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Illustrates the context-aware autocomplete functionality of Jina's CLI, showing suggestions for subcommands under `jina hub` when followed by the Tab key in a Bash shell. ```bash jina hub --help new pull push ``` -------------------------------- ### Jina CLI Autocomplete Top-Level Commands (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install.md Demonstrates the top-level command suggestions provided by Jina's CLI autocomplete feature when `jina` is typed followed by the Tab key in a Bash shell. ```bash jina --help --version --version-full check client flow gateway hello pod ping deployment hub ``` -------------------------------- ### Installing Jina-Serve with pip Source: https://github.com/jina-ai/serve/blob/master/README.md This command installs the Jina-Serve framework using pip, the Python package installer. It is the first step to setting up a development environment for building AI services with Jina. ```bash pip install jina ``` -------------------------------- ### Verifying Jina-serve Installation and System Information (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md This command runs the Jina-serve CLI with verbose and full information flags. It displays the installed Jina-serve version, its dependencies, Python version, platform details, and environment variables, confirming a successful native installation on Apple Silicon. ```bash jina -vf ``` -------------------------------- ### Launching a Jina-serve Deployment (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This command initiates a Jina-serve Deployment using the specified `deployment.yml` configuration file. It starts the server, making the Deployment ready to process requests via gRPC and HTTP protocols. ```shell jina deployment --uses deployment.yml ``` -------------------------------- ### Starting Prometheus and Grafana with Docker Compose (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/cloud-nativeness/monitoring.md Starts the Prometheus and Grafana services defined in the `docker-compose.yaml` within the `example-grafana-prometheus` repository, enabling local metric collection and visualization. ```bash docker-compose up ``` -------------------------------- ### Installing Jina-serve Core Dependencies via Homebrew (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md This command installs essential Jina-serve dependencies, `protobuf` and `numpy`, using Homebrew. These packages are required for Jina-serve's operation and are installed as native wheels for Apple Silicon, ensuring compatibility and performance. ```bash brew install protobuf numpy ``` -------------------------------- ### Installing Jina-serve with Native Pip (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md This command installs Jina-serve using the `pip` executable specifically installed for Apple Silicon Python. It ensures Jina-serve and its dependencies, including `grpcio`, are installed in the native environment, which may take some time due to wheel building. ```bash /opt/homebrew/opt/python@3.10/libexec/bin/pip install jina ``` -------------------------------- ### Installing Raftadmin Binary Locally Source: https://github.com/jina-ai/serve/blob/master/jina/serve/consensus/README.md Installs the `raftadmin` binary locally by cloning its repository into the GOPATH, building it, and then verifying its presence in the Go binary directory. This is necessary due to issues with direct `go install` from the repository. ```shell mkdir -p $GOPATH/src/github.com/Jille cd $GOPATH/src/github.com/Jille git clone github.com/Jille/raftadmin go install cmd/raftadmin/raftadmin.go ls $GOPATH/bin ``` -------------------------------- ### Example Output of Kubernetes Pod Status Source: https://github.com/jina-ai/serve/blob/master/docs/cloud-nativeness/kubernetes.md This text snippet provides an example output from the `kubectl get pods` command, showing the status of the deployed Jina Flow pods. It confirms that the encoder, gateway, and indexer pods are running and ready, indicating a successful deployment. This output helps in verifying the health of the deployed services. ```text NAME READY STATUS RESTARTS AGE encoder-8b5575cb9-bh2x8 1/1 Running 0 60m gateway-66d5f45ff5-4q7sw 1/1 Running 0 60m indexer-8f676fc9d-4fh52 1/1 Running 0 60m ``` -------------------------------- ### Cloning Prometheus/Grafana Example Repository (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/cloud-nativeness/monitoring.md Clones the `example-grafana-prometheus` repository and navigates into the `prometheus-grafana-local` directory, which contains the necessary configuration files for local monitoring. ```bash git clone https://github.com/jina-ai/example-grafana-prometheus cd example-grafana-prometheus/prometheus-grafana-local ``` -------------------------------- ### Launching a Jina-serve Flow (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This command initiates a Jina-serve Flow using the specified `flow.yml` configuration file. It starts the server, making the Flow ready to process requests via gRPC, HTTP, and WebSocket protocols. ```shell jina-serve flow --uses flow.yml ``` -------------------------------- ### Installing Jina AI Cloud CLI Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/jcloud/index.md Instructions for installing the `jcloud` CLI tool independently using pip and verifying the installation by checking its help message. This allows users to manage Jina AI Cloud resources without installing the full Jina-serve package. ```bash pip install jcloud jc -h ``` -------------------------------- ### Installing or Reinstalling Homebrew for Apple Silicon (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md This command executes the official Homebrew installation script. It ensures Homebrew is installed for Apple Silicon, typically to `/opt/homebrew`, providing a native package management environment. Users should back up data before proceeding with reinstallation due to its potentially destructive nature. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Starting Raft Cluster Nodes and Administering Source: https://github.com/jina-ai/serve/blob/master/jina/serve/consensus/README.md Starts individual Raft cluster nodes (A, B, C) using dedicated scripts, each in a new terminal, and then executes an admin script to add these nodes to the cluster. The `--raft_bootstrap` argument is crucial for the initial cluster setup. ```shell scripts/start_nodeA.sh scripts/start_nodeB.sh scripts/start_nodeC.sh scripts/admin_add_nodes.sh ``` -------------------------------- ### Setting Environment Variables for grpcio Build (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md These environment variables are optional and can be set if the `grpcio` installation fails. They instruct the `grpcio` build process to use system OpenSSL and Zlib, potentially resolving compilation issues during the Jina-serve installation. ```bash export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 ``` -------------------------------- ### Installing Go Dependencies Source: https://github.com/jina-ai/serve/blob/master/jina/serve/consensus/README.md Installs all required Go project dependencies. This command should be run in the root directory of the Go project to fetch modules. ```shell go get ``` -------------------------------- ### Example requirements.txt with Environment Variable Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/hub/push-executor.md This `requirements.txt` file demonstrates how to use an environment variable, `${YOUR_TOKEN}`, to securely access a private Git repository for dependency installation. The variable must be wrapped in curly braces. ```text # requirements.txt git+http://${YOUR_TOKEN}@github.com/your_private_repo ``` -------------------------------- ### Installing Jina via PyPI (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/index.md This command installs or upgrades the Jina framework using pip, the Python package installer. It ensures you have the latest version of Jina available for developing AI services and pipelines. ```shell pip install -U jina ``` -------------------------------- ### Installing MPS-enabled PyTorch for Apple Silicon (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md This command installs MPS (Metal Performance Shaders)-enabled PyTorch, torchvision, and torchaudio for Apple Silicon. It uses the native pip and a specific index URL for nightly CPU wheels, leveraging Apple's GPU for accelerated computations in machine learning tasks. ```bash /opt/homebrew/opt/python@3.10/libexec/bin/pip install -U --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu ``` -------------------------------- ### Deploying and Pinging Jina Deployment via CLI Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/readiness.md This snippet demonstrates how to programmatically start a Jina `Deployment` in Python and then use the `jina-serve ping` CLI command to check its health and connectivity. It includes examples of both successful and failed ping attempts, showing the expected console output for each scenario. ```python from jina import Deployment dep = Deployment(port=12345) with dep: dep.block() ``` ```bash jina-serve ping executor grpc://localhost:12345 ``` ```text INFO Jina-serve@92877 ping grpc://localhost:12345 at 0 round... [09/08/22 12:58:13] INFO Jina-serve@92877 ping grpc://localhost:12345 at 0 round takes 0 seconds (0.04s) INFO Jina-serve@92877 ping grpc://localhost:12345 at 1 round... INFO Jina-serve@92877 ping grpc://localhost:12345 at 1 round takes 0 seconds (0.01s) INFO Jina-serve@92877 ping grpc://localhost:12345 at 2 round... INFO Jina-serve@92877 ping grpc://localhost:12345 at 2 round takes 0 seconds (0.01s) INFO Jina-serve@92877 avg. latency: 24 ms ``` ```text INFO Jina-serve@92986 ping grpc://localhost:12345 at 0 round... [09/08/22 12:59:00] ERROR GRPCClient@92986 Error while getting response from grpc server DocList[BaseDoc]: print(docs) f = Flow().add(name='myexec1', uses=MyExecutor) with f: f.post(on='/bar', inputs=BaseDoc(), return_type=DocList[BaseDoc], on_done=print) ``` -------------------------------- ### Minimum Working Example of Jina Deployment (Pythonic) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/deployment.md This example illustrates a complete Jina Deployment in a Pythonic style. It defines a custom `MyExecutor` to handle requests on `/bar`, then creates a `Deployment` using this Executor and sends a `post` request within a context manager. ```Python from jina import Deployment, Executor, requests from docarray import DocList, BaseDoc class MyExecutor(Executor): @requests(on='/bar') def foo(self, docs: DocList[BaseDoc], **kwargs) -> DocList[BaseDoc]: print(docs) dep = Deployment(name='myexec1', uses=MyExecutor) with dep: dep.post(on='/bar', inputs=BaseDoc(), return_type=DocList[BaseDoc], on_done=print) ``` -------------------------------- ### Starting Jina Flow via Jina CLI Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/flow.md Illustrates how to start a Jina Flow from the terminal using the Jina CLI and a Flow YAML configuration file. This method is suitable for command-line deployments and automation. ```bash jina flow --uses flow.yml ``` -------------------------------- ### Installing Python 3 for Apple Silicon via Homebrew (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/apple-silicon-m1-m2.md This command installs Python 3 using Homebrew, ensuring it is compiled for Apple Silicon. As of August 2022, this typically installs Python 3.10 natively, providing a crucial prerequisite for Jina-serve's native operation. ```bash brew install python3 ``` -------------------------------- ### Installing Jina via Conda (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/index.md This command installs the Jina framework using Conda, a cross-platform package and environment management system. It fetches Jina from the `conda-forge` channel, ensuring all necessary dependencies are managed. ```shell conda install jina -c conda-forge ``` -------------------------------- ### Running the Jina AI Deployment Script Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/gpu-executor.md This command executes the Python script `main.py`, which is presumed to contain the Jina AI Deployment configuration and operational logic. It initiates the deployment and starts the processing, allowing for performance measurement. ```Bash python main.py ``` -------------------------------- ### Installing Jina-serve via Pip in Dockerfile Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/gateway/customization.md This Dockerfile instruction provides an alternative method to install Jina-serve within a container. Instead of using a Jina-serve specific base image, this command installs the `jina` package using `pip`, which can be useful if a more generic base image is preferred. ```dockerfile RUN pip install jina ``` -------------------------------- ### Installing Python Dependencies (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/gpu-executor.md This command uses `pip` to install all the Python packages listed in the `requirements.txt` file. It ensures that all necessary libraries, such as `sentence-transformers`, are available for the Executor to run. ```bash pip install -r requirements.txt ``` -------------------------------- ### Connecting to Jina-serve with Python Client (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This command executes the `client.py` script, which serves as the entry point for interacting with a running Jina-serve Deployment or Flow. It demonstrates how to send requests and receive responses from the Jina-serve server. ```bash python client.py ``` -------------------------------- ### Starting Jina Deployment with Python Entrypoint and Context Manager Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/deployment.md This Python snippet illustrates how to start and stop a Jina Deployment using a context manager within the `if __name__ == '__main__'` block. This pattern is crucial for ensuring proper process management, especially when dealing with multiprocessing. ```python from jina import Deployment dep = Deployment() if __name__ == '__main__': with dep: pass ``` -------------------------------- ### Example Jina-serve Gateway Environment Info Output (JSON) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/gateway/index.md This JSON snippet provides an example of the structured output returned by the Jina-serve Gateway's environment information endpoint. It includes details about the Jina package, system architecture, and values of relevant Jina-serve environment variables, useful for diagnostics. ```json { "jina": { "architecture": "######", "ci-vendor": "######", "docarray": "######", "grpcio": "######", "jina": "######", "jina-proto": "######", "jina-vcs-tag": "######", "platform": "######", "platform-release": "######", "platform-version": "######", "processor": "######", "proto-backend": "######", "protobuf": "######", "python": "######", "pyyaml": "######", "session-id": "######", "uid": "######", "uptime": "######" }, "envs": { "JINA_AUTH_TOKEN": "(unset)", "JINA_DEFAULT_HOST": "(unset)", "JINA_DEFAULT_TIMEOUT_CTRL": "(unset)", "JINA_DEPLOYMENT_NAME": "(unset)", "JINA_DISABLE_HEALTHCHECK_LOGS": "(unset)", "JINA_DISABLE_UVLOOP": "(unset)", "JINA_EARLY_STOP": "(unset)", "JINA_FULL_CLI": "(unset)", "JINA_GATEWAY_IMAGE": "(unset)", "JINA_GRPC_RECV_BYTES": "(unset)", "JINA_GRPC_SEND_BYTES": "(unset)", "JINA_HUBBLE_REGISTRY": "(unset)", "JINA_HUB_NO_IMAGE_REBUILD": "(unset)", "JINA_LOCKS_ROOT": "(unset)", "JINA_LOG_CONFIG": "(unset)", "JINA_LOG_LEVEL": "(unset)", "JINA_LOG_NO_COLOR": "(unset)", "JINA_MP_START_METHOD": "(unset)", "JINA_RANDOM_PORT_MAX": "(unset)", "JINA_RANDOM_PORT_MIN": "(unset)" } } ``` -------------------------------- ### Listing Jina AI Serve Flows by Phase in Bash Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/jcloud/index.md This command lists all Jina AI Serve Flows, including those in 'Starting', 'Serving', 'Failed', 'Updating', and 'Paused' phases. It provides an overview of the current state of all deployed flows. ```bash jc flows list ``` -------------------------------- ### Building Local Go Executable Source: https://github.com/jina-ai/serve/blob/master/jina/serve/consensus/README.md Compiles the Go project into a local binary executable. This binary is then used to start the individual Raft nodes for the cluster. ```shell go build ``` -------------------------------- ### Example Output from Jina-Serve Streaming Client Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/add-endpoints.md This snippet shows a sample of the output received by the Python streaming client. It illustrates the incremental `hello world` messages, confirming that the client successfully receives and processes the streamed `MyDocument` objects from the Jina-Serve Executor. ```text hello world 0 hello world 1 hello world 2 ``` -------------------------------- ### Expected Output from Jina-serve Flow Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/preliminaries/index.md This snippet displays the expected output when querying the Jina-serve Flow example. It shows that both `FooExec` and `BarExec` Executors have processed the input, resulting in text appended by both, demonstrating the chained execution of services. ```text ['hello, world!goodbye!', 'hello, world!goodbye!'] ``` -------------------------------- ### Jina Executor Tagging Examples (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/hub/push-executor.md These examples illustrate different tagging behaviors when pushing a Jina Executor. The first command results in only the `latest` tag. The second results in only `v1.0.0`. The third explicitly adds both `v1.0.0` and `latest` tags. ```bash jina hub push . ``` ```bash jina hub push . -t v1.0.0 ``` ```bash jina hub push . -t v1.0.0 -t latest ``` -------------------------------- ### Setting Up Server in Custom Gateway with `setup_server` - Python Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/gateway/customization.md This snippet demonstrates the implementation of the `async def setup_server()` method for a custom Jina Gateway. It shows how to initialize a FastAPI application and configure a `uvicorn.Server` instance, assigning it to `self.server`. This method is responsible for setting up all necessary server resources before the server starts running. ```python from jina import Gateway from fastapi import FastAPI from uvicorn import Server, Config class MyGateway(Gateway): async def setup_server(self): app = FastAPI(title='My Custom Gateway') @app.get(path='/endpoint') def custom_endpoint(): return {'message': 'custom-gateway'} self.server = Server(Config(app, host=self.host, port=self.port)) ``` -------------------------------- ### Serving Logic with Jina-serve Deployment (Python) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/preliminaries/index.md This snippet demonstrates how to serve a simple `FooExec` Executor using a Jina-serve `Deployment`. The `FooExec` appends 'hello, world!' to incoming `TextDoc` objects. The Deployment is configured to listen on port 12345 and run 3 replicas of the Executor, blocking indefinitely to keep the service alive. ```python from jina import Executor, Flow, requests from docarray import DocList from docarray.documents import TextDoc class FooExec(Executor): @requests async def add_text(self, docs: DocList[TextDoc], **kwargs) -> DocList[TextDoc]: for d in docs: d.text += 'hello, world!' dep = Deployment(port=12345, uses=FooExec, replicas=3) with dep: dep.block() ``` -------------------------------- ### Example Output of Jina Client Profiling (Text) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/client/index.md This text snippet provides an example of the output generated by the Jina Client's `profiling()` method. It details the breakdown of roundtrip latency, including client-server network time, server processing time, and individual executor latencies, offering insights into performance bottlenecks. ```text Roundtrip 24ms 100% ├── Client-server network 17ms 71% └── Server 7ms 29% ├── Gateway-executors network 0ms 0% ├── executor0 5ms 71% └── executor1 2ms 29% ``` -------------------------------- ### Creating a Jina-serve Deployment Project (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This command uses the Jina-serve CLI to scaffold a new project folder for a Deployment, which is suitable for serving and scaling a single model or microservice. It sets up the basic file structure and configuration. ```bash jina new hello-jina --type=deployment ``` -------------------------------- ### Jina-serve Deployment Project File Structure (Text) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This snippet illustrates the default file structure generated when creating a new Jina-serve Deployment project. It includes key configuration files (`deployment.yml`, `config.yml`), the Executor code directory (`executor1/`), and the client entrypoint (`client.py`). ```text hello-jina/ |- client.py |- deployment.yml |- executor1/ |- config.yml |- executor.py ``` -------------------------------- ### Serving Jina Executor from Docker Image Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/serve.md This example shows how to deploy a Jina Executor from a pre-built Docker image. This method is useful for deploying containerized Executors, ensuring consistent environments and easier scaling. ```Python from jina import Deployment with Deployment(uses='docker://my-executor-image', port=12345, replicas=2) as dep: docs = dep.post(on='/foo', inputs=DocList[TextDoc](TextDoc()), return_type=DocList[TextDoc]) print(docs.text) ``` -------------------------------- ### Specifying CPU-Only PyTorch in requirements.txt (Text) Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/gpu-executor.md This configuration for `requirements.txt` specifies a CPU-only version of PyTorch (`torch==1.9.0+cpu`) along with `sentence-transformers`. This optimizes for environments where GPU is not available, significantly reducing installation size and Docker container startup times. ```text -f https://download.pytorch.org/whl/torch_stable.html sentence-transformers torch==1.9.0+cpu ``` -------------------------------- ### Listing Jina Deployments using Jina CLI Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/jcloud/index.md This command lists all Jina Deployments that are currently in common operational phases such as 'Starting', 'Serving', 'Failed', 'Updating', and 'Paused'. It provides an overview of active and recently managed deployments. ```bash jc deployment list ``` -------------------------------- ### Manually Starting and Stopping Jina Flow in Python Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/flow.md Provides an example of manually controlling a Jina Flow's lifecycle by explicitly calling `f.start()` to initiate the Flow and `f.close()` to shut it down. This offers fine-grained control over the Flow's state. ```python from jina import Flow f = Flow() f.start() f.close() ``` -------------------------------- ### Importing Jina Modules and Checking Version Source: https://github.com/jina-ai/serve/blob/master/docs/Using_Jina_on_Colab.ipynb Imports essential classes from the Jina library, including Flow, Document, Executor, requests, and DocumentArray. It also prints the installed Jina version to confirm successful setup and compatibility. ```python from jina import Flow, Document, Executor, requests, DocumentArray import jina print(jina.__version__) ``` -------------------------------- ### Jina-serve Deployment Server Output (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This output displays the confirmation and network endpoints after a Jina-serve Deployment has successfully launched. It provides local, private, and public addresses for gRPC and HTTP protocols, along with Swagger UI and Redoc documentation links. ```shell ──── 🎉 Deployment is ready to serve! ──── ╭────────────── 🔗 Endpoint ───────────────╮ │ ⛓ Protocol grpc │ │ 🏠 Local 0.0.0.0:54321 │ │ 🔒 Private xxx.xx.xxx.xxx:54321 │ │ Public xx.xxx.xxx.xxx:54321 │ │ ⛓ Protocol http │ │ 🏠 Local 0.0.0.0:54322 │ │ 🔒 Private xxx.xx.xxx.xxx:54322 │ │ Public xx.xxx.xxx.xxx:54322 │ ╰──────────────────────────────────────────╯ ╭─────────── 💎 HTTP extension ────────────╮ │ 💬 Swagger UI 0.0.0.0:54322/docs │ │ 📚 Redoc 0.0.0.0:54322/redoc │ ╰──────────────────────────────────────────╯ ``` -------------------------------- ### Starting a Dummy Jina Executor (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/health-check.md This command initiates a dummy Jina Executor on a specified port, making it available for subsequent health check demonstrations. It serves as a foundational step for testing gRPC health check capabilities. ```shell jina executor --port 12346 ``` -------------------------------- ### Creating a New Jina AI Cloud Project Structure Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/jcloud/index.md Best practice command for initializing a new Jina AI Cloud project with the correct directory structure using `jc new`. This command sets up a template project, ensuring compatibility and ease of deployment. ```bash jc new ``` -------------------------------- ### Invalid Jina Flow: Type Mismatch Example Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/flow.md This snippet demonstrates a Jina Flow configuration that will fail to start. The issue arises because the `ProcessText` Executor's expected input type does not match the output type provided by the `TextEmbeddingExecutor`, leading to a schema incompatibility error. ```python flow = Flow().add(uses=TextEmbeddingExecutor, name='embed').add(uses=ProcessText, name='process') with flow: flow.block() ``` -------------------------------- ### Querying Jina-serve Services with Client (Python) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/preliminaries/index.md This snippet shows how to interact with a Jina-serve Deployment or Flow using the Jina `Client`. It initializes a client connected to port 12345 and sends an empty `TextDoc` to the root endpoint (`/`), expecting a `DocList[TextDoc]` as a response. The result's text content is then printed. ```python from jina import Client from docarray import DocList from docarray.documents import TextDoc c = Client(port=12345) r = c.post(on='/', inputs=DocList[TextDoc]([TextDoc(text='')]), return_type=DocList[TextDoc]) print([d.text for d in r]) ``` -------------------------------- ### Resolving DocArray Dependency Error during Jina-serve Upgrade Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/install/troubleshooting.md This error message indicates that the `docarray` dependency is not correctly installed after upgrading Jina-serve from version 2.x to 3.x. This typically happens when an existing installation is upgraded instead of installing into a new virtual environment. ```text OSError: `docarray` dependency is not installed correctly, please reinstall with `pip install -U --force-reinstall docarray` ``` -------------------------------- ### Creating a Jina-serve Flow Project (Bash) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This command uses the Jina-serve CLI to scaffold a new project folder for a Flow, which allows connecting multiple Deployments into a processing pipeline. It sets up the basic file structure and configuration for a multi-service application. ```bash jina new hello-jina --type=flow ``` -------------------------------- ### Installing Jina in Colab Source: https://github.com/jina-ai/serve/blob/master/docs/Using_Jina_on_Colab.ipynb Installs the Jina framework using pip within the Google Colab environment. A kernel restart is typically required after installation to apply changes. ```python !pip install jina ``` -------------------------------- ### Jina-serve Flow Project File Structure (Text) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This snippet illustrates the default file structure generated when creating a new Jina-serve Flow project. It includes key configuration files (`flow.yml`, `config.yml`), the Executor code directory (`executor1/`), and the client entrypoint (`client.py`). ```text hello-jina/ |- client.py |- flow.yml |- executor1/ |- config.yml |- executor.py ``` -------------------------------- ### Installing Jina-serve via pip in Dockerfile Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/containerize.md This Dockerfile instruction shows how to install `jina-serve` within the Docker image using `pip`. This method is an alternative to using a Jina-serve base image, allowing for custom installation of Jina as a Python package. ```dockerfile RUN pip install jina ``` -------------------------------- ### Serving Locally Built Jina Documentation (Bash) Source: https://github.com/jina-ai/serve/blob/master/CONTRIBUTING.md After building the documentation, these commands show how to serve the generated website locally using Python's built-in HTTP server. This allows developers to preview changes in a web browser before deployment. ```bash cd _build/dirhtml python -m http.server ``` -------------------------------- ### Starting Jina Flow with Python Context Manager Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/flow.md Demonstrates the general Pythonic way to start and stop a Jina Flow using a context manager. The Flow starts upon entering the `with` block and automatically closes upon exiting it, ensuring proper resource management. ```python from jina import Flow f = Flow() with f: pass ``` -------------------------------- ### Good Commit Message Examples Source: https://github.com/jina-ai/serve/blob/master/CONTRIBUTING.md This snippet provides examples of properly formatted commit messages that follow the 'type(scope?): subject' convention. These examples illustrate how to clearly state the type of change, an optional module scope, and a concise subject, ensuring clarity and consistency in the commit history. ```text fix(indexer): fix wrong sharding number in indexer feat: add remote api ``` -------------------------------- ### Building Jina Documentation Locally (Bash) Source: https://github.com/jina-ai/serve/blob/master/CONTRIBUTING.md This sequence of commands outlines the steps to build the Jina documentation website on a local machine. It involves navigating to the docs directory, installing Python requirements, setting an environment variable, and executing the documentation build script. ```bash cd docs pip install -r requirements.txt export NUM_RELEASES=10 bash makedoc.sh local-only ``` -------------------------------- ### Jina-serve Flow Server Output (Shell) Source: https://github.com/jina-ai/serve/blob/master/docs/get-started/create-app.md This output displays the confirmation and network endpoints after a Jina-serve Flow has successfully launched. It provides local, private, and public addresses for gRPC, HTTP, and WebSocket protocols, along with Swagger UI and Redoc documentation links. ```shell ──── 🎉 Flow is ready to serve! ──── ╭────────────── 🔗 Endpoint ───────────────╮ │ ⛓ Protocol grpc │ │ 🏠 Local 0.0.0.0:54321 │ │ 🔒 Private xxx.xx.xxx.xxx:54321 │ │ Public xx.xxx.xxx.xxx:54321 │ │ ⛓ Protocol http │ │ 🏠 Local 0.0.0.0:54322 │ │ 🔒 Private xxx.xx.xxx.xxx:54322 │ │ Public xx.xxx.xxx.xxx:54322 │ │ ⛓ Protocol websocket │ │ 🏠 Local 0.0.0.0:54323 │ │ 🔒 Private xxx.xx.xxx.xxx:54323 │ │ Public xx.xxx.xxx.xxx:54323 │ ╰──────────────────────────────────────────╯ ╭─────────── 💎 HTTP extension ────────────╮ │ 💬 Swagger UI 0.0.0.0:54322/docs │ │ 📚 Redoc 0.0.0.0:54322/redoc │ ╰──────────────────────────────────────────╯ ``` -------------------------------- ### Jina Project Dependency List Source: https://github.com/jina-ai/serve/blob/master/jina/resources/extra-requirements.txt This snippet lists all external package dependencies for the Jina project, categorized by tags such as 'core', 'perf', 'standard', 'devel', 'test', and 'cicd'. Each line specifies a package, its version constraints, and the tags it belongs to. 'core' dependencies are installed by default, while others require explicit tag-based installation using `pip install "jina[tag]"`. ```Dependency Configuration numpy: core protobuf>=3.19.0: core grpcio>=1.46.0,<=1.68.0: core grpcio-reflection>=1.46.0,<=1.68.0: core grpcio-health-checking>=1.46.0,<=1.68.0: core pyyaml>=5.3.1: core packaging>=20.0: core docarray>=0.16.4: core jina-hubble-sdk>=0.30.4: core jcloud>=0.0.35: core opentelemetry-api>=1.12.0: core opentelemetry-instrumentation-grpc>=0.35b0: core uvloop: perf,standard,devel prometheus_client>=0.12.0: perf,standard,devel opentelemetry-sdk>=1.14.0: perf,standard,devel opentelemetry-exporter-otlp>=1.12.0: perf,standard,devel opentelemetry-exporter-prometheus>=0.33b0: perf,standard,devel opentelemetry-instrumentation-aiohttp-client>=0.33b0: perf,standard,devel opentelemetry-instrumentation-fastapi>=0.33b0: perf,standard,devel opentelemetry-exporter-otlp-proto-grpc>=1.13.0: perf,standrad,devel fastapi>=0.76.0: standard,devel uvicorn<=0.23.1: standard,devel docker: standard,devel pathspec: standard,devel filelock: standard,devel requests: standard,devel websockets: standard,devel pydantic<3.0.0: core python-multipart: standard,devel aiofiles: standard,devel aiohttp: standard,devel scipy>=1.6.1: test Pillow: test pytest<8.0.0: test pytest-timeout: test pytest-mock: test pytest-cov==3.0.0: test coverage==6.2: test pytest-repeat: test pytest-asyncio<0.23.0: test pytest-reraise: test flaky: test mock: test requests-mock: test pytest-custom_exit_code: test black==24.3.0: test kubernetes>=18.20.0,<31.0.0: test pytest-kind==22.11.1: test pytest-lazy-fixture: test torch: cicd psutil: test strawberry-graphql>=0.96.0: cicd,devel sgqlc: cicd,devel bs4: cicd jsonschema: cicd portforward>=0.2.4,<0.4.3: cicd tensorflow>=2.0: cicd opentelemetry-test-utils>=0.33b0: test prometheus-api-client>=0.5.1: test watchfiles>=0.18.0: devel urllib3>=1.25.9,<2.0.0: core ``` -------------------------------- ### Installing Jina in Python Virtual Environment Source: https://github.com/jina-ai/serve/blob/master/jina/serve/consensus/README.md Installs the Jina library along with its development dependencies into the active pipenv virtual environment. This ensures the project has access to all necessary Jina components. ```shell pipenv install ".[devel]" ``` -------------------------------- ### Deploying Executor with CPU (Python) Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/gpu-executor.md This Python code demonstrates how to deploy the 'MyGPUExec' using Jina's Deployment, explicitly configuring it to use the CPU. It initializes a 'DocList', sends it to the deployed Executor for encoding via a POST request, and then prints the resulting document embedding and text, confirming CPU usage. ```python from typing import Optional from docarray import DocList, BaseDoc from docarray.typing import AnyTensor from jina import Deployment dep = Deployment(uses=MyGPUExec, uses_with={'device': 'cpu'}) docs = DocList[MyDoc]([MyDoc()]) with dep: docs = dep.post(on='/encode', inputs=docs, return_type=DocList[MyDoc]) print(f'Document embedding: {docs.embedding}') print(docs.text) ``` -------------------------------- ### Installing Python Dependencies in Dockerfile Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/gateway/customization.md This Dockerfile instruction installs any additional Python dependencies required by the custom Gateway. It reads packages from a `requirements.txt` file, ensuring all necessary libraries are available in the containerized environment. ```dockerfile RUN pip install -r requirements.txt ``` -------------------------------- ### Installing pyngrok for Remote Access Source: https://github.com/jina-ai/serve/blob/master/docs/Using_Jina_on_Colab.ipynb Installs the `pyngrok` library, which serves as a Python wrapper for ngrok. This enables the exposure of local services running in Colab to the public internet for remote access. ```python !pip install pyngrok ``` -------------------------------- ### Deploying and Using SentenceEncoder Executor (Python) Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/gpu-executor.md This Python script demonstrates how to deploy and use the `SentenceEncoder` Executor. It creates a `Deployment` instance, generates 10,000 sample documents, and then sends them to the deployed Executor for encoding, showcasing the `post` method with progress tracking. ```python from typing import Optional from jina import Deployment from docarray import DocList, BaseDoc from docarray.typing import AnyTensor from executor import SentenceEncoder class MyDoc(BaseDoc): text: str = '' embedding: Optional[AnyTensor[5]] = None def generate_docs(): for _ in range(10_000): yield MyDoc( text='Using a GPU allows you to significantly speed up encoding.' ) dep = Deployment(uses=SentenceEncoder, uses_with={'device': 'cpu'}) with dep: dep.post(on='/encode', inputs=generate_docs, show_progress=True, request_size=32, return_type=DocList[MyDoc]) ``` -------------------------------- ### Understanding Jina Executor Project File Structure (Text) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/hub/create-hub-executor.md This snippet displays the typical file and directory layout for a newly generated Jina Executor project. It highlights key files like `executor.py` for main logic, `config.yml` for configuration, `requirements.txt` for dependencies, and `README.md` for usage instructions, with `Dockerfile` being optional. ```text MyExecutor/ ├── executor.py ├── config.yml ├── README.md ├── requirements.txt └── Dockerfile ``` -------------------------------- ### Starting Jina Executor Flows Source: https://github.com/jina-ai/serve/blob/master/jina/serve/consensus/README.md Starts three separate Jina executor flows, `nodeA`, `nodeB`, and `nodeC`, each intended to run in a separate terminal. These scripts initialize the individual nodes of the distributed system. ```shell scripts/start_executor.sh nodeA scripts/start_executor.sh nodeB scripts/start_executor.sh nodeC ``` -------------------------------- ### Installing Latest Final Jina Release (PyPi) Source: https://github.com/jina-ai/serve/blob/master/RELEASE.md This command installs or upgrades Jina to its latest stable (final) release from PyPi. It ensures you have the most recent production-ready version of the core Jina library, suitable for general use. ```bash pip install -U jina ``` -------------------------------- ### Initializing Jina Deployment for Readiness Check - Python Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/orchestration/readiness.md This snippet demonstrates how to initialize a Jina `Deployment` instance, configure its protocol (e.g., gRPC) and port, and then block it to start serving. It also sets the Jina log level to DEBUG to observe the process ID (PID) and connection details. ```python from jina import Deployment import os PROTOCOL = 'grpc' # it could also be http or websocket os.environ[ 'JINA_LOG_LEVEL' ] = 'DEBUG' # this way we can check what is the PID of the Executor dep = Deployment(protocol=PROTOCOL, port=12345) with dep: dep.block() ``` ```text ⠋ Waiting ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0/0 -:--:--DEBUG gateway/rep-0@19075 adding connection for deployment executor0/heads/0 to grpc://0.0.0.0:12346 [05/31/22 18:10:16] DEBUG executor0/rep-0@19074 start listening on 0.0.0.0:12346 [05/31/22 18:10:16] DEBUG gateway/rep-0@19075 start server bound to 0.0.0.0:12345 [05/31/22 18:10:17] DEBUG executor0/rep-0@19059 ready and listening [05/31/22 18:10:17] DEBUG gateway/rep-0@19059 ready and listening [05/31/22 18:10:17] ╭─── 🎉 Deployment is ready to serve! ───╮ │ 🔗 Protocol GRPC │ │ 🏠 Local 0.0.0.0:12345 │ │ 🔒 Private 192.168.1.13:12345 │ ╰────────────────────────────────────────╯ DEBUG Deployment@19059 2 Deployments (i.e. 2 Pods) are running in this Deployment ``` -------------------------------- ### Starting Jina Flow with HTTP Protocol Source: https://github.com/jina-ai/serve/blob/master/docs/Using_Jina_on_Colab.ipynb Initializes and starts a Jina Flow configured to use the HTTP protocol on a specified port (54321). The `GPUExec` is added to this Flow, making it accessible for HTTP requests. ```python f = Flow(protocol='http', port=54321).add(uses=GPUExec) f.start() ``` -------------------------------- ### Initializing Jina Executor with CLI Source: https://github.com/jina-ai/serve/blob/master/docs/tutorials/gpu-executor.md This command initiates the creation of a new Jina Executor project. It prompts the user for the Executor's name (e.g., `SentenceEncoder`) and configuration options, including whether to enable advanced configuration and create a `Dockerfile`. ```bash jina hub new ``` -------------------------------- ### Executor Python Dependencies (requirements.txt) Source: https://github.com/jina-ai/serve/blob/master/docs/concepts/serving/executor/containerize.md This `requirements.txt` file lists the Python package dependencies for the `ContainerizedEncoder` Executor, specifically `torch`. This file is used by `pip install -r` within the Dockerfile to ensure all necessary libraries are installed in the container. ```text torch ```