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_id
    string
    Required
    The ID of the vector store to search.

Request body

  • query
    string or array
    A query string for a search
    • query
      string
      Required
    • query
      array
      Required
      • items
        string
        A list of queries to search for.
  • rewrite_query
    boolean
    Defaults: false
    Whether to rewrite the natural language query for vector search.
  • max_num_results
    integer
    Defaults: 10
    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.
    • Comparison Filter
      object
      A filter used to compare a specified attribute key to a given value using a defined comparison operation.
      • type
        string
        Required
        Defaults: eq

        Specifies the comparison operator: eq, ne, gt, gte, lt, lte.

        • eq: equals
        • ne: not equal
        • gt: greater than
        • gte: greater than or equal
        • lt: less than
        • lte: less than or equal
        • eq
          string
        • ne
          string
        • gt
          string
        • gte
          string
        • lt
          string
        • lte
          string
      • key
        string
        Required
        The key to compare against the value.
      • value
        string or number or boolean
        The value to compare against the attribute key; supports string, number, or boolean types.
        • value
          string
          Required
        • value
          number
          Required
        • value
          boolean
          Required
    • Compound Filter
      object

      Combine multiple filters using and or or.

      • type
        string
        Required

        Type of operation: and or or.

        • and
          string
        • or
          string
      • filters
        array
        Required

        Array of filters to combine. Items can be ComparisonFilter or CompoundFilter.

        • Comparison Filter
          object
          A filter used to compare a specified attribute key to a given value using a defined comparison operation.
          • type
            string
            Required
            Defaults: eq

            Specifies the comparison operator: eq, ne, gt, gte, lt, lte.

            • eq: equals
            • ne: not equal
            • gt: greater than
            • gte: greater than or equal
            • lt: less than
            • lte: less than or equal
            • eq
              string
            • ne
              string
            • gt
              string
            • gte
              string
            • lt
              string
            • lte
              string
          • key
            string
            Required
            The key to compare against the value.
          • value
            string or number or boolean
            The value to compare against the attribute key; supports string, number, or boolean types.
            • value
              string
              Required
            • value
              number
              Required
            • value
              boolean
              Required
        • items
          object
  • ranking_options
    object
    Ranking options for search.
    • ranker
      string
      Defaults: auto
      • auto
        string
      • default-2024-11-15
        string
    • score_threshold
      number
      Defaults: 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": null
38
}
Built with