Search vector store
client.vectorStores.search(stringvectorStoreID, VectorStoreSearchParams { query, filters, max_num_results, 2 more } body, RequestOptionsoptions?): Page<VectorStoreSearchResponse { attributes, content, file_id, 2 more } >
POST/vector_stores/{vector_store_id}/search
Search a vector store for relevant chunks based on a query and file attributes filter.
Search vector store
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
// Automatically fetches more pages as needed.
for await (const vectorStoreSearchResponse of client.vectorStores.search('vs_abc123', {
query: 'string',
})) {
console.log(vectorStoreSearchResponse.file_id);
}{
"object": "vector_store.search_results.page",
"search_query": "What is the return policy?",
"data": [
{
"file_id": "file_123",
"filename": "document.pdf",
"score": 0.95,
"attributes": {
"author": "John Doe",
"date": "2023-01-01"
},
"content": [
{
"type": "text",
"text": "Relevant chunk"
}
]
},
{
"file_id": "file_456",
"filename": "notes.txt",
"score": 0.89,
"attributes": {
"author": "Jane Smith",
"date": "2023-01-02"
},
"content": [
{
"type": "text",
"text": "Sample text content from the vector store."
}
]
}
],
"has_more": false,
"next_page": null
}
Returns Examples
{
"object": "vector_store.search_results.page",
"search_query": "What is the return policy?",
"data": [
{
"file_id": "file_123",
"filename": "document.pdf",
"score": 0.95,
"attributes": {
"author": "John Doe",
"date": "2023-01-01"
},
"content": [
{
"type": "text",
"text": "Relevant chunk"
}
]
},
{
"file_id": "file_456",
"filename": "notes.txt",
"score": 0.89,
"attributes": {
"author": "Jane Smith",
"date": "2023-01-02"
},
"content": [
{
"type": "text",
"text": "Sample text content from the vector store."
}
]
}
],
"has_more": false,
"next_page": null
}