JCloud

Deploy your Neural Search on the Cloud

Take the hassle out of hosting your Jina Flows

Alex C-G
Jina AI

--

Recently we launched the newest addition to the Jina family, JCloud:

In short, JCloud simplifies deploying and managing Jina Flows on the cloud. But before we do that, we have to make some changes to our app.

In the README above, you can see a tutorial for starting from scratch. But here we’re going to take an existing app, our fashion search engine, and migrate the Flow to the cloud.

In our case, all of our Executors are already on Jina Hub, so we can just use a single flow.yml file. For more complex projects with custom Executors, look at how to deploy a local project.

This means we have to do several things:

  1. Merge Flows into one
  2. Migrate Flows to YAML
  3. Dockerize (or bundle) our Executors
  4. Run locally the stuff that we need to
  5. A few final tweaks
  6. Deploy Flows to JCloud

Merge Flows into one

When I initially built the fashion search engine I used two Flows (be warned — this is ancient code and totally deprecated):

  • One for indexing, which did stuff like checking if the Document already existed.
  • One for querying the indexed data, which skipped that.

However, since we only deploy one Flow with JCloud, we need to merge those into one. An easy way in our case would be to use on_requests in our Executor configuration:

Migrate Flows to YAML

JCloud works with YAML Flows, so if our Flow is written in Python we’ll need to convert it over.

Here we’ll look at (very recent) versions of our Flow, both in Python and YAML formats:

Python

YAML

One big difference here is that YAML doesn’t support imports, so I manually defined all the columns instead of importing from our helper.py . I also changed out the workspace meta since it was a somewhat irrelevant option given recent refactoring work.

Dockerize (or bundle) our Executors

  • To Dockerize Jina Hub Executors, it’s as simple as changing every instance of jinahub:// to jinahub+docker:// .
  • To bundle your own Executors, see instructions here.

Run locally the stuff that we need to

If you previously ran your Flows on your local machine (especially outside of Docker), building Executors to work with local files was pretty straightforward. I would often build an Executor just for local image processing right at the start of my Flow.

That gets more difficult when you’re running a remote Flow. You can’t just point an Executor to ./data/images/foo.jpg and expect it to find the file, since the Flow and file are on different machines.

So for now I just bundle that stuff into my Document handling before I send the Documents to the Flow:

As you can see I still use the same Executor to perform those actions, except now I’m not integrating it into the Flow. You could even just push your Documents straight to the Executor on Jina Hub and save even more effort.

A few final tweaks

Adding more memory

One useful thing we can do is to increase the memory allocation for CLIPEncoder. By default JCloud assigns 100M to each Executor, and for a costly operation like encoding that’s just peanuts. We can do that with resources: memory :

Modifying our file paths

If we’re building an image search, we want our frontend to be able to see our images. If you were just running your app locally, you could easily just follow Document.uri , but as we mentioned before that won’t work this time round.

Instead, we can just create another tag based on a root_url (where we host the images) and the Document.uri :

Better yet, write the URL handling code as a function and bulk-apply to your Documents

You can then point your frontend to Document.tags["url"] instead of Document.uri to resolve your images correctly. (We won’t go into that here, since all frontends are different.)

The final YAML Flow

After all’s said and done, we’ve got our finalized Flow:

Deploy your Flow

Now you can install JCloud with pip install jcloud and deploy using:

jc deploy flow.yml

Your Flow will spin up and be ready for sending requests via Jina Client!

Issues? Questions?

Venture into the exciting world of Neural Search with Jina’s Learning Bootcamp. Get certified and be a part of Jina’s Hall of Fame! 🏆

Stay tuned for more exciting updates on the upcoming products and features from Jina AI! 👋

--

--