Length
length filter 删除不满足指定长度要求的 token,允许您控制在文本处理期间保留的 token 长度。
配置
length filter 是 Milvus 中的自定义 filter。要使用它,请在 filter 配置中指定 "type": "length",并使用 min 和 max 参数设置长度要求。
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);
}}));
cosnt analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "length", # Specifies the filter type as length
"max": 10, # Sets the maximum token length to 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 filter 接受以下可配置参数:
参数 | 描述 |
|---|---|
| 保留 token 的最小长度。默认为 0。 |
| 保留 token 的最大长度。默认为 255。 |
length filter 对 tokenizer 生成的 term 进行操作,因此必须与 tokenizer 结合使用。
定义 analyzer_params 后,您可以在定义 collection schema 时将其应用于 VARCHAR field。这允许 Milvus 使用指定的 analyzer 处理该 field 中的文本,以实现高效的分词和过滤。有关详细信息,请参阅 示例使用。
示例
在将 analyzer 配置应用到您的 collection schema 之前,使用 run_analyzer 方法验证其行为。
Analyzer 配置
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);
}}));
// javascript
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "length",
"max": 10,
}}}
# restful
Verification using run_analyzer
使用 run_analyzer 验证
# 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)
// java
// javascript
// go
# restful
Expected output
预期输出
['The', 'length', 'filter', 'allows', 'control', 'over', 'token', 'length', 'for', 'text', 'processing']