Rerank search is a technique that uses the Rerank Model to perform secondary sorting on search results. It leverages a deep learning model to meticulously evaluate the semantic relevance between query terms and candidate documents, thereby optimizing search result rankings and enhancing search accuracy and user experience.
In Retrieval-Augmented Generation (RAG) applications, AI reranking is a key component. OceanBase AI Database provides the AI_RERANK function, allowing you to directly invoke the Rerank Model in SQL without writing additional code to achieve intelligent optimization of search results. The AI_RERANK function specifies a registered Rerank Model using model_key, organizes the message according to vendor rules, sends it to the specified model, and parses and returns the sorted results provided by the model.
Use the AI_RERANK function
The AI_RERANK function specifies a registered Rerank Model using model_key, sends the user-provided query terms and document list to the model, parses and returns the model's sorted results.
Syntax
AI_RERANK(model_key, query, documents[, document_key])
Parameter description:
Parameter |
Description |
Type |
Nullable |
|---|---|---|---|
| model_key | The model registered in the database. | VARCHAR(128) | No |
| query | The search text entered by the user. | VARCHAR(1024) | No |
| documents | The list of documents entered by the user. | JSON ARRAY, for example, '["apple", "banana"]' |
No |
If model_key, query, or documents is specified as NULL, the function returns an error.
Return value:
- A JSON array containing the documents and their relevance scores returned by the Rerank Model, sorted in descending order by relevance score.
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}] |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+