Basic Concepts

Document, Executor, and Flow are the three fundamental concepts in Jina. Understanding these will help you build your search engine.

  • Document is the basic data type in Jina;

  • Executor is how Jina processes Documents;

  • Flow is how Jina streamlines and scales Executors.

Learn them all, nothing more, you are good to go.

Document

Document is the basic data type that Jina operates with. Text, picture, video, audio, image or 3D mesh: They are all Documents in Jina.

DocumentArray is a sequence container of Documents. It is the first-class citizen of Executor, serving as the Executor’s input and output.

You could say Document is to Jina is what np.float is to Numpy, while DocumentArray is similar to np.ndarray.

Example code

  1. from jina import Document, DocumentArray
  2. doc1 = Document(text="hello world")
  3. doc2 = Document(uri="cute_kittens.png")
  4. docs = DocumentArray([doc1, doc2])

Executor

An Executor performs a single task on a Document or DocumentArray.

Example code

  1. from jina import Executor, requests
  2. class MyExecutor(Executor):
  3. @requests
  4. def foo(self, **kwargs):
  5. print(kwargs)

Flow

The Flow ties Executors together into a processing pipeline to perform a bigger task, like indexing or querying a dataset.

Example code

  1. from jina import Flow, Document, Executor, requests
  2. class MyExecutor(Executor):
  3. @requests(on='/bar')
  4. def foo(self, docs, **kwargs):
  5. print(docs)
  6. f = Flow().add(name='myexec1', uses=MyExecutor)
  7. with f:
  8. f.post(on='/bar', inputs=Document(), on_done=print)