標準分析器

standard 分析器是 Milvus 中的預設分析器,若未指定分析器,系統會自動將其套用至文字欄位。它結合了標準分詞器與小寫過濾器。

standard 分析器適用於那些依賴分隔符號(例如空格、標點符號)來界定單詞邊界的語言。然而,像中文、阿拉伯文、泰文、日文和韓文等語言,則需要特定於該語言的詞元化或正規化處理。在這種情況下,請使用特定於該語言的分析器,例如 chinese、 arabic,或 thai,或是搭配專用分詞器的自訂分析器,例如 lindera 和 icu。

定義

standard 分析器由以下部分組成:

  • 分詞器:使用「standard 」分詞器,將連續的 Unicode 字母和數字保留在同一個分詞中,並在其他字元處進行分割。有關確切的字元規則,請參閱「標準分詞器」。

  • 篩選器:使用「lowercase 」篩選器將所有語素轉換為小寫,以實現不區分大小寫的搜尋。如需更多資訊,請參閱「小寫轉換」。

standard 分析器的功能等同於以下自訂分析器設定:

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 」分析器套用至某個欄位,只需在 `analyzer_params` 中將 `type ` 設定為 `standard `,並視需要加入可選參數即可。

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

standard 分析器接受以下可選參數:

參數

說明

stop_words

一個包含停用詞清單的陣列,這些詞彙將在分詞過程中被移除。預設值為_english_ ,這是內建的一組常見英文停用詞。

自訂停用詞的配置範例:

analyzer_params = {
    "type": "standard", # Specifies the standard analyzer type
    "stop_words", ["of"] # Optional: List of words to exclude from tokenization
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "standard");
analyzerParams.put("stop_words", Collections.singletonList("of"));
analyzer_params = {
    "type": "standard", // Specifies the standard analyzer type
    "stop_words", ["of"] // Optional: List of words to exclude from tokenization
}
analyzerParams = map[string]any{"type": "standard", "stop_words": []string{"of"}}
# restful

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

範例

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

分析器設定

analyzer_params = {
    "type": "standard",  # Standard analyzer configuration
    "stop_words": ["for"] # Optional: Custom stop words parameter
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "standard");
analyzerParams.put("stop_words", Collections.singletonList("for"));
// javascript
analyzerParams = map[string]any{"type": "standard", "stop_words": []string{"for"}}
# restful
analyzerParams='{
  "type": "standard",
  "stop_words": [
    "of"
  ]
}'

使用以下方式進行驗證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"
    "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

預期輸出

Standard analyzer output: ['the', 'milvus', 'vector', 'database', 'is', 'built', 'scale']

翻譯者DeepL

免費嘗試托管的 Milvus

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

開始使用
反饋

這個頁面有幫助嗎?