Standard トークナイザー
Zilliz Cloud の standard トークナイザーは、連続する Unicode の文字と数字を 1つのトークンにまとめ、その他の文字で分割します。
トークン化のルール
standard トークナイザーは、次のセットに属する連続した文字を同じトークンに保持します。
- ASCII 文字: 英字
A-Zとa-z、および数字0-9。 - 非 ASCII 文字: Unicode の
Alphabeticプロパティ、または数値の一般カテゴリNd、Nl、Noのいずれかを持つ文字。
| Unicode のプロパティまたはカテゴリ | 意味 | トークンに保持される文字の例 |
|---|---|---|
Alphabetic | 中国語の文字や日本語のかな、一部の結合マークを含む、さまざまな表記体系の文字 | 中文测试, カタカナ |
Nd(Decimal_Number) | 10 進数字 | ٣ |
Nl(Letter_Number) | 文字に似た数値文字 | Ⅷ |
No(Other_Number) | 丸囲み数字、上付き文字、分数などのその他の数値文字 | ①²¾ |
これらのセットに含まれない文字はトークンを区切り、破棄されます。これには空白、句読点、アンダースコア(_)、ハイフン(-)、アポストロフィ(')、および +、$、😀 などの記号が含まれます。連続する区切り文字は空のトークンを生成しません。
文字の分類は Rust の char::is_alphanumeric() に従います。プロパティの定義については、Unicode Standard Annex #44 を参照してください。Unicode 17.0 の完全な文字リストは、Alphabetic には DerivedCoreProperties.txt、Nd、Nl、No には DerivedGeneralCategory.txt で入手できます。文字がどの集合に属するかは、デプロイされたバージョンで使用される Unicode データによって異なります。
次の例では、{"tokenizer": "standard"} をフィルターなしで使用します。トークナイザーは文字の大文字と小文字を保持し、連続する中国語テキストを個々の単語に分割しません。
| 入力 | 出力トークン |
|---|---|
foo_bar-can't😀123 | ["foo", "bar", "can", "t", "123"] |
中文测试 | ["中文测试"] |
version①.¾ | ["version①", "¾"] |
Hello,World! | ["Hello", "World"] |
設定
standard トークナイザーを使用するアナライザーを設定するには、analyzer_params で tokenizer を standard に設定します。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"tokenizer": "standard",
}
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams := map[string]any{"tokenizer": "standard"}
let analyzer_params = serde_json::json!({
"tokenizer": "standard"
});
nlohmann::json analyzer_params = {
{"tokenizer", "standard"}
};
const analyzer_params = {
"tokenizer": "standard",
};
using System.Collections.Generic;
Dictionary<string, object> analyzerParams = new()
{
["tokenizer"] = "standard"
};
# restful
analyzerParams='{
"tokenizer": "standard"
}'
standard トークナイザーは、1つ以上のフィルターと組み合わせて使用できます。たとえば、次のコードは standard トークナイザーと lowercase フィルターを使用するアナライザーを定義しています。
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter": ["lowercase"]
}
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"lowercase"}}
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["lowercase"]
});
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"lowercase"}}
};
const analyzer_params = {
"tokenizer": "standard",
"filter": ["lowercase"]
};
using System.Collections.Generic;
Dictionary<string, object> analyzerParams = new()
{
["tokenizer"] = "standard",
["filter"] = new List<object> { "lowercase" }
};
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"lowercase"
]
}'
analyzer_params を定義した後、コレクションスキーマを定義する際にそれらを VARCHAR フィールドに適用できます。これにより、Zilliz Cloud は指定されたアナライザーを使用してそのフィールドのテキストを処理し、効率的なトークン化とフィルタリングを実行できます。詳細については、使用例 を参照してください。
例
アナライザー設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使ってその動作を確認してください。
アナライザーの設定
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter": ["lowercase"]
}
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"lowercase"}}
let analyzer_params = serde_json::json!({
"tokenizer": "standard",
"filter": ["lowercase"]
});
nlohmann::json analyzer_params = {
{"tokenizer", "standard"},
{"filter", {"lowercase"}}
};
const analyzer_params = {
"tokenizer": "standard",
"filter": ["lowercase"]
};
using System.Collections.Generic;
Dictionary<string, object> analyzerParams = new()
{
["tokenizer"] = "standard",
["filter"] = new List<object> { "lowercase" }
};
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"lowercase"
]
}'
run_analyzer を使った検証
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
from pymilvus import (
MilvusClient,
)
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
# Sample text to analyze
sample_text = "The Milvus vector database is built for scale!"
# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)
import java.util.ArrayList;
import java.util.List;
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("The Milvus vector database is built for scale!");
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{"The Milvus vector database is built for scale!"}
option := milvusclient.NewRunAnalyzerOption(texts...).
WithAnalyzerParams(analyzerParams)
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
fmt.Println(result)
use milvus::v2::prelude::*;
let config = ConnectConfig::new().uri("YOUR_CLUSTER_ENDPOINT").token("YOUR_CLUSTER_TOKEN");
let client = ClientV2::new(&config).await?;
let sample_text = "The Milvus vector database is built for scale!";
let result = client
.run_analyzer(
RunAnalyzerRequest::builder()
.texts(vec![sample_text])
.analyzer_params(analyzer_params)
.build()?,
)
.await?;
println!("Standard analyzer output: {:?}", result);
#include "milvus/MilvusClientV2.h"
#include <iostream>
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 = "The Milvus vector database is built for scale!";
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;
}
import { MilvusClient } from "@zilliz/milvus2-sdk-node";
const client = new MilvusClient({ address: "YOUR_CLUSTER_ENDPOINT", token: "YOUR_CLUSTER_TOKEN" });
const sampleText = "The Milvus vector database is built for scale!";
const result = await client.runAnalyzer({
text: sampleText,
analyzer_params,
});
console.log("Standard analyzer output:", result);
using Milvus.Client.V2;
using Milvus.Client.V2.Requests.Utility;
using Milvus.Client.V2.Responses.Utility;
using Milvus.Client.V2.Types;
MilvusClientV2 client = new(new ConnectConfig
{
Uri = "YOUR_CLUSTER_ENDPOINT",
ApiKey = "YOUR_CLUSTER_TOKEN"
});
// Sample text to analyze
string sampleText = "The Milvus vector database is built for scale!";
// Run the standard analyzer with the defined configuration
RunAnalyzerResp result = await client.RunAnalyzerAsync(new RunAnalyzerReq
{
AnalyzerParams = analyzerParams,
Texts = [sampleText]
});
foreach (AnalyzerToken t in result.Results.SelectMany(r => r.Tokens))
{
Console.WriteLine(t.Token);
}
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/common/run_analyzer" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--header "Request-Timeout: 10" \
-d '{
"text": ["The Milvus vector database is built for scale!"],
"analyzerParams": "{\"tokenizer\": \"standard\", \"filter\": [\"lowercase\"]}"
}'
期待される出力
['the', 'milvus', 'vector', 'database', 'is', 'built', 'for', 'scale']