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

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']
このページは役に立ちましたか?