Unlock Multilingual Capabilities with the Adirik/Multilingual E5-Large Action

23 Apr 2025
Unlock Multilingual Capabilities with the Adirik/Multilingual E5-Large Action

In today's globalized world, the ability to understand and generate content in multiple languages is crucial for applications that serve diverse audiences. The Adirik/multilingual-e5-large model provides developers with a powerful toolset for creating multilingual text embeddings. This model, based on the XLM-RoBERTa architecture, allows you to process queries and passages to obtain relevant text embeddings, which can be used for various applications such as search, recommendation systems, and semantic understanding.

By utilizing pre-built cognitive actions, developers can seamlessly integrate multilingual capabilities into their applications without the need for extensive machine learning expertise.

Prerequisites

Before you start utilizing the Adirik/multilingual-e5-large actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and how to make HTTP requests in your preferred programming language.
  • A suitable environment to execute Python code.

You'll need to authenticate your requests by passing the API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Multilingual Text Embeddings

The Generate Multilingual Text Embeddings action is designed to create embeddings from a passage of text in response to a given query. This action is essential for applications involving semantic search, content recommendation, and understanding user intent across different languages.

Input

The input for this action is a JSON object that requires the following fields:

  • passage (required): A string containing the text you want to analyze.
  • query (optional): A string that represents the user's question or request for information.
  • normalize (optional): A boolean indicating whether the output embeddings should be normalized. Defaults to false.

Example Input:

{
  "query": "What is the recommended sugar intake for women",
  "passage": "As a general guideline, the CDC’s average recommended sugar intake for women ages 19 to 70 is 20 grams per day.",
  "normalize": false
}

Output

The output of this action includes a relevancy score and the generated embeddings, which can be used to measure the relationship between the query and the passage.

Example Output:

{
  "score": 90.9375,
  "embeddings": [
    [...]  // Array of numerical values representing the embeddings
  ]
}

Conceptual Usage Example (Python)

Here’s how you might call the Generate Multilingual Text Embeddings action with a hypothetical API endpoint:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "a3839da7-3e16-4c46-825a-8a403739c239"  # Action ID for Generate Multilingual Text Embeddings

# Construct the input payload based on the action's requirements
payload = {
    "query": "What is the recommended sugar intake for women",
    "passage": "As a general guideline, the CDC’s average recommended sugar intake for women ages 19 to 70 is 20 grams per day.",
    "normalize": False
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is constructed according to the required inputs, and the request is sent to the hypothetical endpoint for execution. The response is then printed in a readable format.

Conclusion

The Adirik/multilingual-e5-large action provides a powerful way to integrate multilingual text embeddings into your applications. By leveraging this cognitive action, developers can enhance their applications' capabilities to understand and generate diverse content, ultimately improving user engagement and satisfaction.

Consider exploring additional use cases, such as embedding-based search engines or personalized content recommendations, to fully utilize the potential of this technology!