How to Ensure Reproducibility in OpenAI Assistant API Responses?

I am building a service based on the OpenAI Assistant API. In my implementation, the assistant uses file_search to search through uploaded .txt files and generates responses based on the retrieved content.

For my use case, I need to reproduce the same response every time the API is executed with the same input. However, when I run the following code, I get different results each time.

run = self.client.beta.threads.runs.create_and_poll(
    thread_id=thread.id,
    assistant_id=self.assistant.id,
    tools=[{"type": "file_search"}],
    tool_choice={"type": "file_search"},
    temperature=0.0,
    top_p=1.0
)

Iā€™d like to know:

  1. Are there other parameters that affect response determinism, especially when using file_search?

  2. Is this varying behavior expected when using the Assistant API with file search?

  3. Are there any recommended approaches to achieve more consistent outputs when searching and responding based on file content?

1 Like