ClaudeCloudflare Developer PlatformMar 23, 2026, 12:00 AM

AI Search - Custom metadata filtering for AI Search

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

claudeenmodel: claude-sonnet-4-20250514

AI Search - Custom metadata filtering for AI Search

Key Points

  • Custom metadata filtering now available for AI Search
  • Support for up to 5 custom fields per instance
  • Advanced query filtering with comparison operators

Summary

Cloudflare AI Search now supports custom metadata filtering, enabling developers to define custom metadata fields and filter search results based on specific attributes like category, version, or any user-defined field.

Key Points

  • Custom metadata schema: Define up to 5 custom metadata fields per AI Search instance with support for text, number, and boolean data types
  • Flexible metadata attachment: Add metadata via S3-compatible headers for R2 buckets or HTML meta tags for websites
  • Advanced filtering: Use custom metadata fields alongside built-in attributes like folder and timestamp in search queries
  • Query operators: Support for comparison operators like $gte for numeric fields in filter expressions
  • API integration: Full REST API support for creating instances with custom metadata schemas and performing filtered searches

Full Translation

Translations

A translation section that keeps the flow of the original article.

claudejamodel: claude-sonnet-4-20250514

AI Search - AI Search用カスタムメタデータフィルタリング

AI Search用カスタムメタデータフィルタリング

2026年3月23日

AI Searchでカスタムメタデータフィルタリングがサポートされ、独自のメタデータフィールドを定義し、カテゴリ、バージョン、または定義したカスタムフィールドなどの属性に基づいて検索結果をフィルタリングできるようになりました。

カスタムメタデータスキーマの定義

AI Searchインスタンスごとに最大5つのカスタムメタデータフィールドを定義できます。各フィールドには名前とデータ型(textnumber、またはboolean)があります:

curl -X POST https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/instances \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {API_TOKEN}" \
  -d '{
    "id": "my-instance",
    "type": "r2",
    "source": "my-bucket",
    "custom_metadata": [
      {
        "field_name": "category",
        "data_type": "text"
      },
      {
        "field_name": "version",
        "data_type": "number"
      },
      {
        "field_name": "is_public",
        "data_type": "boolean"
      }
    ]
  }'

ドキュメントへのメタデータの追加

メタデータの添付方法はデータソースによって異なります:

  • R2 bucket: オブジェクトをアップロードする際にS3互換のカスタムヘッダー(x-amz-meta-*)を使用してメタデータを設定します。例については[R2 custom metadata](R2 custom metadata)を参照してください。
  • Website: HTMLページに<meta>タグを追加します。詳細については[Website custom metadata](Website custom metadata)を参照してください。

検索結果のフィルタリング

検索クエリでカスタムメタデータフィールドを、foldertimestampなどの組み込み属性と併用できます:

curl https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai-search/instances/{NAME}/search \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {API_TOKEN}" \
  -d '{
    "messages": [
      {
        "content": "How do I configure authentication?",
        "role": "user"
      }
    ],
    "ai_search_options": {
      "retrieval": {
        "filters": {
          "category": "documentation",
          "version": {
            "$gte": 2.0
          }
        }
      }
    }
  }'

詳細については[metadata filtering documentation](metadata filtering documentation)をご覧ください。