跳至主要内容

此浏览器不再受支持。

请升级到 Microsoft Edge 以使用最新的功能、安全更新和技术支持。

下载 Microsoft Edge 有关 Internet Explorer 和 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.

路径参数

vector_store_id string 必需

The ID of the vector store to search.

请求正文

The request body.

Content-Type: application/json
query string | string[] 必需

A query string for a search

下列类型作之一:
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.

下列类型作之一:
type enum 必需

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 必需

The key to compare against the value.

value string | OpenAI.numeric | boolean | (string | OpenAI.numeric)[] 必需

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

下列类型作之一:
string
number
boolean
(string | OpenAI.numeric)[]
type enum 必需

Type of operation: and or or.

andor
filters (OpenAI.ComparisonFilter | OpenAI.CompoundFilter)[] 必需

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

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

响应

The request has succeeded.

正文

Content-Type: application/json
object enum 必需

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

vector_store.search_results.page
search_query string[] 必需
data OpenAI.VectorStoreSearchResultItem[] 必需

The list of search result items.

has_more boolean 必需

Indicates if there are more results to fetch.

next_page string | null 必需

Client error

正文

Content-Type: application/json
error OpenAI.Error 必需
code string | null 必需
message string 必需
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
以下任何项:
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 必需

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

正文

Content-Type: application/json
error OpenAI.Error 必需
code string | null 必需
message string 必需
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
以下任何项:
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 必需

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

请求

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)

响应

{
  "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
}
zh-cn
你的隐私选择
  • AI 免责声明
  • 早期版本
  • 博客
  • 参与
  • 隐私
  • 消费者健康隐私
  • 使用条款
  • 商标
  • © Microsoft 2026