I did some testing and found that the issue seems to be related to attachments for the file_search
tool when the file doesn’t exist in the vector store.
A lot of use cases probably rely on the assumption that attachments automatically associate the file_id
with the vector store behind the scenes. But now, if the file_id
isn’t in the vector store, it just fails.
Reproducing the issue
The simplest way to see this in action is:
1. Upload a file
curl --location 'https://api.openai.com/v1/files' \
--header 'OpenAI-Beta: assistants=v2' \
--header 'Authorization: ••••••' \
--form 'purpose="assistants"' \
--form 'file=@"...myfile.docx"'
{
"object": "file",
"id": "yourfileid",
"purpose": "assistants",
"filename": "myfile.docx",
"bytes": 11244,
"created_at": 1738859492,
"status": "processed",
"status_details": null
}
2. Create a thread using the file
curl --location 'https://api.openai.com/v1/threads' \
--header 'OpenAI-Beta: assistants=v2' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
"messages": [
{
"role": "user",
"content": "What is the associated document about?",
"attachments": [
{
"file_id": "yourfileid",
"tools": [{ "type": "file_search" }]
}
]
}
]
}'
{
"error": {
"message": "Failed to create file operation.",
"type": "server_error",
"param": null,
"code": null
}
}
Basically, if you don’t add the file to the vector store before creating the thread (or attaching it to a message), the request fails. But if you create the vector store with the file_id
first, everything works fine.
From what I understand, when you attach files as message attachments in a thread, a vector store should be automatically created and associated with the thread. If a vector store already exists for the thread, the new file should be added to it.
As stated in the docs:
“You can also attach files as Message attachments on your thread. Doing so will create another vector_store associated with the thread, or, if there is already a vector store attached to this thread, attach the new files to the existing thread vector store. When you create a Run on this thread, the file search tool will query both the vector_store from your assistant and the vector_store on the thread.”