RAG ingest
POST /v1/rag/ingest is an all-in-one ingestion pipeline. It takes a file upload or a URL, optionally runs OCR on it, splits the text into chunks, embeds the chunks with an embedding model on the gateway, and writes them to a vector store, creating the store if needed. Each step uses models and stores registered on the gateway, so everything is logged, costed and access controlled, and an application does not need its own ingestion code.
Scenario
A legal team drops contracts into a folder and wants them searchable within minutes. A small job watches the folder and sends each new PDF to the ingest endpoint, naming the team's vector store, an OCR model for scanned pages and an embedding model. The contract is searchable as soon as the call returns, and the cost of the OCR and embedding calls is recorded under the team's key.
Steps
-
Register the models the pipeline uses. In the Admin UI open Models + Endpoints (
/ui/models-and-endpoints) and add an embedding model (Mode Embedding - /embeddings) and, for scanned documents, an OCR model (Mode OCR - /ocr). Create or register the target vector store on the Vector Stores page (/ui/vector-stores), see create a vector store. -
Create a key in Virtual Keys (
/ui/api-keys) that may use the embedding model, the OCR model and the vector store. -
Ingest a file upload. A form upload sends the file in
fileand the rest of the request,ingest_optionsincluded, as JSON in therequestfield.curl -X POST http://localhost:4000/v1/rag/ingest \-H "Authorization: Bearer $SPANWAY_API_KEY" \-F "file=@leave-policy.pdf" \-F 'request={"ingest_options": {"vector_store": {"custom_llm_provider": "openai", "vector_store_id": "vs_hr_policies"}, "chunking_strategy": {"chunk_size": 800, "chunk_overlap": 100}, "embedding": {"model": "text-embedding-3-large"}}}'Or ingest from a URL with a JSON body.
curl -X POST http://localhost:4000/v1/rag/ingest \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"file_url": "https://example.com/handbook.pdf","ingest_options": {"vector_store": {"custom_llm_provider": "openai", "vector_store_id": "vs_hr_policies"},"chunking_strategy": {"chunk_size": 800, "chunk_overlap": 100},"embedding": {"model": "text-embedding-3-large"}}}'An existing uploaded file can be ingested by sending
file_idinstead offile_url. -
Ingest from the browser instead. Open Vector Stores (
/ui/vector-stores), click the Create Vector Store tab, drop PDF, TXT or Markdown files on the upload area, pick the Provider and the provider fields and click Create Vector Store. The tab sends each file to this endpoint. -
Check the result. Search the store on the Test Vector Store tab, and open Logs (
/ui/logs) to see the OCR, embedding and vector store calls under the same request.
Expected result
{"id": "ingest_7c2d4e1f", "status": "completed", "vector_store_id": "vs_hr_policies", "file_id": "file-abc123", "error": null}
status is completed, in_progress for backends that index asynchronously, or failed with an error.
Ingest options
| Block | Fields |
|---|---|
vector_store | custom_llm_provider (openai, bedrock, gemini, vertex_ai or s3_vectors), optional vector_store_id (a new store is created when omitted, except for bedrock, which needs the id of a knowledge base you already created in AWS), ttl_days, and a saved credential through spanway_credential_name. Credentials themselves are never taken from the request: api_key, api_base, the aws_* key and role fields, azure_ad_token and vertex_credentials are refused with 400, so configure them on the gateway. S3 Vectors takes vector_bucket_name, index_name and aws_region_name. gemini uses the gateway's Gemini key, creates a File Search store when vector_store_id is left out, and takes optional custom_metadata. |
chunking_strategy | chunk_size (default 1000) and chunk_overlap (default 200). |
ocr | model, an OCR model on the gateway, used for PDFs. |
embedding | model, an embedding model on the gateway. |
name | Optional pipeline name shown in the logs. |
Access and limits
The key needs access to the vector store (or permission to create one), the embedding model and the OCR model. Any vector store ids mentioned in the request are authorized against the key's object_permission.
Upload checks
Every document, whether uploaded as a file, sent as base64 or fetched from file_url, goes through the same checks before anything reaches the provider, so a file that is not a document never lands in your store. The gateway looks at the bytes themselves, not the file name. It accepts PDF and UTF-8 text, which covers TXT, Markdown, CSV and JSON. Word, Excel and other office files, images, archives such as ZIP and executables are refused, so save Word files as PDF first. The size cap is 512 MB per document and is not configurable. Each document also goes through the malware scan, and the gateway gives the file a server-generated name, so a path in the uploaded name is never used.
A file_url is fetched by the gateway itself, after the key's access is checked, with the URL rules in user_url_validation and user_url_allowed_hosts: private and metadata addresses are refused unless the host is allowed, redirects are followed at most a few times, and the download must finish within 120 seconds.
A refused document answers 400 with a reason:
reason | Message |
|---|---|
empty_file | Uploaded file is empty. |
file_too_large | Uploaded file is <n> bytes, exceeding the 536870912-byte limit. |
archive_not_allowed | Archive uploads are not allowed. |
executable_not_allowed | Executable uploads are not allowed. |
unsupported_format | Only PDF and UTF-8 text documents are accepted. |
malware_detected | Uploaded file was flagged by malware scanning (<signature>). |
malware_scan_error | Malware scanning could not complete; upload rejected. |
Errors
| Status | What it means | Fix |
|---|---|---|
400 BadRequestError | ingest_options is missing, the request form field is not valid JSON, none of file, file_url and file_id was sent, or vector_store.custom_llm_provider is unknown. | Send ingest_options with a vector_store block and exactly one file source. |
400 The request form field is not valid JSON: <detail> | The multipart request field could not be parsed. | Send the options as one JSON object in the request field. |
400 '<field>' cannot be set in ingest_options.vector_store. Credentials must be configured server-side. | The request carried a credential or a destination such as api_key or api_base. | Remove the field and use spanway_credential_name, or configure the credential on the gateway. |
400 file_url could not be fetched: <reason> | The URL points at a private address, did not answer in time, was too large or answered with an error status. | Use a reachable public https URL, allow the host in user_url_allowed_hosts, or upload the file. |
400 with a reason | The document failed the upload checks. | Send a PDF or text document under 512 MB. |
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 PermissionDeniedError | The named store belongs to another team, the key may not use the embedding model or the OCR model, or the internal user viewer role tried to create a new store. | Use a store of your team, grant the models on the key or team, or send vector_store.vector_store_id. A missing grant on the store is the 401 above. |
500 RAG ingest failed. The gateway log has the cause. | An unexpected failure inside the gateway. | Look for the RAG Ingest failed line in the gateway log. A provider error keeps the provider's status and message instead. |
status failed, error Creating a new Bedrock knowledge base needs ... | A bedrock ingest left out vector_store_id. The gateway images cannot create a Bedrock knowledge base, so the gateway stops before it creates anything in AWS. | Create the knowledge base in AWS, then send its id as vector_store.vector_store_id. |
status failed | A step failed at the provider. error carries the reason, for example an embedding dimension that does not match the index. | Read error, fix the model or the store and ingest again. |
Audit
When ingest creates a new store, it registers the store on the gateway and writes a created audit row with table_name Spanway_ManagedVectorStoresTable. When it adds a document to a store the gateway already holds, it writes an updated row with the list of ingested files before and after. See audit logs.
Logs
| Level | Line | What it means | Action |
|---|---|---|---|
| ERROR | RAG Ingest failed: <cause> | Ingest stopped on an unexpected error and answered 500, or a provider error with the provider's status. | Action needed. Read the cause. |
| ERROR | Failed to save vector store <id> to database: <cause> | The document was ingested at the provider but the gateway registration could not be written. The request still succeeded. | Action needed. Register the store by hand on the Vector Stores page and check the database. |
| INFO | Saving newly created vector store <id> to database and Added file <name> to vector store <id> metadata | Ingest registered a new store or added a file to an existing registration. | Normal. |
| WARNING | Skipping database save: prisma_client=False, ... | The gateway runs without a database, so the new store is not registered. | Normal without a database. Register the store in config.yaml. |
Related
- RAG query for answering questions over the store.
- Vector store files for attaching already uploaded files.
- OCR for the OCR step on its own.
- Vector Stores page for the Create Vector Store tab.