ICU
icu トークナイザーは、ソフトウェアの国際化に向けた主要なツールを提供する Internationalization Components of Unicode(ICU)オープンソースプロジェクトを基盤として構築されています。ICU の単語分割アルゴリズムを使用することで、このトークナイザーは世界の大半の言語においてテキストを正確に単語へ分割できます。
icu トークナイザーは、句読点とスペースを出力内の個別のトークンとして保持します。たとえば、"Привет! Как дела?" は ["Привет", "!", " ", "Как", " ", "дела", "?"] になります。こうした単独の句読点トークンを削除するには、removepunct フィルターを使用してください。
設定
icu トークナイザーを使用するアナライザーを構成するには、analyzer_params で tokenizer を icu に設定します。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams = map[string]any{"tokenizer": "icu"}
use milvus::v2::prelude::*;
use serde_json::json;
let analyzer_params = json!({ "tokenizer": "icu" });
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
const analyzer_params = {
tokenizer: "icu",
};
# restful
analyzerParams='{
"tokenizer": "icu"
}'
icu トークナイザーは、1 つ以上のフィルターと組み合わせて使用できます。たとえば、次のコードは icu トークナイザーと remove punct filter を使用するアナライザーを定義しています。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "icu",
"filter": ["removepunct"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams.put("filter", Collections.singletonList("removepunct"));
analyzerParams = map[string]any{"tokenizer": "icu", "filter": []string{"removepunct"}}
use milvus::v2::prelude::*;
use serde_json::json;
let analyzer_params = json!({
"tokenizer": "icu",
"filter": ["removepunct"]
});
nlohmann::json analyzer_params = {
{"tokenizer", "icu"},
{"filter", {"removepunct"}}
};
const analyzer_params = {
tokenizer: "icu",
filter: ["removepunct"],
};
# restful
analyzerParams='{
"tokenizer": "icu",
"filter": ["removepunct"]
}'
analyzer_params を定義した後、コレクションスキーマを定義するときに、これらを VARCHAR フィールドに適用できます。これにより、Zilliz Cloud は指定されたアナライザーを使用してそのフィールド内のテキストを処理し、効率的なトークン化とフィルタリングを実現できます。詳細については、使用例 を参照してください。
例
アナライザー設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使用してその動作を確認してください。
アナライザー設定
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
analyzer_params = {
"tokenizer": "icu",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams = map[string]any{"tokenizer": "icu"}
use milvus::v2::prelude::*;
use serde_json::json;
let analyzer_params = json!({ "tokenizer": "icu" });
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
const analyzer_params = {
tokenizer: "icu",
};
# restful
analyzerParams='{
"tokenizer": "icu"
}'
run_analyzer による検証
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- cURL
from pymilvus import (
MilvusClient,
)
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
# Sample text to analyze
sample_text = "Привет! Как дела?"
# Run the icu analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("ICU 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();
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
ctx := context.Background()
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "YOUR_CLUSTER_ENDPOINT",
APIKey: "YOUR_CLUSTER_TOKEN",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
texts := []string{"Привет! Как дела?"}
option := milvusclient.NewRunAnalyzerOption(texts...).
WithAnalyzerParams(analyzerParams)
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
use milvus::v2::prelude::*;
use serde_json::json;
let config = ConnectConfig::new().uri("YOUR_CLUSTER_ENDPOINT").token("YOUR_CLUSTER_TOKEN");
let client = ClientV2::new(&config).await?;
let analyzer_params = json!({ "tokenizer": "icu" });
let result = client
.run_analyzer(
RunAnalyzerRequest::builder()
.texts(vec!["Привет! Как дела?"])
.analyzer_params(analyzer_params)
.build()?,
)
.await?;
println!("ICU analyzer output: {:?}", result.results());
#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;
}
const sample_text = "Привет! Как дела?";
// Run the icu analyzer with the defined configuration
const result = await client.runAnalyzer({
text: sample_text,
analyzer_params,
});
console.log("ICU analyzer output:", result);
# restful
curl --request POST \
--url "YOUR_CLUSTER_ENDPOINT/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer YOUR_CLUSTER_TOKEN" \
--header "Content-Type: application/json" \
-d '{
"text": ["Привет! Как дела?"],
"analyzerParams": "{\"tokenizer\": \"icu\"}"
}'
期待される出力
['Привет', '!', ' ', 'Как', ' ', 'дела', '?']