Skip to main content

Rerank Search

Rerank search is a technique that uses an AI rerank model to re-sort search results. It employs deep learning models to evaluate the semantic relevance between query terms and candidate documents, optimizing the search result ranking to enhance accuracy and user experience.

In Retrieval-Augmented Generation (RAG) applications, AI reranking is a crucial step. SeekDB provides the AI_RERANK function, allowing you to directly call an AI rerank model within SQL queries. This eliminates the need for additional coding to achieve intelligent search result optimization. The AI_RERANK function specifies a registered rerank model using model_key, organizes user-provided query terms and document lists according to vendor rules, sends them to the specified model, and returns the sorted results.

Use the AI_RERANK function

The AI_RERANK function specifies a registered rerank model using model_key, sends user-provided query terms and document lists to the model, and returns the sorted results.

Syntax

AI_RERANK(model_key, query, documents[, document_key])

Parameter description:

ParameterDescriptionTypeNullable
model_keyThe model registered in the database.VARCHAR(128)No
queryThe search text entered by the user.VARCHAR(1024)No
documentsThe list of documents entered by the user.JSON array, for example, '["apple", "banana"]'No

You must specify model_key, query, and documents. If one of them is NULL, the function will return an error.

Return value:

  • A JSON array containing the documents and their relevance scores returned by the rerank model, sorted in descending order of relevance scores.

Examples

SELECT AI_RERANK("ob_rerank", "Apple", '["apple", "banana", "fruit", "vegetable"]');

The returned result is as follows:

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ai_rerank("ob_rerank","Apple",'["apple","banana","fruit","vegetable"]') |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [{"index": 0, "document": {"text": "apple"}, "relevance_score": 0.9912109375}, {"index": 1, "document": {"text": "banana"}, "relevance_score": 0.0033512115478515625}, {"index": 2, "document": {"text": "fruit"}, "relevance_score": 0.0003669261932373047}, {"index": 3, "document": {"text": "vegetable"}, "relevance_score": 0.00001996755599975586}] |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+