For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
メインナビゲーション
Theme

ファイル検索

モデルが回答を生成する前に、ファイルから関連情報を検索できるようにします。

ファイル検索は Responses API で利用できるツールです。 モデルはセマンティック検索とキーワード検索を使って、アップロード済みのファイルで構成されるナレッジベースから情報を取得できます。 ベクトルストアを作成してファイルをアップロードし、そのナレッジベース(vector_stores)にモデルがアクセスできるようにすると、モデルがもともと持っている知識を補えます。

ベクトルストアとセマンティック検索の仕組みについては、検索ガイドを参照してください。

このツールは OpenAI がホストして管理するため、ツールを実行するコードを自分で実装する必要はありません。 モデルがファイル検索を使うと判断すると、自動的にツールを呼び出し、ファイルから情報を取得して結果を返します。

使い方

Responses API でファイル検索を使うには、あらかじめベクトルストアにナレッジベースを用意し、ファイルをアップロードしておく必要があります。

ナレッジベースの準備ができたら、モデルが利用できるツールの一覧に file_search を追加し、検索対象のベクトルストアの一覧を指定できます。

ファイル検索ツール
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-6-astra",
    input="What is deep research by OpenAI?",
    tools=[{"type": "file_search", "vector_store_ids": ["<vector_store_id>"]}],
)
print(response)

モデルがこのツールを呼び出すと、レスポンスには次の出力項目が含まれます。

  1. 出力項目 file_search_call には、ファイル検索の呼び出し ID が含まれます。
  2. 出力項目 message には、モデルの回答と、引用元のファイルを示す情報が含まれます。
ファイル検索のレスポンス
{
  "output": [
    {
      "type": "file_search_call",
      "id": "fs_67c09ccea8c48191ade9367e3ba71515",
      "status": "completed",
      "queries": ["What is deep research?"],
      "search_results": null
    },
    {
      "id": "msg_67c09cd3091c819185af2be5d13d87de",
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Deep research is a sophisticated capability that allows for extensive inquiry and synthesis of information across various domains. It is designed to conduct multi-step research tasks, gather data from multiple online sources, and provide comprehensive reports similar to what a research analyst would produce. This functionality is particularly useful in fields requiring detailed and accurate information...",
          "annotations": [
            {
              "type": "file_citation",
              "index": 992,
              "file_id": "file-2dtbBZdjtDKS8eqWxqbgDi",
              "filename": "deep_research_blog.pdf"
            },
            {
              "type": "file_citation",
              "index": 992,
              "file_id": "file-2dtbBZdjtDKS8eqWxqbgDi",
              "filename": "deep_research_blog.pdf"
            },
            {
              "type": "file_citation",
              "index": 1176,
              "file_id": "file-2dtbBZdjtDKS8eqWxqbgDi",
              "filename": "deep_research_blog.pdf"
            },
            {
              "type": "file_citation",
              "index": 1176,
              "file_id": "file-2dtbBZdjtDKS8eqWxqbgDi",
              "filename": "deep_research_blog.pdf"
            }
          ]
        }
      ]
    }
  ]
}

検索のカスタマイズ

検索結果の件数制限

Responses API のファイル検索ツールでは、ベクトルストアから取得する検索結果の件数を指定できます。件数を制限すると、トークン使用量を抑え、レイテンシを短縮できますが、回答の品質が低下する場合があります。

検索結果の件数制限
response = client.responses.create(
    model="gpt-6-astra",
    input="What is deep research by OpenAI?",
    tools=[
        {
            "type": "file_search",
            "vector_store_ids": ["<vector_store_id>"],
            "max_num_results": 2,
        }
    ],
)
print(response)

レスポンスへの検索結果の追加

出力テキストには注釈(ファイルへの参照)が表示されますが、デフォルトではファイル検索の呼び出しで検索結果は返されません。

検索結果をレスポンスに含めるには、レスポンスの作成時に include パラメータを指定します。

レスポンスへの検索結果の追加
response = client.responses.create(
    model="gpt-6-astra",
    input="What is deep research by OpenAI?",
    tools=[
        {
            "type": "file_search",
            "vector_store_ids": ["<vector_store_id>"],
        }
    ],
    include=["file_search_call.results"],
)
print(response)

メタデータによる絞り込み

ファイルのメタデータを使って検索結果を絞り込めます。詳しい手順については、検索ガイドの次の項目を参照してください。

メタデータによる絞り込み
response = client.responses.create(
    model="gpt-6-astra",
    input="What is deep research by OpenAI?",
    tools=[
        {
            "type": "file_search",
            "vector_store_ids": ["<vector_store_id>"],
            "filters": {
                "type": "in",
                "key": "category",
                "value": ["blog", "announcement"],
            },
        }
    ],
)
print(response)

対応ファイル形式

MIME タイプが text/ で始まる場合、エンコーディングには utf-8、utf-16、ascii のいずれかを使用する必要があります。

ファイル形式 MIME タイプ
.c text/x-c
.cpp text/x-c++
.cs text/x-csharp
.css text/css
.doc application/msword
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.go text/x-golang
.html text/html
.java text/x-java
.js text/javascript
.json application/json
.md text/markdown
.pdf application/pdf
.php text/x-php
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.py text/x-python
.py text/x-script.python
.rb text/x-ruby
.sh application/x-sh
.tex text/x-tex
.ts application/typescript
.txt text/plain

利用上の注意

API の対応状況レート制限備考

Build
500 RPM

Launch と Grow
1000 RPM

料金
ZDR とデータレジデンシー