ICU
icu トークナイザーは、ソフトウェアの国際化に不可欠なツールを提供する Internationalization Components of Unicode(ICU)オープンソースプロジェクト上に構築されています。ICU の単語分割アルゴリズムを使用することで、このトークナイザーは世界の大半の言語においてテキストを正確に単語へ分割できます。
Notes
icu トークナイザーは、句読点とスペースを出力内で個別のトークンとして保持します。たとえば、"Привет! Как дела?" は ["Привет", "!", " ", "Как", " ", "дела", "?"] になります。こうした単独の句読点トークンを削除するには、removepunct フィルターを使用してください。
設定
icu トークナイザーを使用してアナライザーを構成するには、analyzer_params 内で tokenizer を icu に設定します。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
python
analyzer_params = {
"tokenizer": "icu",
}
java
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
javascript
// node
go
analyzerParams = map[string]any{"tokenizer": "icu"}
bash
# curl
c++
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
icu トークナイザーは、1 つ以上のフィルターと組み合わせて使用できます。たとえば、次のコードは icu トークナイザーと remove punct filter を使用するアナライザーを定義しています。
- Python
- Java
- NodeJS
- Go
- cURL
- C++
python
analyzer_params = {
"tokenizer": "icu",
"filter": ["removepunct"]
}
java
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
analyzerParams.put("filter", Collections.singletonList("removepunct"));
javascript
// node
go
analyzerParams = map[string]any{"tokenizer": "icu", "filter": []string{"removepunct"}}
bash
# curl
c++
nlohmann::json analyzer_params = {
{"tokenizer", "icu"},
{"filter", {"removepunct"}}
};
analyzer_params を定義した後、コレクションスキーマを定義する際にそれらを VARCHAR フィールドへ適用できます。これにより、Zilliz Cloud は指定されたアナライザーを使用してそのフィールド内のテキストを処理し、効率的なトークン化とフィルタリングを実現できます。詳細については、使用例 を参照してください。
例
アナライザー設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使用してその動作を確認してください。
アナライザー設定
- Python
- Java
- NodeJS
- Go
- cURL
- C++
python
analyzer_params = {
"tokenizer": "icu",
}
java
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "icu");
javascript
// node
go
analyzerParams = map[string]any{"tokenizer": "icu"}
bash
# curl
c++
nlohmann::json analyzer_params = {
{"tokenizer", "icu"}
};
run_analyzer による検証
- Python
- Java
- NodeJS
- Go
- cURL
- C++
python
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)
java
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
// javascript
go
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
}
bash
# restful
c++
#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;
}
期待される出力
sql
['Привет', '!', ' ', 'Как', ' ', 'дела', '?']