Hoppa till huvudinnehåll

Den här webbläsaren stöds inte längre.

Uppgradera till Microsoft Edge och dra nytta av de senaste funktionerna och säkerhetsuppdateringarna, samt teknisk support.

Ladda ned Microsoft Edge Mer information om Internet Explorer och Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Vector stores

Search a vector store

POST /openai/v1/vector_stores/{vector_store_id}/search

Searchs a vector store.

Sökvägsparametrar

vector_store_id string krävs

The ID of the vector store to search.

Begärandetext

The request body.

Content-Type: application/json
query string | string[] krävs

A query string for a search

Något av följande:
string
string[]
rewrite_query boolean

Whether to rewrite the natural language query for vector search.

max_num_results integer
filters OpenAI.ComparisonFilter | OpenAI.CompoundFilter

A filter to apply based on file attributes.

Något av följande:
type enum krävs

Specifies the comparison operator: eq, ne, gt, gte, lt, lte, in, nin. - eq: equals - ne: not equal - gt: greater than - gte: greater than or equal - lt: less than - lte: less than or equal - in: in - nin: not in

eqnegtgteltlteinnin
key string krävs

The key to compare against the value.

value string | OpenAI.numeric | boolean | (string | OpenAI.numeric)[] krävs

The value to compare against the attribute key; supports string, number, or boolean types.

Något av följande:
string
number
boolean
(string | OpenAI.numeric)[]
type enum krävs

Type of operation: and or or.

andor
filters (OpenAI.ComparisonFilter | OpenAI.CompoundFilter)[] krävs

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

ranking_options OpenAI.VectorStoreSearchRequestRankingOptions
ranker enum
noneautodefault-2024-11-15
score_threshold number

Svar

The request has succeeded.

Brödtext

Content-Type: application/json
object enum krävs

The object type, which is always vector_store.search_results.page

vector_store.search_results.page
search_query string[] krävs
data OpenAI.VectorStoreSearchResultItem[] krävs

The list of search result items.

has_more boolean krävs

Indicates if there are more results to fetch.

next_page string | null krävs

Client error

Brödtext

Content-Type: application/json
error OpenAI.Error krävs
code string | null krävs
message string krävs
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Något av följande:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string krävs

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Brödtext

Content-Type: application/json
error OpenAI.Error krävs
code string | null krävs
message string krävs
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Något av följande:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string krävs

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Förfrågan

curl -X POST \
https://api.openai.com/v1/vector_stores/vs_abc123/search \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "What is the return policy?", "filters": {...}}'
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);
}
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
page = client.vector_stores.search(
    vector_store_id="vs_abc123",
    query="string",
)
page = page.data[0]
print(page.file_id)
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    page, err := client.VectorStores.Search(
        context.TODO(),
        "vs_abc123",
        openai.VectorStoreSearchParams{
            Query: openai.VectorStoreSearchParamsQueryUnion{
                OfString: openai.String("string"),
            },
        },
    )
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", page)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.vectorstores.VectorStoreSearchPage;
import com.openai.models.vectorstores.VectorStoreSearchParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        VectorStoreSearchParams params = VectorStoreSearchParams.builder()
            .vectorStoreId("vs_abc123")
            .query("string")
            .build();
        VectorStoreSearchPage page = client.vectorStores().search(params);
    }
}
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

page = openai.vector_stores.search("vs_abc123", query: "string")

puts(page)

Response

{
  "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
}
sv-se
Dina sekretessalternativ
  • Ansvarsfriskrivning för AI
  • Tidigare versioner
  • Blogg
  • Bidra
  • Sekretess
  • Konsumenthälsans integritet
  • Användningsvillkor
  • Varumärken
  • © Microsoft 2026