Enhance Text Pair Relevance with the Ninehills BGE Reranker Action

22 Apr 2025
Enhance Text Pair Relevance with the Ninehills BGE Reranker Action

In today's data-driven world, optimizing the relevance of information is crucial for applications ranging from search engines to recommendation systems. The ninehills/bge-reranker-base provides a powerful Cognitive Action that allows developers to rank text pairs using the BAAI/bge-reranker-base model with fp16 precision. This action enhances the ordering of input pairs, ensuring that the most relevant responses are surfaced effectively.

Prerequisites

Before diving into the integration of the Cognitive Actions, make sure you have:

  • An API key for the Cognitive Actions platform.
  • A basic understanding of JSON format and HTTP requests.

To authenticate your requests, you will typically pass your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Rank Text Pairs With BAAI

The Rank Text Pairs With BAAI action enables you to utilize the BAAI/bge-reranker-base model to rank or rerank pairs of text. This action is particularly effective for improving relevancy in applications that require text prediction and retrieval.

  • Category: Text Processing

Input

The action requires the following input:

  • pairsJson (required): A JSON formatted string representing the input text pairs. For instance, the input [[“a”, “b”], [“c”, “d”]] represents two pairs of text.

Example Input:

{
  "pairsJson": "[[\"a\", \"b\"], [\"c\", \"d\"]]"
}

Output

Upon successful execution, the action returns a response containing:

  • scores: An array of scores representing the ranked relevance of each text pair.
  • use_fp16: A boolean indicating that fp16 precision was used.
  • model_name: The name of the model used for the ranking.

Example Output:

{
  "scores": [
    0.11529541015625,
    -0.48046875
  ],
  "use_fp16": true,
  "model_name": "bge-reranker-base"
}

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet that demonstrates how you might call the Cognitive Actions endpoint to execute the Rank Text Pairs With BAAI action:

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 = "f7cb7f28-3114-40ec-bc00-2e60b85722a0" # Action ID for Rank Text Pairs With BAAI

# Construct the input payload based on the action's requirements
payload = {
    "pairsJson": "[[\"a\", \"b\"], [\"c\", \"d\"]]"
}

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 Python code, ensure to replace the placeholder API key and endpoint URL with your actual credentials. The action_id variable is set to the ID of the Rank Text Pairs With BAAI action, and the payload is structured according to the input schema. The code handles the request and prints out the results or any errors encountered.

Conclusion

The ninehills/bge-reranker-base Cognitive Action provides a robust solution for developers looking to enhance the relevance of text pairs in their applications. By utilizing the BAAI/bge-reranker-base model, you can improve data retrieval and predictions significantly. Explore further use cases, integrate this action into your applications, and unlock the potential of optimized text processing today!