Skip to main content
POST
/
v1
/
vector_stores
/
{vector_store_id}
/
search
from openai import OpenAI
client = OpenAI()

results = client.beta.vector_stores.search(
    vector_store_id="vs_abc123",
    query="How do I reset my password?",
    max_num_results=5
)

for result in results.data:
    print(f"Score: {result.score}")
    print(f"Content: {result.content}")
    print(f"File: {result.file_id}")
    print("---")
{
  "object": "list",
  "data": [
    {
      "type": "vector_store.search_result",
      "score": 0.95,
      "content": "To reset your password, click on the 'Forgot Password' link on the login page...",
      "file_id": "file-abc123",
      "metadata": {
        "page": 5,
        "chunk_id": "chunk_789"
      }
    },
    {
      "type": "vector_store.search_result",
      "score": 0.87,
      "content": "Password reset instructions: Navigate to Settings > Security > Reset Password...",
      "file_id": "file-abc456",
      "metadata": {
        "page": 12,
        "chunk_id": "chunk_456"
      }
    }
  ]
}
Search a vector store for relevant chunks based on a query and file attributes filter.

Path Parameters

vector_store_id
string
required
The ID of the vector store to search.

Request Body

query
string
required
A query string for a search. Can also be an array of strings for multi-query search.
max_num_results
integer
The maximum number of results to return. This number should be between 1 and 50 inclusive.
filters
object
A filter to apply based on file attributes.Example:
{
  "file_id": "file-abc123"
}
ranking_options
object
Ranking options for search.
rewrite_query
boolean
Whether to rewrite the natural language query for vector search.

Response

Returns a list of search results with relevant chunks.
data
array
Array of search result objects.
from openai import OpenAI
client = OpenAI()

results = client.beta.vector_stores.search(
    vector_store_id="vs_abc123",
    query="How do I reset my password?",
    max_num_results=5
)

for result in results.data:
    print(f"Score: {result.score}")
    print(f"Content: {result.content}")
    print(f"File: {result.file_id}")
    print("---")
{
  "object": "list",
  "data": [
    {
      "type": "vector_store.search_result",
      "score": 0.95,
      "content": "To reset your password, click on the 'Forgot Password' link on the login page...",
      "file_id": "file-abc123",
      "metadata": {
        "page": 5,
        "chunk_id": "chunk_789"
      }
    },
    {
      "type": "vector_store.search_result",
      "score": 0.87,
      "content": "Password reset instructions: Navigate to Settings > Security > Reset Password...",
      "file_id": "file-abc456",
      "metadata": {
        "page": 12,
        "chunk_id": "chunk_456"
      }
    }
  ]
}

Build docs developers (and LLMs) love