中文

chinese 分析器專為處理中文文字而設計,提供有效的分割和標記化。

定義

chinese 分析器包括

  • 標記器:使用jieba tokenizer 根據詞彙和上下文將中文文字分割成 token。如需更多資訊,請參考Jieba

  • 過濾器:使用cnalphanumonly 過濾器移除包含任何非中文字元的字元。如需詳細資訊,請參閱Cnalphanumonly

chinese 分析器的功能等同於下列自訂分析器配置:

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

配置

要將chinese 分析器套用到欄位,只要在analyzer_params 中將type 設定為chinese 即可。

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

chinese 分析器不接受任何可選參數。

範例

在將分析器配置套用到您的集合模式之前,請使用run_analyzer 方法驗證其行為。

分析器配置

analyzer_params = {
    "type": "chinese",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "chinese");
// javascript
analyzerParams = map[string]any{"type": "chinese"}
# restful

驗證使用run_analyzerCompatible with Milvus 2.5.11+

from pymilvus import (
    MilvusClient,
)

client = MilvusClient(uri="http://localhost:19530")

# Sample text to analyze
sample_text = "Milvus 是一个高性能、可扩展的向量数据库!"

# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("English 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")
        .build();
MilvusClientV2 client = new MilvusClientV2(config);

List<String> texts = new ArrayList<>();
texts.add("Milvus 是一个高性能、可扩展的向量数据库!");

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: "localhost:19530",
    APIKey:  "root:Milvus",
})
if err != nil {
    fmt.Println(err.Error())
    // handle error
}

bs, _ := json.Marshal(analyzerParams)
texts := []string{"Milvus 是一个高性能、可扩展的向量数据库!"}
option := milvusclient.NewRunAnalyzerOption(texts).
    WithAnalyzerParams(string(bs))

result, err := client.RunAnalyzer(ctx, option)
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
# restful

預期輸出

Chinese analyzer output: ['Milvus', '是', '一个', '高性', '性能', '高性能', '可', '扩展', '的', '向量', '数据', '据库', '数据库']

免費嘗試托管的 Milvus

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

開始使用
反饋

這個頁面有幫助嗎?