標準分詞器

Milvus 中的standard 分詞器會將連續的 Unicode 字母和數字分組為詞元,並在其他字元處進行分割。

分詞規則

standard 分詞器會將屬於以下集合的連續字元保留在同一個詞元中:

  • ASCII 字元:字母A-Z 和a-z ,以及數字0-9 。
  • 非 ASCII 字元:具有 UnicodeAlphabetic 屬性,或屬於以下數值通用類別之一的字元:Nd 、Nl 或No 。
Unicode 屬性或類別含義保留在標記中的字元範例
Alphabetic跨書寫系統的字母(包括漢字和日語假名),以及某些組合標記中文测试,カタカナ
Nd (Decimal_Number)十進位數字٣
Nl (Letter_Number)類似字母的數字字元Ⅷ
No (Other_Number)其他數字字元,例如圈號、上標及分數①²¾

這些集合以外的字元會用來分隔標記,並被捨棄。這些字元包括空白、標點符號、底線 (_)、連字號 (-)、單引號 ('),以及符號如+ 、$ 和😀 。連續的分隔符號不會產生空標記。

字元分類遵循 Rust 的 char::is_alphanumeric()。有關屬性定義,請參閱《Unicode 標準附錄 #44》。完整的 Unicode 17.0 字元清單可於 DerivedCoreProperties.txtAlphabetic 以及 DerivedGeneralCategory.txtNd 、Nl 及No 的完整 Unicode 17.0 字元清單。字元歸屬取決於部署版本所使用的 Unicode 資料。

以下範例使用未套用任何篩選條件的{"tokenizer": "standard"} 。該詞元化器會保留字母的大小寫,且不會將連續的中文文字分割成單獨的詞彙。

輸入輸出標記
foo_bar-can't😀123["foo", "bar", "can", "t", "123"]
中文测试["中文测试"]
version①.¾["version①", "¾"]
Hello,World!["Hello", "World"]

設定

若要使用standard 分詞器來配置分析器,請在analyzer_params 中將tokenizer 設定為standard 。

analyzer_params = {
    "tokenizer": "standard",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
const analyzer_params = {
    "tokenizer": "standard",
};
analyzerParams = map[string]any{"tokenizer": "standard"}
# restful
analyzerParams='{
  "tokenizer": "standard"
}'

standard 分詞器可與一個或多個篩選器配合使用。例如,以下程式碼定義了一個使用standard 分詞器與lowercase 篩選器的分析器:

analyzer_params = {
    "tokenizer": "standard",
    "filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
const analyzer_params = {
    "tokenizer": "standard",
    "filter": ["lowercase"]
};
analyzerParams = map[string]any{"tokenizer": "standard", "filter": []any{"lowercase"}}
# restful
analyzerParams='{
  "tokenizer": "standard",
  "filter": [
    "lowercase"
  ]
}'

若要簡化設定,您可以選擇使用 standard分析器,該分析器將standard 分詞器與 lowercase 篩選器。

定義analyzer_params 後,您可在定義集合架構時將其套用至VARCHAR 欄位。這使 Milvus 能使用指定的分析器處理該欄位中的文字,以實現高效的分詞與過濾。詳細資訊請參閱「使用範例」。

範例

在將分析器設定套用至您的集合架構之前,請先使用 `run_analyzer ` 方法驗證其運作行為。

分析器設定

analyzer_params = {
    "tokenizer": "standard",
    "filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
// javascript
analyzerParams = map[string]any{"tokenizer": "standard", "filter": []any{"lowercase"}}
# restful

使用以下方式進行驗證run_analyzer

from pymilvus import (
    MilvusClient,
)

client = MilvusClient(
    uri="http://localhost:19530",
    token="root:Milvus"
)

# 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 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")
        .token("root:Milvus")
        .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();
// javascript
import (
    "context"
    "fmt"

    "github.com/milvus-io/milvus/client/v2/milvusclient"
)

ctx := context.Background()
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
    Address: "localhost:19530",
    APIKey:  "root:Milvus",
})
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
}
# restful

預期輸出

['the', 'milvus', 'vector', 'database', 'is', 'built', 'for', 'scale']

翻譯者DeepL

免費嘗試托管的 Milvus

Zilliz Cloud 無縫接入,由 Milvus 提供動力,速度提升 10 倍。

開始使用
反饋

這個頁面有幫助嗎?