Semantic Rerank API

Improve the accuracy of your search results with semantic reranking.

1. API Overview

The Semantic Rerank API is designed to improve the accuracy of your search results by leveraging deep semantic understanding to reorder results based on the relevance between the search query and the document content. This API performs a second-layer ranking on the initial search results (e.g., from keyword or vector search) to ensure that the most semantically relevant documents are presented to the user.

2. Rank Results

The Semantic Rerank API evaluates the semantic match between the search query and a set of candidate documents. It then reorders the results, assigning each document a semantic relevance score. This process is designed to enhance traditional ranking mechanisms like BM25 or RRF by considering the deeper semantic meaning behind both the query and document content.

  • index: The position of the document in the document list.

  • document: The document details, including:

    • text: The document content.

  • relevance_score: The semantic relevance score, ranging from 0 to 1. A higher score indicates stronger semantic alignment with the query.

3. API Endpoint

  • API Domain: https://api.langsearch.com

  • Endpoint: https://api.langsearch.com/v1/rerank

4. Request Method

  • Method: POST

5. Request Parameters

Request Headers

Parameter
Value
Description

Authorization

Bearer {API KEY}

Authentication parameter. Example: Bearer xxxxxx. API KEY can be obtained from the LangSearch API Dashboard (https://langsearch.com/dashboard) > API Key Management.

Content-Type

application/json

Specifies the format of the request body.

Request Body:

Parameter
Type
Required
Description

model

String

Yes

The model version to use for reranking. Available models: - langsearch-reranker-v1

query

String

Yes

The search query (can be in natural language, e.g., "Tell me the key points of Alibaba's 2024 ESG report").

documents

Array<String>

Yes

Array of documents to be reranked (max 50 documents).

top_n

Integer

No

The number of top-ranked documents to return. Default is the number of documents provided.

return_documents

Boolean

No

Whether to return the original text of each document in the result. Default is false.

Response:

Parameter
Type
Description

code

Integer

Status code. 200 means success.

log_id

String

Request ID for tracking.

msg

String

Status message.

model

String

The model used for reranking.

results

Array

The reranked results. Each result includes the document index and its relevance score.

6. Example Request

Request Body:

Response Body:

7. SDKs

cURL

Python

Last updated