Milvus
Zilliz
Home
  • User Guide
  • Home
  • Docs
  • User Guide

  • Embeddings & Reranking

  • Reranking Function

  • Model Ranker

  • Voyage AI Ranker

Voyage AI RankerCompatible with Milvus 2.6.x

The Voyage AI Ranker leverages Voyage AI’s specialized rerankers to enhance search relevance through semantic reranking. It provides high-performance reranking capabilities optimized for retrieval-augmented generation (RAG) and search applications.

Voyage AI Ranker is particularly valuable for applications requiring:

  • Advanced semantic understanding with models specifically trained for reranking tasks

  • High-performance processing with optimized inference for production workloads

  • Flexible truncation controls for handling diverse document lengths

  • Fine-tuned performance across different model variants (rerank-2, rerank-lite, etc.)

Prerequisites

Before implementing Voyage AI Ranker in Milvus, ensure you have:

  • A Milvus collection with a VARCHAR field containing the text to be reranked

  • A valid Voyage AI API key with access to rerankers. Sign up at Voyage AI’s platform to obtain your API credentials. You can either:

    • Set the VOYAGE_API_KEY environment variable, or

    • Specify the API key directly in the ranker configuration

Create a Voyage AI ranker function

To use Voyage AI Ranker in your Milvus application, create a Function object that specifies how the reranking should operate. This function will be passed to Milvus search operations to enhance result ranking.

from pymilvus import MilvusClient, Function, FunctionType

# Connect to your Milvus server
client = MilvusClient(
    uri="http://localhost:19530"  # Replace with your Milvus server URI
)

# Configure Voyage AI Ranker
voyageai_ranker = Function(
    name="voyageai_semantic_ranker",        # Unique identifier for your ranker
    input_field_names=["document"],         # VARCHAR field containing text to rerank
    function_type=FunctionType.RERANK,      # Must be RERANK for reranking functions
    params={
        "reranker": "model",                # Enables model-based reranking
        "provider": "voyageai",             # Specifies Voyage AI as the service provider
        "model_name": "rerank-2.5",           # Voyage AI reranker to use
        "queries": ["renewable energy developments"], # Query text for relevance evaluation
        "max_client_batch_size": 128,       # Optional: batch size for model service requests (default: 128)
        "truncation": True,                 # Optional: enable input truncation (default: True)
        # "credential": "your-voyage-api-key" # Optional: if not set, uses VOYAGE_API_KEY env var
    }
)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.common.clientenum.FunctionType;
import io.milvus.v2.service.collection.request.CreateCollectionReq;

MilvusClientV2 client = new MilvusClientV2(ConnectConfig.builder()
        .uri("http://localhost:19530")
        .build());

CreateCollectionReq.Function ranker = CreateCollectionReq.Function.builder()
                       .functionType(FunctionType.RERANK)
                       .name("voyageai_semantic_ranker")
                       .inputFieldNames(Collections.singletonList("document"))
                       .param("reranker", "model")
                       .param("provider", "voyageai")
                       .param("model_name", "rerank-2.5")
                       .param("queries", "[\"renewable energy developments\"]")
                       .param("endpoint", "http://localhost:8080")
                       .param("max_client_batch_size", "128")
                       .param("truncation", "true")
                       .build();
// nodejs
// go
# restful

Voyage AI ranker-specific parameters

The following parameters are specific to the Voyage AI ranker:

Parameter

Required?

Description

Value / Example

reranker

Yes

Must be set to "model" to enable model reranking.

"model"

provider

Yes

The model service provider to use for reranking.

"voyageai"

model_name

Yes

The Voyage AI reranker to use from supported models on Voyage AI platform.

For a list of rerankers available, refer to Voyage AI documentation.

"rerank-2.5"

queries

Yes

List of query strings used by the rerank model to calculate relevance scores. The number of query strings must match exactly the number of queries in your search operation (even when using query vectors instead of text), otherwise an error will be reported.

["search query"]

max_client_batch_size

No

Since model services may not process all data at once, this sets the batch size for accessing the model service in multiple requests.

128 (default)

truncation

No

Whether to truncate the input to satisfy the "context length limit" on the query and the documents.

  • If True, the query and documents will be truncated to fit within the context length limit, before processed by the reranker model.

  • If False, an error will be raised when the query exceeds 8,000 tokens for rerank-2.5 and rerank-2.5-lite; 4,000 tokens for rerank-2; 2,000 tokens rerank-2-lite and rerank-1; and 1,000 tokens for rerank-lite-1, or the sum of the number of tokens in the query and the number of tokens in any single document exceeds 16,000 for rerank-2; 8,000 for rerank-2-lite and rerank-1; and 4,000 for rerank-lite-1.

True (default) or False

credential

No

Authentication credential for accessing Voyage AI API services. If not specified, the system will look for the VOYAGE_API_KEY environment variable.

"your-voyage-api-key"

For general parameters shared across all model rankers (e.g., provider, queries), refer to Create a model ranker.

To apply Voyage AI Ranker to a standard vector search:

# Execute search with Voyage AI reranker
results = client.search(
    collection_name="your_collection",
    data=[your_query_vector],  # Replace with your query vector
    anns_field="dense_vector",                   # Vector field to search
    limit=5,                                     # Number of results to return
    output_fields=["document"],                  # Include text field for reranking
    ranker=voyageai_ranker,                     # Apply Voyage AI reranker
    consistency_level="Bounded"
)
import io.milvus.v2.common.ConsistencyLevel;
import io.milvus.v2.service.vector.request.SearchReq;
import io.milvus.v2.service.vector.response.SearchResp;
import io.milvus.v2.service.vector.request.data.EmbeddedText;

SearchReq searchReq = SearchReq.builder()
        .collectionName("your_collection")
        .data(Arrays.asList(new EmbeddedText("AI Research Progress"), new EmbeddedText("What is AI")))
        .annsField("vector_field")
        .limit(10)
        .outputFields(Collections.singletonList("document"))
        .functionScore(FunctionScore.builder()
                .addFunction(ranker)
                .build())
        .consistencyLevel(ConsistencyLevel.BOUNDED)
        .build();
SearchResp searchResp = client.search(searchReq);
// nodejs
// go
# restful

Voyage AI Ranker can also be used with hybrid search to combine dense and sparse retrieval methods:

from pymilvus import AnnSearchRequest

# Configure dense vector search
dense_search = AnnSearchRequest(
    data=[your_query_vector_1], # Replace with your query vector
    anns_field="dense_vector",
    param={},
    limit=5
)

# Configure sparse vector search  
sparse_search = AnnSearchRequest(
    data=[your_query_vector_2], # Replace with your query vector
    anns_field="sparse_vector", 
    param={},
    limit=5
)

# Execute hybrid search with Voyage AI reranker
hybrid_results = client.hybrid_search(
    collection_name="your_collection",
    [dense_search, sparse_search],              # Multiple search requests
    ranker=voyageai_ranker,                    # Apply Voyage AI reranker to combined results
    limit=5,                                   # Final number of results
    output_fields=["document"]
)
import io.milvus.v2.service.vector.request.AnnSearchReq;
import io.milvus.v2.service.vector.request.HybridSearchReq;
import io.milvus.v2.service.vector.request.data.EmbeddedText;
import io.milvus.v2.service.vector.request.data.FloatVec;
        
List<AnnSearchReq> searchRequests = new ArrayList<>();
searchRequests.add(AnnSearchReq.builder()
        .vectorFieldName("dense_vector")
        .vectors(Arrays.asList(new FloatVec(embedding1), new FloatVec(embedding2)))
        .limit(5)
        .build());
searchRequests.add(AnnSearchReq.builder()
        .vectorFieldName("sparse_vector")
        .data(Arrays.asList(new EmbeddedText("AI Research Progress"), new EmbeddedText("What is AI")))
        .limit(5)
        .build());

HybridSearchReq hybridSearchReq = HybridSearchReq.builder()
                .collectionName("your_collection")
                .searchRequests(searchRequests)
                .ranker(ranker)
                .limit(5)
                .outputFields(Collections.singletonList("document"))
                .build();
SearchResp searchResp = client.hybridSearch(hybridSearchReq);
// nodejs
// go
# restful

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?