Multilingual Search with jina-embeddings-v3 and Elasticsearch

In this tutorial, we’ll build a multilingual semantic search system with Elastic Cloud APIs using the jina-embeddings-v3 text embedding model.

First, you will need a Jina AI API key. Go to https://jina.ai/#apiform and follow the instructions there to get a free API key with 10 million tokens.

For expert users who are able to run AI models locally and generate embedding vectors outside of Elasticsearch, you can download and run jina-embeddings-v3 by following the instructions on the model’s page at Hugging Face: https://huggingface.co/jinaai/jina-embeddings-v3

Create an inference endpoint for jina-embeddings-v3

If you are running the model locally, you can skip this section and jump down to the section titled Index multilingual documents.

First, open your Elastic Cloud deployment’s console. This tutorial will use console commands to show you how to set up search with Jina AI.

Register the model with your Jina AI API key with the following command, inserting your API key in the "api_key" field:

To verify that you can now access the Jina AI API and generate embeddings, use the following command:

You should receive a result with a "text_embedding" field like the one below:

Create an index

Register a mapping definition for the model. We’ll call this one “jina-multilingual-demo.”

You will need to choose a vector size for your embeddings. jina-embeddings-v3 supports five sizes: 128, 256, 512, 768, 1024 dimensions. More dimensions mean larger vectors, resulting in higher accuracy but taking more storage space, more memory, and more time to search.

Put your choice in the "dims" field of the registration request, as in the example below. For simplicity, we will use the maximum size in this demo: 1024 dimensions.

Add an ingest pipeline

Ingest pipelines automate processing before data is inserted into Elasticsearch. We will create one named "jina_embed_pipeline".

Use the following command:

Index multilingual documents

Now you can add some documents to your Elastic deployment. The three below are in English, French, and Spanish and are translations of each other. Each POST command adds one document.

Query the index

To demonstrate jina-embeddings-v3’s cross-language semantics, we will query the index in German. The query text, in English translation, is “Which new music genres are currently popular?”

First, we obtain a query vector. jina-embeddings-v3 implements asymmetric retrieval, so query embeddings and indexed document embeddings are generated differently. It is important to make sure the "input_type" field is set to "search" to get query embeddings.

This command will return a query vector. Insert the resulting vector into the "query_vector" field of the command below. This command will perform a search using Elasticsearch’s built-in "knn" approximate nearest neighbor algorithm.

The response will be a list with the best scoring document to match this query (in our tests it was the French one) along with the cosine similarity score that document has to the query.

For fuller documentation of the search options for AI-generated dense vector indices, see the relevant documentation page for the Elasticsearch API.

Previously

Jina Reader

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. Elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as you are. Let’s connect and work together to build the magical search experience that will get you the results you want.

Try it yourself