Introduction to OpenAI Responses API (10) - File search
I have summarized the "File search" feature of the "Responses API".
Previous
1. File search
"File search" is one of the built-in tools of the "Responses API". It allows you to add information retrieved from a vector store via semantic and keyword search to your prompt. You prepare the vector store in advance by uploading multiple files. The model decides whether or not to perform a file search based on user input.

2. Vector store usage fees
Vector store usage fees are determined by chunk size and the corresponding embeddings. You are charged based on the total storage used by all vector stores.
・Free up to 1GB
・$0.10 per GB/day for storage exceeding 1GB
3. Preparing the OpenAI API
The steps to prepare the "OpenAI API" in "Google Colab" are as follows.
(1) Install packages.
Install the "Responses API" and "Agent SDK" packages.
# パッケージのインストール
!pip install -U openai openai-agents(2) Prepare environment variables.
Set "OPENAI_API_KEY" using the key icon on the left, then execute the following cell.
import os
from google.colab import userdata
# 環境変数の準備 (左端の鍵アイコンでOPENAI_API_KEYを設定)
os.environ["OPENAI_API_KEY"] = userdata.get("OPENAI_API_KEY")(3) Prepare the client.
from openai import OpenAI
# クライアントの準備
client = OpenAI()4. Create a vector store
(1) Create a vector store.
# ベクトルストアの作成
vector_store = client.vector_stores.create(
name="My Vector Store",
)
print(vector_store.id)(2) Upload files to Colab.
This time, I uploaded the "OpenAI GPT-4.5 System Card" PDF.

(3) Upload files to the OpenAI server.
# ファイルをOpenAIのサーバにアップロード
client.vector_stores.files.upload_and_poll(
vector_store_id=vector_store.id,
file=open("gpt-4-5-system-card-2272025.pdf", "rb")
)You can also check the uploaded files in the Dashboard Storage.

5. Execute File search
(1) Prepare the message list.
# メッセージリストの準備
messages = [
{
"role": "user",
"content": "GPT-4.5の性能について教えて。",
}
](2) Execution of inference.
# 推論の実行
response = client.responses.create(
model="gpt-4o",
tools=[
{
"type": "file_search",
"vector_store_ids": [vector_store.id]
}
],
input=messages,
)
print(response.output_text)GPT-4.5は、より広範な知識ベースとユーザーの意図に対する整合性の強化、感情的な知性の向上を特徴としています。具体的には、執筆、プログラミング、実践的な問題解決において、より自然なインタラクションを可能にし、誤情報(ハルシネーション)の発生が減少しています。
また、GPT-4.5は、高度なステアラビリティ(操作性)と、人間の意図やニーズをより深く理解することで、創造的な執筆やデザインの手助けをする能力に優れています。
安全性についても、GPT-4.5は従来のモデルと比較して大幅な改良が加えられていることが報告されています。リスク評価では、中リスクとして分類されており、特にC解 Persuasion(説得)において優れた性能を示しています。6. Output and Citations
The model output using "File search" includes the following information:
・file_search_call: Output item containing the search call ID.
・message: Output item containing the following:
・message.content[0].text: Output text
・message.content[0].annotations: List of citation URLs
(1) Confirmation of output and citations.
# 出力と引用の確認
for event in response.output:
print(event)ResponseFileSearchToolCall(
id='fs_67d6c6b4722c8191ba52063f1335fa5b0ce16a9a934dfca4',
queries=[
'GPT-4.5の性能について教えて',
'GPT-4.5 performance',
'GPT-4.5 capabilities',
'how does GPT-4.5 perform',
'GPT-4.5 features'
],
status='completed',
type='file_search_call',
results=None
)
ResponseOutputMessage(
id='msg_67d6c6b7c9808191910be46eca1ecad50ce16a9a934dfca4',
content=[
ResponseOutputText(
annotations=[
AnnotationFileCitation(
file_id='file-FYBCZaopwF7Sujt946yE86',
index=130,
type='file_citation',
filename='gpt-4-5-system-card-2272025.pdf'
),
AnnotationFileCitation(
file_id='file-FYBCZaopwF7Sujt946yE86',
index=212,
type='file_citation',
filename='gpt-4-5-system-card-2272025.pdf'
),
AnnotationFileCitation(
file_id='file-FYBCZaopwF7Sujt946yE86',
index=326,
type='file_citation',
filename='gpt-4-5-system-card-2272025.pdf'
),
AnnotationFileCitation(
file_id='file-FYBCZaopwF7Sujt946yE86',
index=326,
type='file_citation',
filename='gpt-4-5-system-card-2272025.pdf'
)
],
text='''
GPT-4.5は、より広範な知識ベースとユーザーの意図に対する整合性の強化、
感情的な知性の向上を特徴としています。具体的には、執筆、プログラミング、
実践的な問題解決において、より自然なインタラクションを可能にし、
誤情報(ハルシネーション)の発生が減少しています。
また、GPT-4.5は、高度なステアラビリティ(操作性)と、
人間の意図やニーズをより深く理解することで、
創造的な執筆やデザインの手助けをする能力に優れています。
安全性についても、GPT-4.5は従来のモデルと比較して
大幅な改良が加えられていることが報告されています。
リスク評価では、中リスクとして分類されており、
特にC解 Persuasion(説得)において優れた性能を示しています。
''',
type='output_text'
)
],
role='assistant',
status='completed',
type='message'
)7. Supported Files
Supported files are as follows:

8. Limitations
Limitations are as follows:
・Projects are limited to a total size of 100 GB for all files.
・Vector stores are limited to a total of 10,000 files.
・Individual files are up to 512 MB (approximately 5 million tokens per file)
