Enhance Your Search Experience with BAAI's Reranking Actions

24 Apr 2025
Enhance Your Search Experience with BAAI's Reranking Actions

In today's data-driven world, enhancing search capabilities is crucial for delivering relevant content to users. The yxzwayne/bge-reranker-v2-m3 provides developers with powerful Cognitive Actions designed to efficiently rank query-document pairs using a state-of-the-art reranker model from BAAI. By leveraging these pre-built actions, developers can significantly improve the relevance of search results, optimize performance, and streamline integration into their applications.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON structure and API requests.
  • Familiarity with Python for executing API calls.

Authentication typically involves passing your API key in the request headers.

Cognitive Actions Overview

Rank Query-Document Pairs

The Rank Query-Document Pairs action allows you to leverage the latest reranker model from BAAI to output rank scores for pairs of queries and documents. This action is categorized under semantic-search and supports FP16 inference for enhanced efficiency, making it suitable for applications requiring quick and accurate ranking of search results.

Input

The input for this action requires a JSON string representing either a single query-document pair or a list of such pairs. Each pair consists of a query and a corresponding passage, formatted as a list of lists.

  • Required Field:
    • inputList: A JSON string containing the query-document pairs.

Example Input:

{
  "inputList": "[[\"attention mechanism\", \"why does the chicken cross the road?\"], [\"attention mechanism\", \"attention is off by one\"], [\"attention mechanism\", \"evolutionary scale protein language models.\"]]"
}

Output

The action returns a list of rank scores, each corresponding to the input query-document pairs. The scores denote the relevance of the documents to the queries, with lower scores indicating higher relevance.

Example Output:

[
  -11.03125,
  -2.306640625,
  -10.40625
]

Conceptual Usage Example (Python)

Here’s how you can call the Rank Query-Document Pairs action using Python:

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 = "7a2409f2-4474-48f5-971f-61e1b9482686" # Action ID for Rank Query-Document Pairs

# Construct the input payload based on the action's requirements
payload = {
    "inputList": "[[\"attention mechanism\", \"why does the chicken cross the road?\"], [\"attention mechanism\", \"attention is off by one\"], [\"attention mechanism\", \"evolutionary scale protein language models.\"]]"
}

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 the placeholder API key and endpoint with your actual values. The action_id corresponds to the Rank Query-Document Pairs action, and the payload is structured according to the input schema provided. The response will contain the rank scores for the input pairs.

Conclusion

By utilizing the Cognitive Actions from the yxzwayne/bge-reranker-v2-m3, you can greatly enhance the relevance of search results within your applications. The Rank Query-Document Pairs action offers a straightforward way to implement advanced semantic search capabilities with minimal setup. Consider experimenting with various query-document pairs to further refine your search functionality and explore additional use cases where ranking can deliver enhanced user experiences.