ブログ

MLを使用したフィルターとファセットの生成

ML モデルを使用した検索エクスペリエンスにおけるフィルターとファセットの作成を自動化することと、従来のハードコードされたアプローチを比較して、長所と短所を検討します。

フィルターとファセットは、検索結果を絞り込むために使用されるメカニズムであり、ユーザーが関連するコンテンツや製品をより迅速に見つけるのに役立ちます。従来のアプローチでは、ルールは手動で定義されます。たとえば、映画カタログでは、フィルターやファセットで使用するためにジャンルなどの属性が事前定義されています。一方、AI モデルを使用すると、映画の特徴から新しい属性を自動的に抽出できるため、プロセスはより動的かつパーソナライズされたものになります。このブログでは、それぞれの方法の長所と短所を検討し、その応用と課題に焦点を当てます。

フィルターとファセットの違い

始める前に、フィルターとファセットとは何かを定義しましょう。フィルターは、結果セットを制限するために使用される定義済みの属性です。たとえば、マーケットプレイスでは、検索を実行する前でもフィルターを利用できます。ユーザーは、 「PS5」 を検索する前に 「ビデオゲーム」 などのカテゴリを選択し、データベース全体ではなく、より具体的なサブセットに検索を絞り込むことができます。これにより、より関連性の高い結果を得られる可能性が大幅に高まります。

各種フィルター

ファセットはフィルターと同様に機能しますが、検索を実行した後にのみ使用できます。つまり、検索によって結果が返され、それに基づいて絞り込みオプションの新しいリストが生成されます。たとえば、PS5 コンソールを検索する場合、ストレージ容量送料などの側面が表示され、ユーザーが理想的な製品を選択できるようになります。

ファセット

フィルターとファセットを定義したので、次に、従来のアプローチと機械学習 (ML) ベースのアプローチがそれらの実装と使用に与える影響について説明しましょう。それぞれの方法には、検索効率に影響する利点と課題があります。

フィルターとファセットに対する従来のアプローチ

このアプローチでは、フィルターとファセットは事前定義されたルールに基づいて手動で定義されます。つまり、検索を絞り込むために使用できる属性は、カタログ構造とユーザーのニーズを考慮して事前に固定され、計画されています。

たとえば、マーケットプレイスでは、「エレクトロニクス」や「ファッション」などのカテゴリに、ブランド、フォーマット、価格帯などの特定のフィルターがある場合があります。これらのルールは静的に作成されるため、検索エクスペリエンスの一貫性は確保されますが、新しい製品やカテゴリが登場するたびに手動で調整する必要があります。

このアプローチでは、表示されるフィルターとファセットの予測可能性と制御が可能になりますが、動的な改良を必要とする新しいトレンドが生まれた場合には制限される可能性があります。

長所:

  • 予測可能性と制御:フィルターとファセットは手動で定義されるため、管理が容易になります。

  • 複雑さが低い:モデルをトレーニングする必要はありません。

  • メンテナンスの容易さ:ルールが事前に定義されているため、調整や修正を迅速に行うことができます。

短所:

  • 新しいフィルターには再インデックスが必要です:新しい属性をフィルターとして使用する必要がある場合は、ドキュメントにこの情報が含まれていることを確認するために、データセット全体のインデックスを再作成する必要があります。

  • 動的適応の欠如:フィルターは静的であり、ユーザーの行動の変化に自動的に適応しません。

フィルター/ファセットの実装 – 古典的なアプローチ

開発ツールの Kibanaでは、従来のアプローチを使用してフィルター/ファセットのデモを作成します。

まず、インデックスを構造化するためのマッピングを定義します。

PUT videogames
{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "brand": { "type": "keyword" },
      "storage": { "type": "keyword" },
      "price": { "type": "float" },
      "description": { "type": "text" }
    }
  }
}

ブランドおよびストレージフィールドはキーワードとして設定されており、集計 (ファセット) で直接使用できます。価格フィールドはfloat型であり、価格範囲の作成を可能にします。

次のステップでは、製品データがインデックス化されます。

POST videogames/_bulk
{ "index": { "_id": 1 } }
{ "name": "Play Station 5", "brand": "Sony", "storage": "1TB", "price": 499.99, "description": "Stunning Gaming: Marvel at stunning graphics and experience the features of the new PS5. Breathtaking Immersion: Discover a deeper gaming experience with support for haptic feedback, adaptive triggers, and 3D Audio technology. Slim Design: With the PS5 Digital Edition, gamers get powerful gaming technology in a sleek, compact design. 1TB of Storage: Have your favorite games ready and waiting for you to play with 1TB of built-in SSD storage. Backward Compatibility and Game Boost: The PS5 console can play over 4,000 PS4 games. With Game Boost, you can even enjoy faster, smoother frame rates in some of the best PS4 console games." }
{ "index": { "_id": 2 } }
{ "name": "Xbox Series X", "brand": "Microsoft", "storage": "1TB", "price": 499.99, "description": "Fastest, most powerful Xbox console ever. Play thousands of titles: Every game looks and plays better on Xbox Series X. At the heart of Series X is the Xbox Velocity. Architecture, which combines a custom SSD and built-in software to significantly reduce load times in and out of game. Switch between multiple games in an instant with Quick Resume. Explore new worlds and experience the action like never before with an unparalleled 12 teraflops of graphics processing power. Enjoy 4K gaming at up to 120 frames per second, premium advanced 3D sound, and more. 4K at 120 FPS: requires compatible content and display X version - with disc drive" }
{ "index": { "_id": 3 } }
{ "name": "Nintendo Switch", "brand": "Nintendo", "storage": "512GB", "price": 299.99, "description": "SHARPER, VIBRANT VISUALS. The new 7-inch screen on the Nintendo Switch OLED takes your gaming to the next level: vibrant colors with sharp contrasts for every moment. INTEGRATED GAMEPLAY. Enjoy the console's many multiplayer modes and connect with other players. Online or locally, the fun on the Nintendo Switch is guaranteed. ENJOY IMMERSION FOR LONGER. In addition to delivering an unparalleled experience, thanks to its improved audio, the Nintendo Switch has a rechargeable battery while you play. From 4.5 hours to 9 hours of battery life. INCLUDES SUPER MARIO BROS. WONDER. Transform your world with the phenomenal flowers in this new Mario game, full of amazing adventures, power-ups and new abilities. NINTENDO SWITCH ONLINE SUBSCRIPTION. Access online games, play with friends and enjoy the exclusive benefits of the Nintendo Switch Online subscription." }
{ "index": { "_id": 4 } }
{ "name": "Steam Deck", "brand": "Valve", "storage": "512GB", "price": 399.99, "description": "You can save games, apps, photos and videos without worrying about space. High-Level Performance: The 4-core processor and graphics ensure a dynamic experience and fast responses. High-Definition Images: Smooth transitions and sharp images provide complete immersion in the game. Wireless Connectivity: Wi-Fi technology allows you to play wherever you want, without wires or cables limiting your fun" }
{ "index": { "_id": 5 } }
{ "name": "Nintendo Switch Lite", "brand": "Nintendo", "storage": "512GB", "price": 299.99, "description": "MADE TO BE PORTABLE. Nintendo Switch Lite is designed specifically for portable gaming. The console lets you jump into your favorite games wherever you are. COMPACT AND LIGHTWEIGHT. With its sleek, lightweight design, this console is ready to hit the road wherever you are. COMPATIBLE GAMES. The Nintendo Switch Lite system plays the library of Nintendo Switch games that work in handheld mode. A WORLD OF COLOR TO CHOOSE FROM. Available in a variety of vibrant and unique colors, Nintendo Switch Lite lets you bring even more personality wherever you go." }

ここで、ブランド、ストレージ、価格帯別に結果をグループ化して、クラシック ファセットを取得してみましょう。クエリでは、size:0 が定義されました。このシナリオでは、クエリに対応するドキュメントを含めずに、集計結果のみを取得することが目標です。

POST videogames/_search
{
  "size": 0,
  "aggs": {
    "brands": {
      "terms": { "field": "brand" }
    },
    "storage_sizes": {
      "terms": { "field": "storage" }
    },
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 300 },   
          { "from": 300, "to": 500 },  
          { "from": 500 }  
        ]
      }
    }
  }
}

応答には、 BrandStoragePriceのカウントが含まれ、フィルターとファセットの作成に役立ちます。

"aggregations": {
   "brands": {
     "doc_count_error_upper_bound": 0,
     "sum_other_doc_count": 0,
     "buckets": [
       {
         "key": "Microsoft",
         "doc_count": 1
       },
       {
         "key": "Nintendo",
         "doc_count": 1
       },
       {
         "key": "Sony",
         "doc_count": 1
       },
       {
         "key": "Valve",
         "doc_count": 1
       }
     ]
   },
   "storage_sizes": {
     "doc_count_error_upper_bound": 0,
     "sum_other_doc_count": 0,
     "buckets": [
       {
         "key": "1TB",
         "doc_count": 2
       },
       {
         "key": "512GB",
         "doc_count": 2
       }
     ]
   },
   "price_ranges": {
     "buckets": [
       {
         "key": "*-300.0",
         "to": 300,
         "doc_count": 1
       },
       {
         "key": "300.0-500.0",
         "from": 300,
         "to": 500,
         "doc_count": 3
       },
       {
         "key": "500.0-*",
         "from": 500,
         "doc_count": 0
       }
     ]
   }
 }

フィルターとファセットに対する機械学習/AIベースのアプローチ

このアプローチでは、人工知能 (AI) 技術を含む機械学習 (ML) モデルがデータ属性を分析して、関連するフィルターとファセットを生成します。ML/AI は、事前定義されたルールに依存するのではなく、インデックス化されたデータ特性を活用します。これにより、新しいファセットとフィルターを動的に検出できるようになります。

長所:

  • 自動更新:新しいフィルターとファセットは自動的に生成され、手動で調整する必要はありません。

  • 新しい属性の検出:これまで考慮されていなかったデータ特性をフィルターとして識別し、検索エクスペリエンスを充実させることができます。

  • 手作業の削減: AI が利用可能なデータから学習するため、チームはフィルタリング ルールを継続的に定義および更新する必要がありません。

短所:

  • メンテナンスの複雑さ:モデルを使用する場合、生成されたフィルターの一貫性を確保するために事前検証が必要になる場合があります。

  • ML と AI の専門知識が必要:このソリューションでは、モデルのパフォーマンスを微調整および監視する資格のある専門家が必要です。

  • 無関係なフィルターのリスク:モデルが適切に調整されていない場合、ユーザーにとって役に立たないファセットが生成される場合があります。

  • コスト: ML および AI の使用にはサードパーティのサービスが必要になる場合があり、運用コストが増加する可能性があります。

適切に調整されたモデルと適切に作成されたプロンプトを使用しても、生成されたファセットはレビュー手順を経る必要があることに注意してください。この検証は手動で行うことも、モデレーション ルールに基づいて行うこともできます。これにより、コンテンツが適切かつ安全であることが保証されます。必ずしも欠点ではありませんが、ファセットをユーザーに提供する前に、その品質と適合性を確認することは重要な考慮事項です。

フィルター/ファセットの実装 - AIアプローチ

このデモでは、AI モデルを使用して製品の特性を自動的に分析し、関連する属性を提案します。適切に構造化されたプロンプトを使用して、カタログから情報を抽出し、それをフィルターとファセットに変換します。以下に、プロセスの各ステップを紹介します。

最初に、 Inference API を使用して、ML サービスとの統合のためのエンドポイントを登録します。以下はOpenAI のサービスとの統合の例です。

PUT _inference/completion/generate_filter_ia
{
   "service": "openai",
   "service_settings": {
       "api_key": "your-key",
       "model_id": "gpt-4o-mini"
   }
}

ここで、プロンプトを実行し、モデルによって生成された新しいフィルターを取得するためのパイプラインを定義します。

PUT /_ingest/pipeline/generate_filter_ai
{
   "processors": [
     {
       "script": {
         "source": """ctx.prompt = "You are an expert in data organization for search and product categorization. Your task is to analyze the following product and identify the best dynamic facets that can be used in an e-commerce search experience. Product: " + ctx.name + "description: " + ctx.description + "Instructions: - Analyze the product name and description. - Extract only the dynamic facets (technological features or product characteristics that can be inferred from the description, try to create max 3 facets by characteristics found). Put the values into an array. Using key and value, e.g. dynamic_facets: [{ \"name\": \"Gaming Experience\", \"value\": \"Haptic Feedback\" },{ \"name\": \"Gaming Experience\", \"value\": \"Adaptive Triggers\" } - Return only a JSON."
         """
       }
     },
     {
       "inference": {
         "model_id": "generate_filter_ia",
         "input_output": {
           "input_field": "prompt",
           "output_field": "result"
         }
       }
     },
     {
       "gsub": {
         "field": "result",
         "pattern": "```json",
         "replacement": ""
       }
     },
     {
       "json" : {
         "field" : "result",
         "strict_json_parsing": false,
         "add_to_root" : true
       }
     },
     {
       "remove": {
         "field": "result"
       }
     },
     {
       "remove": {
         "field": "prompt"
       }
     }
   ]
}

「PlayStation 5」製品用にこのパイプラインのシミュレーションを実行すると、次のようになります。

驚異的なゲーム体験: 驚異的なグラフィックスに驚嘆し、新しい PS5 の機能を体験してください。

息を呑むような没入感: 触覚フィードバック、アダプティブ トリガー、3D オーディオ テクノロジーのサポートにより、より奥深いゲーム体験を体験できます。

スリムなデザイン: PS5 デジタル エディションでは、洗練されたコンパクトなデザインで強力なゲーミング テクノロジーをゲーマーに提供します。

1TB のストレージ: 1TB の内蔵 SSD ストレージで、お気に入りのゲームをいつでもプレイできます。

下位互換性とゲームブースト: PS5 コンソールは 4,000 以上の PS4 ゲームをプレイできます。Game Boost を使用すると、最高の PS4 コンソール ゲームの一部で、より高速でスムーズなフレーム レートを楽しむことができます。

このシミュレーションから生成されたプロンプト出力を観察してみましょう。

{
 "docs": [
   {
     "doc": {
       "_index": "index",
       "_version": "-3",
       "_id": "1",
       "_source": {
         "name": "Play Station 5",
         "result": """```json
{
 "dynamic_facets": [
   { "name": "Storage Capacity", "value": "1TB SSD" },
   { "name": "Graphics Technology", "value": "Stunning Graphics" },
   { "name": "Audio Technology", "value": "3D Audio" }
 ]
}
```""",
         "description": "Stunning Gaming: Marvel at stunning graphics and experience the features of the new PS5. Breathtaking Immersion: Discover a deeper gaming experience with support for haptic feedback, adaptive triggers, and 3D Audio technology. Slim Design: With the PS5 Digital Edition, gamers get powerful gaming technology in a sleek, compact design. 1TB of Storage: Have your favorite games ready and waiting for you to play with 1TB of built-in SSD storage. Backward Compatibility and Game Boost: The PS5 console can play over 4,000 PS4 games. With Game Boost, you can even enjoy faster, smoother frame rates in some of the best PS4 console games.",
         "model_id": "generate_filter_ia",
         "prompt": """You are an expert in data organization for search and product categorization. Your task is to analyze the following product and identify the best dynamic facets that can be used in an e-commerce search experience. Product: Play Station 5description: Stunning Gaming: Marvel at stunning graphics and experience the features of the new PS5. Breathtaking Immersion: Discover a deeper gaming experience with support for haptic feedback, adaptive triggers, and 3D Audio technology. Slim Design: With the PS5 Digital Edition, gamers get powerful gaming technology in a sleek, compact design. 1TB of Storage: Have your favorite games ready and waiting for you to play with 1TB of built-in SSD storage. Backward Compatibility and Game Boost: The PS5 console can play over 4,000 PS4 games. With Game Boost, you can even enjoy faster, smoother frame rates in some of the best PS4 console games.Instructions: - Analyze the product name and description. - Extract only the dynamic facets (technological features or product characteristics that can be inferred from the description, try create max 3 facets by characteristics found). Put the values like arrays. Using key and value, e.g. dynamic_facets: [{ "name": "Gaming Experience", "value": "Haptic Feedback" },{ "name": "Gaming Experience", "value": "Adaptive Triggers" } - Return only a JSON."""
       },
       "_ingest": {
         "timestamp": "2025-03-19T22:14:32.0161803Z"
       }
     }
   }
 ]
}

これで、AI によって生成されたファセットを保存するための新しいフィールドdynamic_facetsが新しいインデックスに追加されます。

PUT videogames_1
{
 "mappings": {
   "properties": {
     "name": { "type": "text" },
     "brand": { "type": "keyword" },
     "storage": { "type": "keyword" },
     "price": { "type": "float" },
     "description": { "type": "text" },
     "dynamic_facets": { "type": "nested",
     "properties": { "name": { "type": "keyword" },
                     "value": { "type": "keyword" } } }
   }
 }
}

Reindex API を使用して、プロセス中に generate_filter_ai パイプラインを適用し、 videogames インデックスを videogames_1 に再インデックスします。このパイプラインは、インデックス作成中に動的ファセットを自動的に生成します。

POST _reindex?wait_for_completion=false
{
 "source": {
   "index": "videogames"
 },
 "dest": {
   "index": "videogames_1",
   "pipeline": "generate_filter_ai"
 }
}

ここで、検索を実行して新しいフィルターを取得します。

GET videogames_1/_search
{
 "size": 0,
 "query": {
   "match": {
     "name": "nintendo"
   }
 },
 "aggs": {
   "dynamic_facets": {
     "nested": {
       "path": "dynamic_facets"
     },
     "aggs": {
       "facets": {
         "terms": {
           "field": "dynamic_facets.name"
         },
         "aggs": {
           "facets": {
             "terms": {
               "field": "dynamic_facets.value"
             }
           }
         }
       }
     }
   }
 }
}

結果:

"aggregations": {
   "dynamic_facets": {
     "doc_count": 3,
     "facets": {
       "doc_count_error_upper_bound": 0,
       "sum_other_doc_count": 0,
       "buckets": [
         {
           "key": "Frame Rate",
           "doc_count": 1,
           "facets": {
             "doc_count_error_upper_bound": 0,
             "sum_other_doc_count": 0,
             "buckets": [
               {
                 "key": "120 FPS",
                 "doc_count": 1
               }
             ]
           }
         },
         {
           "key": "Gaming Resolution",
           "doc_count": 1,
           "facets": {
             "doc_count_error_upper_bound": 0,
             "sum_other_doc_count": 0,
             "buckets": [
               {
                 "key": "4K",
                 "doc_count": 1
               }
             ]
           }
         },
         {
           "key": "Graphics Processing Power",
           "doc_count": 1,
           "facets": {
             "doc_count_error_upper_bound": 0,
             "sum_other_doc_count": 0,
             "buckets": [
               {
                 "key": "12 Teraflops",
                 "doc_count": 1
               }
             ]
           }
         }
       ]
     }
   }
 }

ファセットの実装を象徴するシンプルなフロントエンドを以下に示します。

ファセットの実装

提示された UI コードはここにあります。

まとめ

フィルターとファセットを作成する両方のアプローチには、利点と注意点があります。手動ルールに基づく従来のアプローチでは、制御が可能になりコストも削減されますが、継続的な更新が必要となり、新しい製品や機能に動的に適応することができません。

一方、AI と機械学習ベースのアプローチでは、ファセット抽出が自動化されるため、検索がより柔軟になり、手動による介入なしに新しい属性を発見できるようになります。ただし、このアプローチは実装と維持が複雑になる可能性があり、一貫した結果を確保するために調整が必要になります。

従来のアプローチと AI ベースのアプローチのどちらを選択するかは、ビジネスのニーズと複雑さによって異なります。データ属性が安定していて予測可能な、より単純なシナリオでは、従来のアプローチの方が効率的で保守が容易になり、インフラストラクチャと AI モデルによる不必要なコストを回避できます。一方、ML/AI を使用してファセットを抽出すると、検索エクスペリエンスが向上し、フィルタリングがよりインテリジェントになるため、大きな価値が付加されます。

重要なのは、自動化が投資を正当化するかどうか、あるいはより従来型のソリューションがすでにビジネス ニーズを効果的に満たしているかどうかを評価することです。

よくあるご質問

フィルターとは何ですか?

フィルターは、結果のセットを制限するために使用される事前定義された属性です。

ファセットとは何ですか?

ファセットは、検索の実行後に生成される絞り込みオプションの新しいリストです。

フィルターとファセットに対する従来のアプローチとは?

フィルターとファセットに対する従来のアプローチでは、検索を絞り込むために使用できる属性は固定され、計画されています。 このアプローチは予測可能性には優れていますが、動的な適応性に欠けており、再インデックスのために新しいフィルターの作成が必要となります。

フィルターやファセットに対する機械学習(ML)アプローチとは?

フィルターやファセットに対する機械学習(ML)のアプローチは、主にAIベースです。MLモデルはデータ属性を分析して、関連するフィルターとファセットを生成します。ML/AIは、事前定義されたルールに頼るのではなく、インデックス化されたデータの特性を活用します。

関連記事

判断リストによる検索クエリの関連性の評価

Jhon Guzmán

コンテキストのためのYou Know - パート1:ハイブリッド検索とコンテキストエンジニアリングの進化

Woody Walton

同義語APIを使用して同義語を自動化し、アップロードする方法

Andre Luiz

Elasticsearchでの後期相互作用モデルのスケーリング - パート 2

Peter Straßer

面倒な手間を省いたハイブリッド検索:リトリーバーによるハイブリッド検索の簡素化

Mike Pellegrini

最先端の検索体験を構築する準備はできましたか?

十分に高度な検索は 1 人の努力だけでは実現できません。Elasticsearch は、データ サイエンティスト、ML オペレーター、エンジニアなど、あなたと同じように検索に情熱を傾ける多くの人々によって支えられています。ぜひつながり、協力して、希望する結果が得られる魔法の検索エクスペリエンスを構築しましょう。

はじめましょう