실리콘플로우 랭커Compatible with Milvus 2.6.x

SiliconFlow Ranker는 SiliconFlow의 포괄적인 재랭크 모델을 활용하여 시맨틱 재랭크를 통해 검색 관련성을 향상시킵니다. 유연한 문서 청킹 기능을 제공하며 다양한 제공업체의 전문화된 다양한 재랭크 모델을 지원합니다.

SiliconFlow Ranker는 특히 필요한 애플리케이션에 유용합니다:

  • 긴 문서 처리를 위한 구성 가능한 오버랩을 통한 고급 문서 청킹 기능

  • BAAI/bge-ranker 시리즈 및 기타 전문화된 모델을 포함한 다양한 재랭킹 모델에 대한 액세스

  • 가장 높은 점수를 받은 청크가 문서 점수를 나타내는 유연한 청크 기반 점수 매기기

  • 표준 및 프로 모델 변형을 모두 지원하는 비용 효율적인 재랭킹

전제 조건

Milvus에서 SiliconFlow Ranker를 구현하기 전에 다음이 필요합니다:

  • 재랭크할 텍스트가 포함된 VARCHAR 필드가 있는 Milvus 컬렉션

  • 재랭크 모델에 액세스할 수 있는 유효한 SiliconFlow API 키. SiliconFlow 플랫폼에 가입하여 API 자격 증명을 받습니다. 다음 중 하나를 수행할 수 있습니다:

    • SILICONFLOW_API_KEY 환경 변수를 설정하거나

    • 랭커 구성에서 직접 API 키를 지정합니다.

SiliconFlow 랭커 함수 생성하기

Milvus 애플리케이션에서 실리콘플로우 랭커를 사용하려면, 재랭킹 작동 방식을 지정하는 함수 객체를 생성하세요. 이 함수는 Milvus 검색 작업에 전달되어 결과 순위를 향상시킵니다.

from pymilvus import MilvusClient, Function, FunctionType

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

# Configure SiliconFlow Ranker
siliconflow_ranker = Function(
    name="siliconflow_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": "siliconflow",          # Specifies SiliconFlow as the service provider
        "model_name": "BAAI/bge-reranker-v2-m3", # SiliconFlow reranking model 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)
        "max_chunks_per_doc": 5,            # Optional: max chunks per document for supported models
        "overlap_tokens": 50,               # Optional: token overlap between chunks for supported models
        # "credential": "your-siliconflow-api-key" # Optional: if not set, uses SILICONFLOW_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("siliconflow_semantic_ranker")
                       .inputFieldNames(Collections.singletonList("document"))
                       .param("reranker", "model")
                       .param("provider", "siliconflow")
                       .param("model_name", "BAAI/bge-reranker-v2-m3")
                       .param("queries", "[\"renewable energy developments\"]")
                       .param("endpoint", "http://localhost:8080")
                       .param("max_client_batch_size", "32")
                       .param("max_chunks_per_doc", "5")
                       .param("overlap_tokens", "50")
                       .build();
// nodejs
// go
# restful

SiliconFlow 랭커 관련 파라미터

다음 파라미터는 SiliconFlow 랭커에만 해당되는 파라미터입니다:

파라미터

필수?

설명

값/예시

reranker

모델 순위 재지정을 사용하려면 "model" 으로 설정해야 합니다.

"model"

provider

재랭크에 사용할 모델 서비스 제공업체입니다.

"siliconflow"

model_name

SiliconFlow 플랫폼에서 지원되는 모델 중에서 사용할 SiliconFlow 재랭크 모델입니다.

사용 가능한 재랭크 모델 목록은 SiliconFlow 설명서를 참조하세요.

"BAAI/bge-reranker-v2-m3"

queries

재랭크 모델에서 연관성 점수를 계산하는 데 사용하는 쿼리 문자열 목록입니다. 쿼리 문자열의 수는 검색 작업의 쿼리 수와 정확히 일치해야 하며(텍스트 대신 쿼리 벡터를 사용하는 경우에도 마찬가지), 그렇지 않으면 오류가 보고됩니다.

["검색 쿼리"]

max_client_batch_size

No

모델 서비스가 모든 데이터를 한 번에 처리하지 못할 수 있으므로 여러 요청에서 모델 서비스에 액세스하기 위한 배치 크기를 설정합니다.

128 (기본값)

max_chunks_per_doc

No

문서 내에서 생성되는 최대 청크 수입니다. 긴 문서는 계산을 위해 여러 개의 청크로 나뉘며, 청크 중 가장 높은 점수를 문서의 점수로 사용합니다. 특정 모델에서만 지원됩니다: BAAI/bge-reranker-v2-m3, Pro/BAAI/bge-reranker-v2-m3, 및 netease-youdao/bce-reranker-base_v1.

5, 10

overlap_tokens

No

문서가 청크로 분할될 때 인접한 청크 간에 토큰이 겹치는 개수입니다. 이렇게 하면 청크 경계를 넘어 연속성을 보장하여 의미적 이해를 높일 수 있습니다. 특정 모델에서만 지원됩니다: BAAI/bge-reranker-v2-m3, Pro/BAAI/bge-reranker-v2-m3, 및 netease-youdao/bce-reranker-base_v1.

50

credential

아니요

SiliconFlow API 서비스에 액세스하기 위한 인증 자격 증명입니다. 지정하지 않으면 시스템에서 SILICONFLOW_API_KEY 환경 변수를 찾습니다.

"your-siliconflow-api-key"

모델별 기능 지원: max_chunks_per_docoverlap_tokens 매개 변수는 특정 모델에서만 지원됩니다. 다른 모델을 사용하는 경우 이러한 매개 변수는 무시됩니다.

모든 모델 랭커에서 공유되는 일반 매개변수(예: provider, queries)는 모델 랭커 만들기를 참조하세요.

실리콘플로우 랭커를 표준 벡터 검색에 적용하려면 다음과 같이 하세요:

# Execute search with SiliconFlow reranking
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=siliconflow_ranker,                  # Apply SiliconFlow reranking
    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

Try Managed Milvus for Free

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

Get Started
피드백

이 페이지가 도움이 되었나요?