Search vector store
POSThttps:/api.openai.com/v1/vector_stores/{vector_store_id}/search
Search a vector store for relevant chunks based on a query and file attributes filter.
Path parameters
vector_store_idstringRequired
The ID of the vector store to search.
Request body
querystring or array
A query string for a searchquerystringRequired
queryarrayRequired
itemsstring
A list of queries to search for.
rewrite_querybooleanDefaults: false
Whether to rewrite the natural language query for vector search.max_num_resultsintegerDefaults: 10
The maximum number of results to return. This number should be between 1 and 50 inclusive.filtersobject
A filter to apply based on file attributes.Comparison Filterobject
A filter used to compare a specified attribute key to a given value using a defined comparison operation.typestringRequiredDefaults: eq
Specifies the comparison operator:
eq,ne,gt,gte,lt,lte.eq: equalsne: not equalgt: greater thangte: greater than or equallt: less thanlte: less than or equal
eqstring
nestring
gtstring
gtestring
ltstring
ltestring
keystringRequired
The key to compare against the value.valuestring or number or boolean
The value to compare against the attribute key; supports string, number, or boolean types.valuestringRequired
valuenumberRequired
valuebooleanRequired
Compound Filterobject
Combine multiple filters using
andoror.typestringRequired
Type of operation:
andoror.andstring
orstring
filtersarrayRequired
Array of filters to combine. Items can be
ComparisonFilterorCompoundFilter.Comparison Filterobject
A filter used to compare a specified attribute key to a given value using a defined comparison operation.typestringRequiredDefaults: eq
Specifies the comparison operator:
eq,ne,gt,gte,lt,lte.eq: equalsne: not equalgt: greater thangte: greater than or equallt: less thanlte: less than or equal
eqstring
nestring
gtstring
gtestring
ltstring
ltestring
keystringRequired
The key to compare against the value.valuestring or number or boolean
The value to compare against the attribute key; supports string, number, or boolean types.valuestringRequired
valuenumberRequired
valuebooleanRequired
itemsobject
ranking_optionsobject
Ranking options for search.rankerstringDefaults: auto
autostring
default-2024-11-15string
score_thresholdnumberDefaults: 0
Response
A page of search results from the vector store.
Example request
1 curl -X POST \2 https://api.openai.com/v1/vector_stores/vs_abc123/search \3 -H "Authorization: Bearer $OPENAI_API_KEY" \4 -H "Content-Type: application/json" \5 -d '{"query": "What is the return policy?", "filters": {...}}'
Example response
1 {2 "object": "vector_store.search_results.page",3 "search_query": "What is the return policy?",4 "data": [5 {6 "file_id": "file_123",7 "filename": "document.pdf",8 "score": 0.95,9 "attributes": {10 "author": "John Doe",11 "date": "2023-01-01"12 },13 "content": [14 {15 "type": "text",16 "text": "Relevant chunk"17 }18 ]19 },20 {21 "file_id": "file_456",22 "filename": "notes.txt",23 "score": 0.89,24 "attributes": {25 "author": "Jane Smith",26 "date": "2023-01-02"27 },28 "content": [29 {30 "type": "text",31 "text": "Sample text content from the vector store."32 }33 ]34 }35 ],36 "has_more": false,37 "next_page": null38 }
Built with