SiliconFlow ランカーCompatible with Milvus 2.6.x
SiliconFlow RankerはSiliconFlowの包括的なリランキングモデルを活用し、セマンティックなリランキングによって検索の関連性を高めます。SiliconFlow Rankerは柔軟なドキュメント チャンキング機能を提供し、さまざまなプロバイダが提供する幅広い特殊なリランキング モデルをサポートします。
SiliconFlow Rankerは特に以下のようなアプリケーションに最適です:
長いドキュメントを扱うためのオーバーラップを設定できる高度なドキュメントチャンキング
BAAI/bge-rerankerシリーズやその他の特殊モデルを含む多様なリランキングモデルへのアクセス
最もスコアの高いチャンクがドキュメントのスコアを表す、柔軟なチャンクベースのスコアリング
標準モデルとプロモデルの両バリエーションをサポートした費用対効果の高いリランキング
前提条件
MilvusにSiliconFlow Rankerを実装する前に、以下のものをご用意ください:
リランキングするテキストを含む
VARCHARフィールドを持つ Milvus コレクション。リランキングモデルにアクセスできる有効なSiliconFlow APIキー。SiliconFlowのプラットフォームでサインアップし、API認証情報を取得します。以下のいずれかを実行します:
SILICONFLOW_API_KEY環境変数を設定する。ランカー構成で API キーを直接指定する。
SiliconFlow ランカー関数の作成
Milvus アプリケーションで SiliconFlow ランカーを使用するには、再ランキングの動作方法を指定する Function オブジェクトを作成します。この関数は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 ランカー固有のものです:
パラメータ |
必須か? |
パラメータ 説明 |
値 / 例 |
|---|---|---|---|
|
Yes |
モデルの再ランキングを有効にするには、 |
|
|
Yes |
リランキングに使用するモデルサービスプロバイダ。 |
|
|
はい |
SiliconFlow プラットフォームでサポートされているモデルの中から使用する SiliconFlow リランキング モデル。 使用可能なリランキング モデルのリストについては、SiliconFlow のドキュメントを参照してください。 |
|
|
はい |
リランク モデルが関連性スコアを計算するために使用するクエリ文字列のリスト。クエリ文字列の数は、検索操作のクエリの数と正確に一致する必要があります(テキストの代わりにクエリベクタを使用する場合も同様)。 |
[検索クエリ] |
|
いいえ |
モデルサービスは一度にすべてのデータを処理しない可能性があるため、複数のリクエストでモデルサービスにアクセスする際のバッチサイズを設定します。 |
|
|
いいえ |
文書内から生成されるチャンクの最大数。長い文書を複数のチャンクに分割して計算し、その中で最も高いスコアを文書のスコアとする。特定のモデルでのみサポート: |
|
|
いいえ |
文書がチャンク化されたときに、隣接するチャンク間で重複するトークンの数。これにより、チャンクの境界を越えた連続性が確保され、より良い意味理解が可能になる。特定のモデルでのみサポート: |
|
|
いいえ |
SiliconFlow API サービスにアクセスするための認証クレデンシャル。指定されていない場合、システムは |
"your-siliconflow-api-key"。 |
モデル固有の機能のサポート:max_chunks_per_doc およびoverlap_tokens パラメータは、特定のモデルでのみサポートされています。他のモデルを使用する場合、これらのパラメータは無視されます。
すべてのモデルランカーで共有される一般的なパラメーター(例:provider 、queries )については、モデルランカーを作成するを参照してください。
標準ベクトル検索への適用
SiliconFlow ランカーを標準的なベクトル検索に適用します:
# 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