# File search disregards max num results

**URL:** <https://community.openai.com/t/file-search-disregards-max-num-results/896153>\
**Category:** Bugs\
**Tags:** gpt-4, api, assistants-api\
**Created:** [August 6, 2024, 9:42pm UTC](https://community.openai.com/t/file-search-disregards-max-num-results/896153 "2024-08-06T21:42:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![groverkartik25](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/groverkartik25/32/420759_2.png) [@groverkartik25](https://community.openai.com/u/groverkartik25)\
**Post date:** [August 6, 2024, 9:42pm UTC](https://community.openai.com/t/file-search-disregards-max-num-results/896153/1 "2024-08-06T21:42:51Z")

</div>

Even after specifying the “file\_search”: { “max\_num\_results”: 2 } in an assistant createRun the response sometimes fetching more than 2 annotations from the vector store. Is this a bug or is there another way to do this…  
CODE:

```auto
const createRunAndPollStatus = async (threadId, tools = [{ 
    "type": "file_search", 
    "file_search": { "max_num_results": 2 }
}]) => {
    const delay = ms => new Promise(res => setTimeout(res, ms));
    const maxAttempts = 10; // Adjust based on your needs
    
    try {
        const createResponse = await axios.post(`https://api.openai.com/v1/threads/${threadId}/runs`, {
            assistant_id: assistantId,
            tools: tools
        }, {
            headers: {
                "Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
                "OpenAI-Beta": "assistants=v2"
            }
        });

```

Thanks

---

<div class="post-metadata">

**Author:** ![HenryHung](https://avatars.discourse-cdn.com/v4/letter/h/a9a28c/32.png) [@HenryHung](https://community.openai.com/u/HenryHung)\
**Post date:** [August 20, 2024, 2:16pm UTC](https://community.openai.com/t/file-search-disregards-max-num-results/896153/2 "2024-08-20T14:16:08Z")

</div>

I’m using Azure OpenAI (API version 2024-07-01-preview) and have encountered the same problem. Even if I set this parameter to 3, the prompt token for file search in the GPT-4 assistant is still 16k, which equals 800 tokens \* 20 chunks.

I think there might be some bugs on OpenAI’s side causing this parameter to malfunction.

```python
assistant = await client.beta.assistants.create(
    model="<PLACEHOLDER>",
    name="<PLACEHOLDER>",
    instructions="<PLACEHOLDER>",
    tools=[
        {
            "type": "file_search",
            "file_search": {
                "max_num_results": 3
            }
        }
    ],
    tool_resources={"file_search": {"vector_store_ids": ["<PLACEHOLDER>"]}},
)

```

---

<div class="post-metadata">

**Author:** ![groverkartik25](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/groverkartik25/32/420759_2.png) [@groverkartik25](https://community.openai.com/u/groverkartik25)\
**Post date:** [August 30, 2024, 10:04pm UTC](https://community.openai.com/t/file-search-disregards-max-num-results/896153/3 "2024-08-30T22:04:24Z")

</div>

yes I think its a bug too. I also found out I had to specify it as a tool choice to make sure it gets called everytime:

```
    const createResponse = await axios.post(`https://api.openai.com/v1/threads/${threadId}/runs`, {
        assistant_id: assistantId,
        tools: tools,
        tool_choice: {
            type: "file_search"
        }

```

---

<div class="post-metadata">

**Author:** ![FreqShift](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/freqshift/32/453578_2.png) [@FreqShift](https://community.openai.com/u/FreqShift)\
**Post date:** [October 18, 2024, 4:37pm UTC](https://community.openai.com/t/file-search-disregards-max-num-results/896153/4 "2024-10-18T16:37:15Z")

</div>

Definitively a bug, a few experimentations lead me to believe the max\_results (coded at the assistant or run objects) is doubled. This workaround may help:

```python
max_results = assistant.tools[0].file_search.max_num_results
max_results = math.ceil(max_results / 2)
user_prompt = f"{user_prompt}\n - retrieve a maximum of {max_results} items"

```

---

<div class="post-metadata">

**Author:** ![baglan](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/baglan/32/512244_2.png) [@baglan](https://community.openai.com/u/baglan)\
**Post date:** [April 18, 2025, 1:02pm UTC](https://community.openai.com/t/file-search-disregards-max-num-results/896153/5 "2025-04-18T13:02:07Z")

</div>

The issue persists to this day. In Response API, tool calls to the File Search tool(to a vector store with a PDF book) counts to at least 20. The response output is maxxed at 20 can all filled with tool call.

This happens to only 4o-mini though. 4.1-mini and 4.1-nano make 1 call to the same vector store.
