跳到主要内容

Whitespace

空格分词器在单词之间存在空格时,将文本划分为词项。

配置

要使用空格分词器配置分析器,请在 analyzer_params 中将 tokenizer 设置为 whitespace

analyzer_params = {
"tokenizer": "whitespace",
}

空格分词器可以与一个或多个过滤器结合使用。例如,以下代码定义了一个使用空格分词器和小写过滤器的分析器:

analyzer_params = {
"tokenizer": "whitespace",
"filter": ["lowercase"]
}

定义 analyzer_params 后,您可以在定义 Collection Schema 时将其应用于 VARCHAR 字段。这使得 Zilliz Cloud 能够使用指定的分析器处理该字段中的文本,以实现高效的分词和过滤。更多信息,请参阅使用示例

使用示例

在完成 Analyzer 配置后,您可以使用 run_analyzer 方法来验证分词效果是否符合预期。

Analyzer 配置

from pymilvus import (
MilvusClient,
)

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)

# 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)

使用 run_analyzer 验证效果

from pymilvus import (
MilvusClient,
)

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)

# 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("English analyzer output:", result)

预期输出

['the', 'milvus', 'vector', 'database', 'is', 'built', 'for', 'scale!']