ICUCompatible with Milvus 2.5.11+
icu tokenizer 建立在國際化 Unicode 元件 (Internationalization Components of Unicode, ICU) 開放源碼專案上,該專案提供軟體國際化的關鍵工具。透過使用 ICU 的分詞演算法,標記器可以準確地將文字分割成世界上大多數語言的單字。
icu tokenizer 在輸出中保留了標點符號和空格作為獨立的 token。例如,"Привет! Как дела?" 變成["Привет", "!", " ", "Как", " ", "дела", "?"] 。若要移除這些獨立的標點符號,請使用 removepunct過濾器。
配置
若要配置使用icu tokenizer 的分析器,請在analyzer_params 中設定tokenizer 為icu 。
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
// node
analyzerParams = map[string]any{"tokenizer": "icu"}
# curl
icu tokenizer 可以與一個或多個過濾器結合使用。例如,以下程式碼定義了一個使用icu tokenizer 和remove punct 過濾器的分析器:
analyzer_params = {
"tokenizer": "icu",
"filter": ["removepunct"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams.put("filter", Collections.singletonList("removepunct"));
// node
analyzerParams = map[string]any{"tokenizer": "icu", "filter": []string{"removepunct"}}
# curl
定義analyzer_params 之後,您可以在定義集合模式時,將它們套用到VARCHAR 欄位。這可讓 Milvus 使用指定的分析器來處理該欄位中的文字,以進行有效率的標記化和過濾。詳情請參閱範例使用。
範例
在應用分析器配置到您的收集模式之前,請使用run_analyzer 方法驗證其行為。
分析器配置
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
// node
analyzerParams = map[string]any{"tokenizer": "icu"}
# curl
驗證使用run_analyzer
from pymilvus import (
MilvusClient,
)
client = MilvusClient(uri="http://localhost:19530")
# Sample text to analyze
sample_text = "Привет! Как дела?"
# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.RunAnalyzerReq;
import io.milvus.v2.service.vector.response.RunAnalyzerResp;
ConnectConfig config = ConnectConfig.builder()
.uri("http://localhost:19530")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
List<String> texts = new ArrayList<>();
texts.add("Привет! Как дела?");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
// javascript
import (
"context"
"encoding/json"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "localhost:19530",
APIKey: "root:Milvus",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
bs, _ := json.Marshal(analyzerParams)
texts := []string{"Привет! Как дела?"}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
預期輸出
['Привет', '!', ' ', 'Как', ' ', 'дела', '?']