標準標記器

Milvus 中的standard tokenizer 會根據空格和標點符號分割文字,因此適用於大多數語言。

配置

要配置使用standard 令牌器的分析器,請在analyzer_params 中設定tokenizerstandard

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 tokenizer 可以與一個或多個過濾器結合使用。例如,以下程式碼定義了一個使用standard tokenizer 和lowercase filter 的分析器:

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 tokenizer 與 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("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")
        .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"
    "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{"The Milvus vector database is built for scale!"}
option := milvusclient.NewRunAnalyzerOption(texts).
    WithAnalyzerParams(string(bs))

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

預期輸出

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

免費嘗試托管的 Milvus

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

開始使用
反饋

這個頁面有幫助嗎?