Ranking_options in file_search not supported by API (contrary to info in docs)

I am trying to fine-tune the behavior of file_search by supplying a ranking_options parameter as described in the API docs:
https://platform.openai.com/docs/api-reference/vector-stores/search

My assistants code is as follows:

r_options = {
    # ignore chunks below 62.5% similarity score
    "score_threshold": 0.625,  
    "ranker": "default_2024_08_21"
}
assistant = client.beta.assistants.create(
    name="My Assistant Bot",
    instructions='You are a polite, helpful, and intelligent assistant',
    model='gpt-4-turbo-2024-04-09',
    temperature=0,
    tools=[{"type": "file_search"}],
    tool_resources={
        "file_search": {
            "vector_store_ids": [vs_id],
            "ranking_options": r_options
        }
    }
)

I believe the above code ought to modify the default behavior of file_search. Instead, I get the following error:

BadRequestError: Error code: 400 - {‘error’: {‘message’: “Unknown parameter: ‘tool_resources.file_search.ranking_options’.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘tool_resources.file_search.ranking_options’, ‘code’: ‘unknown_parameter’}}

Am I using ranking_options incorrectly? Or is ranking_options still not supported by the API? If it’s the latter, does anyone know when ranking_options will be supported by OpenAI?

You will have a good request with:

from openai import OpenAI
client = OpenAI()
assistant_id = None
vector_store_id = "vs_123412341234"
try:
    assistant = client.beta.assistants.create(
        description="Shows how to use ranker; documentation sucks",
        instructions="You are a world knowledge assistant.",
        metadata={"key":"value"},
        model="gpt-4o",
        name="ranker test",
        tools=[
            {
                "type": "file_search",
                "file_search": {
                    "max_num_results": 10,
                    "ranking_options": {
                        "ranker": "default_2024_08_21",
                        "score_threshold": 0.4,
                    }
                }
            }
        ],
        tool_resources={
            "file_search": {
                "vector_store_ids": [vector_store_id]
            }
        },
        # response_format=response_format,
        top_p=0.95,
    )
    assistant_id=assistant.id
    print("Assistant ID: ", assistant_id)
    import json
    print(json.dumps(assistant.model_dump(), indent=2))

except Exception as the_API_barfed:
    print(the_API_barfed)
    raise
if assistant_id:
    try:
        deleted_response = client.beta.assistants.delete(assistant_id)
        print(deleted_response)
    except Exception as the_API_delete_failed:
        print(the_API_delete_failed)

In this case, use of initial tool_resources requires a vector store ID.

1 Like