I’ve read through a few posts here and the API references, and it seems that there isn’t any way to filter / limit the file search of a vector store to any specific files or set of files, lets say year <= 2010, or file name with “Apple”. I would like to confirm if that’s the case, or I’m missing any functionality that could implement such feature, or any ways to wrap the file search to an external tool / code. I’m mainly trying to avoid look-ahead bias, but creating a separate vector store for each year or company-year seems to be both tedious and a waste. Any ideas is appreciated. Thanks!
You are correct. In Assistants, all files in a vector store, and even multiple vector stores when one is attached to an assistant and another is created as a thread attachment, are combined, and the top-ranked document chunks are returned from the entirety.
The documentation is fragmented so it can’t really refer to a whole file unless short; just knowledge sections of high relevance.
You could be extra-clever, and do something unattempted as far as I know: offer a tool to switch the document data that will be found in a file search, one where the AI is instructed to call it first to use the appropriate data.
With that you could capture the tool call, and then rebuild the existing vector store ID with new documents from your subset list, only returning the tool_call once extraction and inclusion is complete. This could only really work on a one-user assistant and vector store, as you can’t change anything else while a run is in progress. Then the next tool call from the AI might be an internal one to its file search.
Much easier to map out the kind of pattern you want to provide the AI as selective informationn, and just provide your own Chat Completions knowledge tools, or even have them powered through a user interface.
i store each file separately and then attach them dynamically to the thread as necessary.
I’ve also been wanting this feature. It appears that it has been released today for the new Responses API. However, it also appears that the Assistants API will be deprecated. “…After we achieve full feature parity, we will announce a deprecation plan later this year, with a target sunset date in the first half of 2026.”
I haven’t played with it yet but this is the section on attribute filtering for date ranges:
https://platform.openai.com/docs/guides/retrieval?attributes-filter-example=date-range#attribute-filtering
Have you had a chance to play around with this yet? I’m trying to do a file search while filtering to search in one file. When I add the filter I get a response about not being able to find the information, but if I don’t filter on file (i.e. use the entire vector store), I get a response. Example request below:
response = client.responses.create(
model="gpt-4o-mini",
input="where do mermaids live",
tools=[{
"type": "file_search",
"vector_store_ids": ["<my_vs_id>"],
"max_num_results": 1,
"filters": {
"type": "eq",
"key": "filename",
"value": "mermaid_docs.pdf"
}
}],
)
In the retrieval API, allowing you to directly use vector store semantic search outside of a chat with an AI, you have new options that can nail down results by dropping files, something that otherwise would take a carefully-constructed or dynamic single-user vector store.
Those attributes are metadata you must store. They are not auto-generated.
For example, a date (shown as example) is not sourced from the file or upload or addition time. it is simply an integer of a name you made up, that “greater than” can be searched against.
You could add “ignore_after_chat_turn_length” as metadata with an integer as an example of an application’s clever use.
Was “filename” an assumption from an example? You must give that as one of the keys in the attribute parameter when creating a vector store file from a file ID.
BTW: “query rewriting” looks to be the anti-HyDE. It makes the input look LESS like document sections, LESS like true language model semantics to generate an attention-based embeddings state. Somebody thought embeddings was still a keyword search. It could work if there was a separate vector store layer with rewriting.
Watch your billing about this: it has higher value than semantic search than can only be an input to an AI model, but a per-call price is not directly mentioned, unlike the $0.01 per four usages of a Responses file search tool.
Thanks for your help and reply. My goal here is asking questions of documents, but they are state specific, and if someone if asking about Alaska, I would only want the results to come from that file. I understand what you’re saying that this can fragment the knowledge base - appreciate it and agree it’s maybe not the bets approach now.
Those attributes are metadata you must store . They are not auto-generated.
I wondered about this, but couldn’t find how to add user attributes to files, any idea where this is documented?
The retrieval documentation page is out-of-order, with the “setting” coming far after the “using”.
client.vector_stores.files.create(
vector_store_id="vs_123",
file_id="file_123",
attributes={
"region": "US",
"category": "Marketing",
"date": 1672531200 # Jan 1, 2023
}
)
Yes we cannot filter or rewrite_query using the assistants. This is available on the vector store apis themselves. If you need to filter, you would need to add the attributes
to the file, this can be done only through the API while adding the file to the vector or you can also later update the file with the attributes: https://platform.openai.com/docs/api-reference/vector-stores-files/updateAttributes
Then you can use the vector search API to filter the results:
https://platform.openai.com/docs/api-reference/vector-stores/search