Jina “Hello, World!” 👋🌍

Note

This guide expects you have a basic understanding of Jina, if you haven’t, please check out Jina 101 first.

Run the example

There are 2 ways to run this example:

  • With Docker

  • With Jina installed

If you have Jina installed you don’t need any extra dependencies, simply run:

jina hello-world

If you have Docker you don’t even Jina installed for this example, simply run:

On MacOS:

docker run -v "$(pwd)/j:/j" jinaai/jina hello-world --workdir /j && open j/hello-world.html

On Linux:

docker run -v "$(pwd)/j:/j" jinaai/jina hello-world --workdir /j && xdg-open j/hello-world.html
../../_images/hello-world-demo.png

Overview

With this script you will:

  1. Download the Fashion-MNIST training and test data

  2. Index 60,000 images from the training set

  3. Use random images from the test set as queries

  4. Retrieve the relevant results

  5. After around 1 minute, a web page will open and show results like this:

../../_images/hello-world.gif

And the implementation behind it? It’s simple:

Python API
from jina.flow import Flow

f = Flow.load_config('helloworld.flow.index.yml')

with f:
    f.index_ndarray(fashion_mnist)
YAML spec
!Flow
pods:
  encode:
    uses: helloworld.encoder.yml
    parallel: 2
  index:
    uses: helloworld.indexer.yml
    shards: 2
Flow in Dashboard
../../_images/hello-world-flow.png

All the big words you can name: computer vision, neural search, microservices, indexing, querying/searching, and shards all happened in just one minute!

View “Hello World” in Jina Dashboard

You can see the the logs and get insight into the health of your Flow with Jina Dashboard. In order to do that you’ll need 2 steps:

  1. Connect to JinaD.

  2. Set the right port in Dashboard.

You can follow the detailed steps here.

More Options for “Hello, World”

Intrigued? Play with different options via:

jina hello-world --help

Start the hello-world demo, a simple end2end image index and search demo without any extra dependencies.

usage: jina hello-world [-h] [--workdir] [--download-proxy] [--shards]
                        [--parallel] [--uses-index] [--index-data-url]
                        [--index-labels-url] [--index-request-size]
                        [--uses-query] [--query-data-url] [--query-labels-url]
                        [--query-request-size] [--num-query] [--top-k]

General arguments

--workdir

The workdir for hello-world demoall data, indices, shards and outputs will be saved there

Default: “1a5a8023-3239-48ec-8a83-9754e44f04c2”

--download-proxy

The proxy when downloading sample data

Scalability arguments

--shards

The number of shards when index and query

Default: 2

--parallel

The number of parallel when index and query

Default: 2

Index arguments

--uses-index

The yaml path of the index flow

Default: “/opt/hostedtoolcache/Python/3.8.9/x64/lib/python3.8/site-packages/jina/resources/fashion/helloworld.flow.index.yml”

--index-data-url

The url of index data (should be in idx3-ubyte.gz format)

Default: “http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz

--index-labels-url

The url of index labels data (should be in idx3-ubyte.gz format)

Default: “http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz

--index-request-size

The request size in indexing (the maximum number of documents that will be included in a Request before sending it)

Default: 1024