Unlocking Multilingual Semantic Search with lucataco/bge-m3 Cognitive Actions

22 Apr 2025
Unlocking Multilingual Semantic Search with lucataco/bge-m3 Cognitive Actions

In the world of data retrieval and natural language processing, the ability to perform effective semantic searches across multiple languages is crucial. The lucataco/bge-m3 Cognitive Actions offer developers a powerful toolset for executing sophisticated embedding retrieval operations. This suite includes the capability to handle dense, sparse, and multi-vector retrievals, accommodating various granularities of input data. By utilizing these pre-built actions, developers can quickly enhance their applications with multilingual semantic search capabilities.

Prerequisites

Before diving into the integration of the lucataco/bge-m3 Cognitive Actions, ensure that you have the following prerequisites in place:

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform.
  • Environment Setup: Have a programming environment ready, such as Python, to execute the API calls.

Authentication typically involves passing your API key in the request headers to secure your access to the Cognitive Actions.

Cognitive Actions Overview

Perform Multilingual Multi-Mode Embedding Retrieval

Description: This action allows you to execute retrieval operations using the BGE-M3 embedding model. It supports dense, sparse, and multi-vector retrievals in multiple languages, with input granularity levels reaching up to 8192 tokens.

Category: Semantic Search

Input

The input for this action is structured as follows:

  • inputSentencesListOne (required): A string containing the first list of sentences, separated by newlines.
  • inputSentencesListTwo (required): A string containing the second list of sentences, separated by newlines.
  • maxLength (optional): An integer specifying the maximum number of characters for input, with a default of 8192.
  • embeddingType (optional): A string indicating the type of embedding to use, with options for "dense", "sparse", and "colbert", defaulting to "dense".

Example Input:

{
  "maxLength": 4096,
  "embeddingType": "dense",
  "inputSentencesListOne": "What is BGE M3?\nDefination of BM25",
  "inputSentencesListTwo": "BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.\nBM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"
}

Output

The action typically returns a list of numerical arrays representing the embeddings. For example:

Example Output:

[[0.626  0.3477]
 [0.3499 0.678 ]]

This output structure contains the computed embeddings based on the input sentences, which can be further utilized in various applications such as search ranking or similarity detection.

Conceptual Usage Example (Python)

Here's how a developer might call this action using a hypothetical Cognitive Actions execution 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 = "57dbdfaa-a683-4d68-bef2-908ebbb905a9"  # Action ID for Perform Multilingual Multi-Mode Embedding Retrieval

# Construct the input payload based on the action's requirements
payload = {
    "maxLength": 4096,
    "embeddingType": "dense",
    "inputSentencesListOne": "What is BGE M3?\nDefination of BM25",
    "inputSentencesListTwo": "BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.\nBM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"
}

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 code snippet, developers can see how to structure the input JSON payload and where to insert the action ID. Note that the endpoint URL and request structure are illustrative and should be adjusted as per actual API documentation.

Conclusion

The lucataco/bge-m3 Cognitive Actions empower developers to integrate advanced multilingual embedding retrieval capabilities seamlessly into their applications. By leveraging these actions, you can enhance your search functionalities, improve data retrieval accuracy, and ultimately provide a richer user experience. Explore the possibilities with these actions and consider how they can fit into your next project!