Skip to main content

Create a vector store

A vector store holds embedded documents that models and applications search for relevant context. The gateway serves the OpenAI vector stores API for creating and managing stores, and keeps a registry of stores hosted on different backends, so one search API reaches OpenAI vector stores, Azure AI Search, Bedrock Knowledge Bases, Vertex AI Search, PG Vector, Milvus, Amazon S3 Vectors, MongoDB, Valkey and others. A store that is registered on the gateway can be granted to keys and teams, searched through one endpoint, and attached to chat completions.

Scenario​

A people operations team wants its handbook searchable by the company assistant. The admin creates a new vector store through the gateway on the company's OpenAI account, the team adds the handbook files to it, and the admin grants the store to the assistant's key. A product team already has a Bedrock Knowledge Base, so the admin registers that existing store instead of creating a new one, and both stores are searched the same way.

Steps​

  1. Create a store through the API, or register an existing one in the Admin UI.

    curl -X POST http://localhost:4000/v1/vector_stores \
    -H "Authorization: Bearer $SPANWAY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name": "hr-policies", "custom_llm_provider": "openai", "metadata": {"team": "people-ops"}}'

    custom_llm_provider picks the backend. A store created this way exists at the provider only. It is not registered on the gateway, so it does not show in the Admin UI and cannot be granted to keys or teams until you register it in step 2 with its new id.

  2. To register the new store, or a store that already exists at a provider, open Vector Stores (/ui/vector-stores) in the Admin UI, click + Add Vector Store, pick the Provider, enter the Vector Store ID the provider knows, fill the provider fields (for example AWS Region for Amazon Bedrock), give it a Vector Store Name and a Description and click Create. The same registration through the API is POST /vector_store/new, see vector store management.

  3. Grant the store to a key. Open Virtual Keys (/ui/api-keys), open the key, click Settings, pick the store under Vector Stores and save.

  4. Confirm the store is registered. Open Vector Stores, find the store in the Manage Vector Stores tab, and run a test query on the Test Vector Store tab once documents are in it.

Expected result​

{"id": "vs_hr_policies", "object": "vector_store", "name": "hr-policies", "status": "completed", "created_at": 1760441234, "file_counts": {"in_progress": 0, "completed": 0, "failed": 0, "cancelled": 0, "total": 0}, "metadata": {"team": "people-ops"}}

Once registered in step 2, the store appears in the Manage Vector Stores table with source DB, and keys granted the store can search it right away.

Endpoints​

{{ops:^/v1/vector_stores(/{vector_store_id})?$}}

GET /v1/vector_stores lists every store the provider holds and does not filter by the key's grants, so use GET /vector_store/list for the stores registered on the gateway that the key may use. GET /v1/vector_stores/{vector_store_id} returns one store, POST /v1/vector_stores/{vector_store_id} changes its name, metadata or expiry at the provider, and DELETE removes it at the provider only. The gateway registration stays until you also call POST /vector_store/delete or click Delete on the store in the Admin UI.

A user who created a store with target_model_names can list those managed stores with GET /v1/vector_stores/managed, which takes limit (1 to 100) and after for paging.

Registering stores in config​

Stores that already exist on a backend can also be registered in config.yaml.

vector_store_registry:
- vector_store_name: product-docs
spanway_params:
vector_store_id: my-kb-id
custom_llm_provider: bedrock
aws_region_name: us-east-1
vector_store_description: Product documentation knowledge base
- vector_store_name: tickets
spanway_params:
vector_store_id: tickets
custom_llm_provider: pg_vector
api_base: os.environ/PG_VECTOR_API_BASE
api_key: os.environ/PG_VECTOR_API_KEY

vector_store_description is shown to models and users so they can pick the right store. Config stores are read only in the Admin UI.

Access control​

Keys and teams are granted stores through object_permission.vector_stores. With general_settings.vector_store_deny_by_default: true, a store must be granted explicitly before a key can search it, and a key needs both its own grant and its team's. Creating, updating and deleting stores through the management routes is limited to proxy admins, and can be hidden from internal users with the disable_vector_stores_for_internal_users UI setting.

Adding documents​

Upload files to a store with the vector store files endpoints, or use RAG ingest to extract, chunk and embed a document in one call. Then search with vector store search or attach the store to chat completions as described in knowledge base retrieval.

Errors​

StatusWhat it meansFix
400 BadRequestErrorNo provider could be determined, or a provider field such as the region is missing.Send custom_llm_provider, or set the x-spanway-model header to a deployment of the provider.
401 AuthenticationErrorThe virtual key is wrong, or the provider credential is invalid.Use a live key and check the provider credential.
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 to the key and its team.
403 Access denied: You do not have permission to access this vector storeThe registered store belongs to another team.Use a key of the owning team, or ask a proxy admin.
403 on /vector_store/new, /vector_store/update or /vector_store/deleteOnly proxy admins may change the gateway registry.Use a proxy admin key, or add the route to the key's allowed_routes.
404 NotFoundErrorThe store id does not exist at the provider.Check the id in the provider's console.
500 Database not connected on the management routesThe gateway runs without a database, so registrations cannot be stored.Configure DATABASE_URL, or register stores in config.yaml.
500 Could not create the vector store. The gateway log has the cause. (or update, delete, list, read)An unexpected failure, such as a database error, on a management route. The cause is only in the gateway log.Look for the matching Error creating vector store line in the gateway log.

Audit​

Every change writes an audit row with who made it, when and what changed, with secrets removed. Registering, changing and removing a store through /vector_store/new, /vector_store/update and /vector_store/delete write rows with table_name Spanway_ManagedVectorStoresTable and the action created, updated (with the value before and after) or deleted. Creating, modifying and deleting a store at the provider through /v1/vector_stores write rows with table_name Spanway_ManagedObjectTable and an object_id of vector_store:<id>, and registering an index through POST /v1/indexes writes vector_store_index:<name>. See audit logs.

Logs​

LevelLineWhat it meansAction
ERRORError creating vector store: <cause> (also updating, deleting, listing, getting vector store info)A management route failed unexpectedly and answered 500.Action needed. Read the cause, often a database problem.
DEBUGUpdated vector store <id> in both database and in-memory registryAn update reached the database and the running gateway.Normal. Shown only with detailed debug logging.

Providers​

The gateway's endpoint support matrix marks 4 provider integrations as supporting this endpoint:

Azure AI, OpenAI, RAGFlow, AWS S3 Vectors.