空格
只要字與字之間有空格,whitespace tokenizer 就會將文字分割成詞彙。
配置
若要設定使用whitespace tokenizer 的分析器,請在analyzer_params 中設定tokenizer 為whitespace 。
analyzer_params = {
"tokenizer": "whitespace",
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
const analyzer_params = {
"tokenizer": "whitespace"
};
analyzerParams = map[string]any{"tokenizer": "whitespace"}
# restful
analyzerParams='{
"tokenizer": "whitespace"
}'
空白符記器可與一個或多個過濾器結合使用。例如,以下程式碼定義了一個使用whitespace 記錄器及lowercase 過濾器的分析器:
analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
const analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
};
analyzerParams = map[string]any{"tokenizer": "whitespace", "filter": []any{"lowercase"}}
# restful
analyzerParams='{
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}'
定義analyzer_params 之後,您可以在定義集合模式時,將它們套用到VARCHAR 欄位。這可讓 Milvus 使用指定的分析器來處理該欄位中的文字,以進行有效率的標記化和過濾。詳情請參閱範例使用。
範例
在應用分析器配置到您的收集模式之前,請使用run_analyzer 方法驗證其行為。
分析器配置
analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "whitespace");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
// javascript
analyzerParams = map[string]any{"tokenizer": "whitespace", "filter": []any{"lowercase"}}
# restful
驗證使用run_analyzerCompatible with Milvus 2.5.11+
from pymilvus import (
MilvusClient,
)
client = MilvusClient(uri="http://localhost:19530")
# 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")
.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!']