-
-
Notifications
You must be signed in to change notification settings - Fork 640
Description
Description
On the OpenAI API, the File Search Tool / Searching a vector store supports nesting multiple CompoundFilters in the "filters" parameter to create a complex expression.
The library supports creating API requests of that type but when OpenAI returns the data the library errors while trying to parse the "filters" object returned via the API.
The errors you get are:
[Wed Aug 27 15:15:37 2025] PHP Warning: Undefined array key "key" in /home/ashish/workspace/college-access-poc/vendor/openai-php/client/src/Responses/Responses/Tool/FileSearchComparisonFilter.php on line 40
[Wed Aug 27 15:15:37 2025] PHP Warning: Undefined array key "value" in /home/ashish/workspace/college-access-poc/vendor/openai-php/client/src/Responses/Responses/Tool/FileSearchComparisonFilter.php on line 42
When the API response "tools" key looks like this:
"tools": [
{
"type": "file_search",
"filters": {
"type": "and",
"filters": [
{
"type": "and",
"filters": [
{
"type": "ne",
"key": "state",
"value": "ny"
},
{
"type": "ne",
"key": "state",
"value": "ca"
}
]
}
]
},
"max_num_results": 5,
"ranking_options": {
"ranker": "auto",
"score_threshold": 0.1
},
"vector_store_ids": [
"vs_68a38ae83c288191a1071eeb288e8fb5",
"vs_68adf7d2880481919bde619efeb1526f"
]
}
],
https://platform.openai.com/docs/api-reference/vector_stores/search
Steps To Reproduce
- Create an OpenAI vector store and add some documents
- Use the Responses API with a file search tool and a nested filter object like this:
$result = $client->responses()->create([
'model' => 'gpt-4.1-2025-04-14',
'input' => $data["search"],
'instructions' => $data["prompt"],
'include' => ['file_search_call.results'],
'temperature' => 0,
'tools' => [
[
'type' => 'file_search',
'vector_store_ids' => [$data["vector_id"]],
'filters' => [
"type" => "or",
"filters" => [[
"type" => "or",
"filters" => [
[ "type" => "eq", "key" => "state", "value" => "ny" ],
[ "type" => "ne", "key" => "state", "value" => "ca" ],
],
]],
]
]
]
]);
OpenAI PHP Client Version
v0.16.0
PHP Version
8.3.24
Notes
The issue is in how FileSearchTool and FileSearchCompoundFilter parse the filters that come back from OpenAI in this case.
It looked like some refactoring would need to be done to allow a list of FileSearchCompoundFilter in FileSearchTool as well as allowing FileSearchCompoundFilter to hold FileSearchCompoundFilter children itself.