Length
length 过滤器可移除不符合指定长度要求的标记,让您可以控制文本处理过程中保留的标记长度。
配置
length 过滤器是 Milvus 中的自定义过滤器,通过在过滤器配置中设置 "type": "length" 来指定。您可以在 analyzer_params 中将其配置为字典,以定义长度限制。
- Python
- Java
- Node.js
- Go
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "length", # Specifies the filter type as length
"max": 10, # Sets the maximum token length to 10 characters
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(new HashMap<String, Object>() {{
put("type", "length");
put("max", 10);
}}));
const analyzerParams = {
tokenizer: "standard",
filter: [
{
type: "length", // Use the length token filter.
max: 10, // Keep tokens with at most 10 characters.
},
],
};
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "length",
"max": 10,
}}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
{
"type": "length",
"max": 10
}
]
}'
length 过滤器接受以下可配置参数。
参数 | 说明 |
|---|---|
| 设置最大标记长度。超过此长度的标记将被删除。 |
length 过滤器对 Tokenizer(分词器)生成的 Token(词元)进行操作,因此必须与 Tokenizer 结合使用。有关 Milvus 中可用的 Tokenizer 列表,请参阅 Standard Tokenizer 及其同类页面。
定义 analyzer_params 后,可以在定义 Collection Schema 时将其应用到 VARCHAR 字段。这样,Milvus 就可以使用指定的分析器对该字段中的文本进行处理,从而实现高效的标记化和过滤。有关详情,请参阅 示例使用。
示例
在将分析器配置应用到 Collection Schema 之前,请使用 run_analyzer 方法验证其行为。
Analyzer 配置
- Python
- Java
- Node.js
- Go
- cURL
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "length", # Specifies the filter type as length
"max": 10, # Sets the maximum token length to 10 characters
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(new HashMap<String, Object>() {{
put("type", "length");
put("max", 10);
}}));
Milvus v2.5.x 的官方资料尚未提供经过源码验证的 Node.js 示例。
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "length",
"max": 10,
}}}
Milvus v2.5.x 的官方资料尚未提供经过源码验证的 cURL 示例。
验证使用 run_analyzer
- Python
- Java
- Node.js
- Go
- cURL
# Sample text to analyze
sample_text = "The length filter allows control over token length requirements for text processing."
# Run the standard analyzer with the defined configuration
result = MilvusClient.run_analyzer(sample_text, analyzer_params)
print(result)
Milvus v2.5.x 的官方资料尚未提供经过源码验证的 Java 示例。
Milvus v2.5.x 的官方资料尚未提供经过源码验证的 Node.js 示例。
Milvus v2.5.x 的官方资料尚未提供经过源码验证的 Go 示例。
Milvus v2.5.x 的官方资料尚未提供经过源码验证的 cURL 示例。
预期输出
['The', 'length', 'filter', 'allows', 'control', 'over', 'token', 'length', 'for', 'text', 'processing']