S there a difference between files attached to the assistant and files attached to messages?

I can attach file to assistant api in two way.

from openai import OpenAI
client = OpenAI()

my_assistant = client.beta.assistants.create(
    instructions="~~~",
    name="~~~",
    tools=[{"type": "retrieval"}],
    file_ids = [My files],
    model="gpt-4",
)
print(my_assistant)
from openai import OpenAI
client = OpenAI()

thread_message = client.beta.threads.messages.create(
  "thread_abc123",
  role="user",
  content="How does AI work? Explain it in simple terms.",
  file_ids = [My files],
)
print(thread_message)

In API and also in playground, these two way have difference in response.
It seems attach file to assistant level is way better thant attaching file to message level.

Is there a real difference in response logic?

Welcome to the OpenAI dev forum, @junhyun.park.

Using files in an assistant is a better way to add knowledge, while files in messages only persist for the thread they are part of.

Additionally, if used as knowledge bases, files in messages add to billing as each thread will need a new instance of files to be uploaded, which will multiply as threads grow, leading to increased storage costs per hour.

Creating a knowledge base using files in assistants also simplifies the task of keeping the assistant’s knowledge up-to-date, which can become cumbersome if the knowledge is stored in files within messages.

In my opinion, files in messages should be used for data relevant only to the user of the thread, not for the entire assistant.

6 Likes

Thank you for your response.

However, my question is still not resolved as I missed the details of the question.

I used the same file and questions and compared the two methods.
I noticed that when I attached the file to a message, it seemed to reference the information in the file worse than when I attached the file to assistant.

I’m wondering if this is simply an illusion due to randomness of GPT, or if attaching a file to assistant and message actually references the file in different ways.

The chat models are optimised for conversation.

Here’s a theory on why the behaviour you observed is happening.

The files that are uploaded as part of creating assistants are broken into chunks, embedded and stored in a vector DB on the OpenAI side. According to my understanding there’s a semantic search operation that happens at every run to load the messages and context for response generation.

When you send a file, that is supported by assistants, as part of the user message, there might be a function/tool that’s separately called by the assistant on the file that’s sent by user based on model’s discretion.

Hence it’s likely that the assistant is going to give better answer to the same prompt when the file is part of knowledge base as compared to file that’s shared by the user unless the prompt specifically asks to refer to the file shared by the user in their message.

1 Like

@sps I am facing following issue: Model Gives Incorrect Answers for Second Question in Thread with Retrieval Enabled

The problem is that the model starts hallucinating on the second message. However, I just tried uploading the knowledge base on the second message as well, and then the model doesn’t hallucinate.

Do you have any idea why this is happening?