Vector stores
Search a vector store
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.
query
string | string[]
krävs
A query string for a search
rewrite_query
boolean
Whether to rewrite the natural language query for vector search.
filters
OpenAI.ComparisonFilter | OpenAI.CompoundFilter
A filter to apply based on file attributes.
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
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.
type
enum
krävs
Type of operation: and or or.
filters
(OpenAI.ComparisonFilter | OpenAI.CompoundFilter)[]
krävs
Array of filters to combine. Items can be ComparisonFilter or CompoundFilter.
ranking_options
OpenAI.VectorStoreSearchRequestRankingOptions
ranker
enum
Svar
The request has succeeded.
Brödtext
object
enum
krävs
The object type, which is always vector_store.search_results.page
data
OpenAI.VectorStoreSearchResultItem[]
krävs
The list of search result items.
has_more
boolean
krävs
Indicates if there are more results to fetch.
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
}