ICU
icu tokenizer は、ソフトウェアの国際化に不可欠なツールを提供する Internationalization Components of Unicode (ICU) オープンソースプロジェクト上に構築されています。ICU の単語分割アルゴリズムを使用することで、この tokenizer は世界の大半の言語においてテキストを正確に単語へ分割できます。
icu tokenizer は、句読点とスペースを出力内で個別の token として保持します。たとえば、"Привет! Как дела?" は ["Привет", "!", " ", "Как", " ", "дела", "?"] になります。こうした単独の句読点 token を削除するには、removepunct filter を使用してください。
Configuration
icu tokenizer を使用して analyzer を設定するには、analyzer_params 内で tokenizer を icu に設定します。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
// node
analyzerParams = map[string]any{"tokenizer": "icu"}
# curl
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
icu tokenizer は、1 つ以上の filter と組み合わせて使用できます。たとえば、次のコードは icu tokenizer と remove punct filter を使用する analyzer を定義しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
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
nlohmann::json analyzer_params = {
{"tokenizer", "icu"},
{"filter", {"removepunct"}}
};
analyzer_params を定義した後、collection schema を定義する際にそれらを VARCHAR フィールドへ適用できます。これにより、Zilliz Cloud は効率的な tokenization と filtering のために、指定された analyzer を使用してそのフィールド内のテキストを処理できます。詳細は、使用例 を参照してください。
Examples
analyzer 設定を collection schema に適用する前に、run_analyzer メソッドを使用してその動作を確認してください。
Analyzer configuration
- Python
- Java
- NodeJS
- Go
- cURL
- C++
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
// node
analyzerParams = map[string]any{"tokenizer": "icu"}
# curl
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
run_analyzer を使用した検証
- Python
- Java
- NodeJS
- Go
- cURL
- C++
from pymilvus import (
MilvusClient,
)
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
# 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("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.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: "YOUR_CLUSTER_ENDPOINT",
APIKey: "YOUR_CLUSTER_TOKEN",
})
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
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"YOUR_CLUSTER_ENDPOINT", "YOUR_CLUSTER_TOKEN"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::string text = "Привет! Как дела?";
auto request = milvus::RunAnalyzerRequest()
.AddText(text)
.WithAnalyzerParams(analyzer_params);
milvus::RunAnalyzerResponse response;
status = client->RunAnalyzer(request, response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
Expected output
['Привет', '!', ' ', 'Как', ' ', 'дела', '?']