Standard Analyzer
standard 分析器是 Milvus 的默认分析器,如果没有指定分析器,它将自动应用于文本字段。它使用基于语法的标记化,对大多数语言都很有效。
说明
定义
standard 分析器包括
-
Tokenizer(分词器):使用
standardTokenizer(分词器),根据语法规则将文本分割成离散的单词单元。更多信息,请参阅 标准 Tokenizer。 -
过滤器:使用
lowercase过滤器将所有标记转换为小写,从而实现不区分大小写的搜索。更多信息,请参阅 Lowercase Filter。
standard 分析器的功能相当于以下自定义分析器配置:
- Python
- Java
- Node.js
- Go
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter": ["lowercase"]
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter", Collections.singletonList("lowercase"));
const analyzerParams = {
"tokenizer": "standard",
"filter": ["lowercase"]
};
analyzerParams := map[string]any{"tokenizer": "standard", "filter": []any{"lowercase"}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
"lowercase"
]
}'
配置
要将 standard 分析器应用到一个字段,只需在 analyzer_params 中将 type 设置为 standard,并根据需要加入可选参数即可。
- Python
- Java
- Node.js
- Go
- cURL
analyzer_params = {
"type": "standard", # Specifies the standard analyzer type
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("type", "standard");
const analyzerParams = {
"type": "standard", // Specifies the standard analyzer type
}
analyzerParams = map[string]any{"type": "standard"}
# restful
analyzerParams='{
"type": "standard"
}'
standard 分析器接受以下可选参数:
参数 | 说明 |
|---|---|
| 一个数组,包含将从标记化中删除的停用词列表。默认为 |
自定义停用词配置示例:
- Python
- Java
- Node.js
- Go
- cURL
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"}}
Milvus v2.6.x 的官方资料尚未提供经过源码验证的 cURL 示例。
定义 analyzer_params 后,您可以在定义 Collection Schema 时将其应用到 VARCHAR 字段。这样,Milvus 就能使用指定的分析器处理该字段中的文本,从而实现高效的标记化和过滤。有关详细信息,请参阅 示例使用。
示例
在将分析器配置应用到 Collection Schema 之前,请使用 run_analyzer 方法验证其行为。
Analyzer 配置
- Python
- Java
- Node.js
- Go
- cURL
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"));
Milvus v2.6.x 的官方资料尚未提供经过源码验证的 Node.js 示例。
analyzerParams = map[string]any{"type": "standard", "stop_words": []string{"for"}}
# restful
analyzerParams='{
"type": "standard",
"stop_words": [
"of"
]
}'
验证使用 run_analyzer
- Python
- Java
- Node.js
- Go
- cURL
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();
Milvus v2.6.x 的官方资料尚未提供经过源码验证的 Node.js 示例。
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
}
Milvus v2.6.x 的官方资料尚未提供经过源码验证的 cURL 示例。
预期输出
Standard analyzer output: ['the', 'milvus', 'vector', 'database', 'is', 'built', 'scale']