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

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 フィルターはトークナイザーによって生成された用語に対して動作するため、トークナイザーと組み合わせて使用する必要があります。Zilliz Cloud で利用可能なトークナイザーの一覧については、Standard Tokenizer およびその関連ページを参照してください。

analyzer_params を定義した後は、コレクションスキーマを定義する際にそれらを VARCHAR フィールドへ適用できます。これにより、Zilliz Cloud は効率的なトークン化とフィルタリングのために、そのフィールド内のテキストを指定されたアナライザーを使用して処理できます。詳細については、使用例 を参照してください。

例​

アナライザー設定をコレクションスキーマに適用する前に、run_analyzer メソッドを使用してその動作を確認してください。

アナライザー設定​

python
from pymilvus import (
MilvusClient,
)

client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")

analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "length",
"max": 10,
}],
}

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

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']