メインコンテンツまでスキップ

Length

length フィルターは、指定された長さの要件を満たさないトークンを削除し、テキスト処理中に保持されるトークンの長さを制御できるようにします。

設定

length フィルターは Zilliz Cloud のカスタムフィルターで、フィルター設定で "type": "length" を設定して指定します。analyzer_params 内で辞書として設定し、長さの制限を定義できます。

python
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "length", # Specifies the filter type as length
"max": 10, # Sets the maximum token length to 10 characters
}],
}

length フィルターは、以下の設定可能なパラメータを受け付けます。

パラメータ説明
maxトークンの最大長を設定します。この長さを超えるトークンは削除されます。

length フィルターは tokenizer によって生成された terms に対して動作するため、tokenizer と組み合わせて使用する必要があります。Zilliz Cloud で利用可能な tokenizer の一覧については、Standard Tokenizer およびその関連ページを参照してください。

analyzer_params を定義した後、collection schema を定義する際にそれらを VARCHAR フィールドへ適用できます。これにより、Zilliz Cloud はそのフィールド内のテキストを、指定された analyzer を使用して処理し、効率的な tokenization と filtering を行えます。詳細については、Example use を参照してください。

analyzer 設定を collection schema に適用する前に、run_analyzer メソッドを使用してその動作を確認してください。

アナライザー設定

python
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "length", # Specifies the filter type as length
"max": 10, # Sets the maximum token length to 10 characters
}],
}

run_analyzer を使用した検証

python
from pymilvus import (
MilvusClient,
)

client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")

# 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 = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)

期待される出力

python
['The', 'length', 'filter', 'allows', 'control', 'over', 'token', 'length', 'for', 'text', 'processing']