Search a vector store
POST /v1/vector_stores/{vector_store_id}/search runs a semantic search over a store and returns the most relevant chunks with scores. The request and response follow the OpenAI vector store search format for every backend, so an application can move from an OpenAI store to Bedrock Knowledge Bases or PG Vector without code changes. Searches are authenticated with the virtual key's vector store permissions and logged with the query and the returned file ids.
Scenario
A support assistant needs the three most relevant passages from the knowledge base before it drafts an answer, filtered to the customer's product line. It calls the search endpoint with the question and a metadata filter, gets the chunks with scores, and builds its prompt from them. The team checks what the search returns on the Vector Stores page before wiring it into the assistant.
Steps
-
Register or create the store and grant it to the key, see create a vector store.
-
Run a test search in the Admin UI. Open Vector Stores (
/ui/vector-stores), click the Test Vector Store tab, pick the store under Select Vector Store, type a query and click Search. Each result shows its text and Score, and expanding it shows the File ID, Filename and Attributes. -
Run the same search from your application.
curl -X POST http://localhost:4000/v1/vector_stores/vs_hr_policies/search \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"query": "parental leave policy","max_num_results": 5,"filters": {"type": "eq", "key": "department", "value": "people-ops"},"rewrite_query": false}' -
Check the log. Open Logs (
/ui/logs), open the request and read the Vector Store Requests section with the query, the store, the duration and the results.
Expected result
{
"object": "vector_store.search_results.page",
"search_query": "parental leave policy",
"data": [
{"file_id": "file-abc123", "filename": "leave-policy.pdf", "score": 0.91, "attributes": {"department": "people-ops"}, "content": [{"type": "text", "text": "Employees are entitled to sixteen weeks of paid parental leave."}]}
]
}
Request fields
| Field | Meaning |
|---|---|
query | A string or list of strings. |
max_num_results | Number of chunks to return. |
filters | Metadata filter in the OpenAI filter format, translated for the backend. |
ranking_options | Ranker and score threshold where the backend supports them. |
rewrite_query | Let the backend rewrite the query for retrieval. |
Using search results in a model call
Most applications do not call search directly. Passing vector_store_ids on a chat completion makes the gateway search and inject context automatically, see knowledge base retrieval. The RAG query endpoint adds reranking and generation in one call. The Responses API file_search tool also uses registered stores.
Cost and logging
Searches are logged with the query, the store and the returned file ids, and priced per query where the backend charges for search. Embedding calls made by the gateway to embed the query for backends that need it are logged under the same request.
Errors
| Status | What it means | Fix |
|---|---|---|
400 BadRequestError | query is missing, or the filter uses an operator the backend does not support. | Send a query, and keep filters to eq, ne, gt, gte, lt, lte, and and or. |
| 400 on an embedding field | The body tries to pick the embedding model or its credentials, which belong to the store. | Remove the field. The store's configuration decides the embedding model. |
401 AuthenticationError | The virtual key is wrong, or the store's credential is invalid. | Use a live key and check the credential on the store. |
401 key_vector_store_access_denied (or team_ or user_) | The key, its team or its user lists vector stores and leaves this one out, or vector_store_deny_by_default is on and none of them grants it. | Grant the store on the key and its team. |
403 Access denied: You do not have permission to access this vector store | The registered store belongs to another team. | Use a key of the owning team. |
404 NotFoundError from the provider | An id the gateway has not registered is sent to the provider as is, and the provider does not know it. | Check the id, or register the store on the Vector Stores page. |
500 Unable to validate vector store access | The gateway could not read the store's row to check access, so it refused the call. | Check the database and Redis connections, see Logs. |
Empty data | The store has no indexed documents, or the query embedding model differs from the one that built the index. | Add documents, and for Milvus, MongoDB and Valkey use the embedding model that created the vectors. |
Logs
| Level | Line | What it means | Action |
|---|---|---|---|
| WARNING | Failed to resolve vector store id=<id> from registry: <cause> | The gateway could not read the store from its in-memory registry and tried the database or the provider instead. | Action needed when it repeats. Check the store registration and the database connection. |
| WARNING | Failed to resolve vector store id=<id> from shared cache: <cause> | The store's row could not be read from the database or its cache, and the call answered 500 Unable to validate vector store access. | Action needed. Check the database and Redis connections. |
Related
- Create a vector store and vector store files.
- Knowledge base retrieval and RAG query.
- Rerank for re-scoring the results.
- Vector Stores page.
Providers
The gateway's endpoint support matrix marks 11 provider integrations as supporting this endpoint:
Azure, Azure AI, AWS - Bedrock, Google AI Studio - Gemini, Milvus, MongoDB Atlas (mongodb), OpenAI, PG Vector, AWS S3 Vectors, Valkey (valkey), Google - Vertex AI.