AWS Builder Center
Cut Bedrock knowledge base costs with scale-to-zero OpenSearch Serverless

Cut Bedrock knowledge base costs with scale-to-zero OpenSearch Serverless

Paying for compute while your RAG app sits idle? Move your knowledge base to a NextGen OpenSearch Serverless collection that scales to zero.

Does your retrieval-augmented generation (RAG) application go quiet at night and on weekends while your bill keeps showing compute? If your  Amazon Bedrock knowledge base  stores its vectors in Amazon OpenSearch Serverless classic, the answer is probably yes. A classic collection keeps a capacity floor running whether anyone asks a question or not. The solution is to use the next generation of  Amazon OpenSearch Serverless , which can  scale to zero  when nobody is using it, so you don't pay for idle time. The AWS  launch post  reports up to 60% cost savings compared with Amazon OpenSearch Service domains provisioned for peak capacity, and your savings can be even higher if your knowledge base is queried very rarely.
In this article, I will show you how to move a Bedrock knowledge base onto a NextGen OpenSearch Serverless collection, check its answers, switch your callers and turn off OpenSearch Serverless classic. I tested the NextGen side of this move in US East (N. Virginia) in November 2026, and watched the new collection drop to zero compute between test runs.

Three rules for a safe move

  1. Build a new knowledge base. Don't edit the old one. The  UpdateKnowledgeBase API  requires the same  storageConfiguration  you used at creation, so you can't swap the vector store. Every caller has to switch to the new knowledge base ID.
  1. Copy the embedding and chunking settings exactly. The new knowledge base re-embeds every document. If the model, dimensions, chunking or parsing differ, your results change.
  1. Keep classic running until the new knowledge base has proven itself. While the old one exists, rollback is a config change. Savings start only when classic capacity stops.

OpenSearch Serverless terms used in this article

  • OpenSearch Compute Unit (OCU): the unit of compute OpenSearch Serverless bills, separately for indexing and search. Think of an OCU as a worker on a shift: you pay while the worker is on the clock.
  • Collection group: a container for collections that share OCUs and capacity limits. The  collection group , not the collection, sets the generation. A collection created without a group is classic.
  • Scale to zero: when no collection in a group gets a request for 10 minutes, its indexing and search OCUs drop to zero and compute billing stops. Storage is still charged. The docs say the first request after idle waits 10–30 seconds for capacity. I didn't measure that wait.
  • Sync (ingestion job): the job that reads, chunks and embeds your documents and writes them to the index.  COMPLETE  isn't the finish line for search. In my 3,000-document test, 79% of documents were searchable at  COMPLETE  and 100% about 5 minutes later.

What you'll build

Figure 1 shows the two knowledge bases running side by side during the move.
Two Bedrock knowledge bases read one S3 source. The old one uses classic, the new one a 0-OCU group.

Figure 1: The old and new knowledge bases during the move
The old knowledge base keeps serving callers while the new one fills an index in a group with a minimum of 0 OCU. Once results match, callers switch to the new ID and you delete the classic side.

What you need

  • Python 3 with  boto3 , for the one signed request that creates the vector index.
  • Permissions to manage Bedrock knowledge bases, AWS Identity and Access Management (IAM) roles and OpenSearch Serverless.
  • Access to the embedding model your classic knowledge base uses. I tested with Amazon Titan Text Embeddings V2 at 1,024 dimensions.

Step 1: Record the classic knowledge base's settings

Read the old knowledge base, its data sources and the classic index mapping ( GET /<index-name>/_mapping ).
aws bedrock-agent get-knowledge-base --knowledge-base-id <old-kb-id>
aws bedrock-agent list-data-sources --knowledge-base-id <old-kb-id>
aws bedrock-agent get-data-source --knowledge-base-id <old-kb-id> --data-source-id <data-source-id>
  • Record the embedding model,  dimensions  and  embeddingDataType . If they differ, results change.
  • Record the field mapping. If you reuse the field names, downstream code stays the same.
  • Record each data source's  vectorIngestionConfiguration . It holds  chunking , parsing and custom transformation settings. If you leave it out, your chunks change.
  • Look for  CUSTOM  data sources. A  direct ingestion  data source can't be re-synced, so your application has to push those documents again.
  • List every caller, including agents, flows and infrastructure as code (IaC). That list is your cutover plan for Step 6.

Step 2: Create the collection group and the collection

Create a group with both minimums at 0, the security policies, and a vector search collection in the group. To do this with Terraform instead, see  Set up the next generation of Amazon OpenSearch Serverless with Terraform .
aws opensearchserverless create-collection-group --name my-kb-group --generation NEXTGEN \
--standby-replicas ENABLED \
--capacity-limits minIndexingCapacityInOCU=0,maxIndexingCapacityInOCU=16,minSearchCapacityInOCU=0,maxSearchCapacityInOCU=16

aws opensearchserverless create-security-policy --type encryption --name my-kb-enc \
--policy '{"Rules":[{"ResourceType":"collection","Resource":["collection/my-kb-collection"]}],"AWSOwnedKey":true}'

aws opensearchserverless create-security-policy --type network --name my-kb-net \
--policy '[{"Rules":[{"ResourceType":"collection","Resource":["collection/my-kb-collection"]}],"AllowFromPublic":true}]'

aws opensearchserverless create-collection --name my-kb-collection --type VECTORSEARCH \
--collection-group-name my-kb-group

aws opensearchserverless batch-get-collection --names my-kb-collection \
--query 'collectionDetails[].[status,arn,collectionEndpoint]' --output text
  • Set both minimums to 0. If you set a minimum higher than 0, the group keeps that floor running. The  capacity limits  page lists the allowed values.
  • Set  --collection-group-name . If you leave it out, you get a classic collection. Check the endpoint:  https://<collection-id>.aoss.<region>.on.aws  is the next generation, and  https://<collection-id>.<region>.aoss.amazonaws.com  is classic.
  • Match the classic  encryption  key type. If classic uses a customer managed key, use that key here. I tested only the AWS owned key.
In my test, the collection reached  ACTIVE  in under a minute.
Learning-only setting:  AllowFromPublic: true  opens the endpoint to the internet, with IAM still required. For production, use  "AllowFromPublic": false  and  "SourceServices": ["bedrock.amazonaws.com"]  in the  network policy . In my test, Bedrock syncs and queries kept working, and outside calls got a 401. To create the index yourself, also add your VPC endpoint.

Step 3: Give the knowledge base role access

Reuse the classic  service role  and add  aoss:APIAccessAll  on the new collection ARN to its IAM policy. Then save the following as  kb-access-policy.json  and create the  data access policy .
[{"Rules":[
{"ResourceType":"collection","Resource":["collection/my-kb-collection"],
"Permission":["aoss:DescribeCollectionItems"]},
{"ResourceType":"index","Resource":["index/my-kb-collection/bedrock-kb-index"],
"Permission":["aoss:DescribeIndex","aoss:ReadDocument","aoss:WriteDocument","aoss:UpdateIndex"]}],
"Principal":["arn:aws:iam::<account-id>:role/<kb-role-name>"]},
{"Rules":[
{"ResourceType":"collection","Resource":["collection/my-kb-collection"],"Permission":["aoss:*"]},
{"ResourceType":"index","Resource":["index/my-kb-collection/*"],"Permission":["aoss:*"]}],
"Principal":["arn:aws:iam::<account-id>:role/<your-admin-role>"]}]
aws opensearchserverless create-access-policy --type data --name my-kb-access \
--policy file://kb-access-policy.json
  • Include  aoss:UpdateIndex . Bedrock adds fields to the mapping on its first write. If you leave  UpdateIndex  out, every document fails with  authorization_exception .
  • Give yourself admin rights in a separate rule, because you create the index in Step 4.

Step 4: Create the vector index without  engine  or  mode 

Save this mapping as  index-mapping.json . Copy  dimension ,  space_type ,  data_type  and any HNSW parameters from your classic mapping.
{"settings":{"index.knn":true},
"mappings":{"properties":{
"bedrock-knowledge-base-default-vector":{"type":"knn_vector","dimension":1024,
"method":{"name":"hnsw","space_type":"l2"}},
"AMAZON_BEDROCK_TEXT_CHUNK":{"type":"text"},
"AMAZON_BEDROCK_METADATA":{"type":"text","index":false}}}}
Index requests need  Signature Version 4 (SigV4)  signing for the  aoss  service. Save this as  sigv4_put.py  and run  python3 sigv4_put.py .
import hashlib, json, boto3, urllib.request
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest

ENDPOINT = "https://<collection-id>.aoss.<region>.on.aws"
REGION = "<region>"
body = json.dumps(json.load(open("index-mapping.json"))).encode()
headers = {"Content-Type": "application/json",
"x-amz-content-sha256": hashlib.sha256(body).hexdigest()}
req = AWSRequest(method="PUT", url=ENDPOINT + "/bedrock-kb-index", data=body, headers=headers)
SigV4Auth(boto3.Session().get_credentials().get_frozen_credentials(), "aoss", REGION).add_auth(req)
with urllib.request.urlopen(urllib.request.Request(req.url, data=body, headers=dict(req.headers), method="PUT")) as r:
print(r.status, r.read().decode())
  • Leave out  engine  and  mode . The Bedrock  vector store prerequisites  show  "engine": "faiss" , and so does a copied classic mapping. The next generation rejects both with a 400, for example  Field parameter 'mode' is not supported , and sets  faiss ,  on_disk  and  32x  compression itself.
  • Sign the  x-amz-content-sha256  header. If you leave it out, you get a bare 403 that looks like a policy problem.
  • Retry a 403 for about a minute. My first PUT, 15 seconds after creating the policy, returned 403 and worked on retry.
  • Check for a 200 before you sync. Otherwise Bedrock's writes create a plain float field, and every vector query fails with  Field ... is not knn_vector type .
In my 3,000-document test, the default 32x  compression  gave recall@10 of 1.0, the same as classic.

Step 5: Create the new knowledge base and sync it

Create the knowledge base with the same embedding settings and field mapping, then clone each data source and sync it.
aws bedrock-agent create-knowledge-base --name my-kb-v2 \
--role-arn arn:aws:iam::<account-id>:role/<kb-role-name> \
--knowledge-base-configuration '{"type":"VECTOR","vectorKnowledgeBaseConfiguration":{"embeddingModelArn":"arn:aws:bedrock:<region>::foundation-model/amazon.titan-embed-text-v2:0","embeddingModelConfiguration":{"bedrockEmbeddingModelConfiguration":{"dimensions":1024}}}}' \
--storage-configuration '{"type":"OPENSEARCH_SERVERLESS","opensearchServerlessConfiguration":{"collectionArn":"<collection-arn>","vectorIndexName":"bedrock-kb-index","fieldMapping":{"vectorField":"bedrock-knowledge-base-default-vector","textField":"AMAZON_BEDROCK_TEXT_CHUNK","metadataField":"AMAZON_BEDROCK_METADATA"}}}'

aws bedrock-agent create-data-source --knowledge-base-id <new-kb-id> --name s3-docs \
--data-source-configuration '{"type":"S3","s3Configuration":{"bucketArn":"arn:aws:s3:::<bucket>","inclusionPrefixes":["docs/"]}}'

aws bedrock-agent start-ingestion-job --knowledge-base-id <new-kb-id> --data-source-id <new-data-source-id>
aws bedrock-agent get-ingestion-job --knowledge-base-id <new-kb-id> --data-source-id <new-data-source-id> \
--ingestion-job-id <job-id> --query 'ingestionJob.[status,statistics]'
  • Use the ordinary  OPENSEARCH_SERVERLESS  storage type. In my test, the knowledge base went  ACTIVE  in under 10 seconds.
  • Clone every data source setting from Step 1 with  CreateDataSource , including  dataDeletionPolicy .
  • Budget for a full re-embed. In my test, 3,000 small documents took about 6.3 minutes with Titan Text Embeddings V2.
  • Check  numberOfDocumentsFailed . In one test sync, 94 of 3,004 documents failed with  [security_exception] authentication/authorization failure. Call to Amazon OpenSearch Serverless Vector Database did not succeed.  Recheck the data access policy from Step 3, then  sync  again before you go further.

Check that the new knowledge base answers the same way

Wait until the index's  _count  stops changing, then run 20–50 real user queries against both knowledge bases. Pass each query as JSON, because CLI shorthand fails with  ParamValidation  on text with a comma.
aws bedrock-agent-runtime retrieve --knowledge-base-id <old-kb-id> \
--retrieval-query '{"text":"How do I reset my password?"}' \
--retrieval-configuration '{"vectorSearchConfiguration":{"numberOfResults":5}}'

aws bedrock-agent-runtime retrieve --knowledge-base-id <new-kb-id> \
--retrieval-query '{"text":"How do I reset my password?"}' \
--retrieval-configuration '{"vectorSearchConfiguration":{"numberOfResults":5}}'
Compare the top result and the top-five overlap. With matching embedding and chunking settings, expect close to identical results with small reordering among close scores. Large differences usually point to a chunking or parsing mismatch.
Then test the  Retrieve  features your application uses. In my tests, hybrid search,  RetrieveAndGenerate  and every metadata filter operator I tried returned the right documents. Measure latency from your application, warm and after 10 idle minutes.

Step 6: Switch your callers

Point every caller from your Step 1 list at the new knowledge base ID.
Caller
Change
Application config and Lambda environment variables
Set  knowledgeBaseId  to the new ID, then deploy
Amazon Bedrock Agents
Associate the new knowledge base, disassociate the old one, prepare the agent, then update the alias
Amazon Bedrock Flows
Point the knowledge base node at the new ID, then publish a new version
IAM policies scoped to the knowledge base ARN
Add the new ARN
IaC templates
Model the new collection and knowledge base as new resources
Scheduled syncs
Point them at the new knowledge base and data source IDs
Run one more sync just before cutover to pick up recent changes. Deletes took about 5 minutes to apply in my test, so plan for that with compliance-sensitive content. To roll back, point callers at the old ID.

Watch the new group go to zero

Now for the fun part. The following table shows  SearchOCU  and  IndexingOCU  in  Amazon CloudWatch  (Maximum, 15-minute periods) for my test group.
Window
Activity
SearchOCU
IndexingOCU
08:35–13:05
Idle
0
0
13:20–14:35
Knowledge base tests
4
1–2
14:50–15:05
Idle gap
0
0
15:20–15:50
Bulk load and queries
4
1
16:05 onward
Idle
0
0
The group returned to zero within one or two periods of the last request. If the first-request wait is too long for your users, set the minimum search OCU higher than 0 to keep a small search floor. Compute is  billed  per OCU-hour at the group level, and storage is billed per GB-month even at zero compute.

Quick reference: what happens if…

If you…
What happens
Fix
Try to change the old knowledge base's storage configuration
 UpdateKnowledgeBase  requires the original  storageConfiguration 
Create a new knowledge base
Copy a classic mapping with  "engine": "faiss"  or  mode 
Index creation fails with a 400,  Field parameter 'mode' is not supported 
Remove both fields
Leave  aoss:UpdateIndex  out of the data access policy
Every document in the sync fails with  authorization_exception 
Add  UpdateIndex  to the index rule
Create the collection without  --collection-group-name 
You get a classic collection on a  .aoss.amazonaws.com  endpoint
Delete it and create it in the group
Query right after the sync reports  COMPLETE 
Some documents are missing from results
Poll  _count  until it stops changing
Sign index requests without  x-amz-content-sha256 
A bare 403 that looks like a policy problem
Add the payload-hash header
Delete classic while another classic collection shares its capacity
Classic OCUs keep billing
Delete the last classic collection in the pool

Next steps

Measure the first-request wait from your own application and decide whether you need a search floor. Then move the other classic collections in that account and Region.

Clean up

Classic keeps billing until you delete it. After your soak period, delete the old data sources and knowledge base, then the classic collection and any unused policies.
aws bedrock-agent delete-data-source --knowledge-base-id <old-kb-id> --data-source-id <data-source-id>
aws bedrock-agent delete-knowledge-base --knowledge-base-id <old-kb-id>
aws opensearchserverless delete-collection --id <classic-collection-id>
Classic collections share capacity, so the floor stays until the last classic collection in that pool is gone. Check the account-level  SearchOCU  and  IndexingOCU  metrics, which cover collections outside any group, and confirm the drop in  AWS Cost Explorer .

From idle floor to zero

A move off classic means a new knowledge base, not a flipped switch. Copy the embedding and chunking settings, create the index without  engine  or  mode , and give the role  UpdateIndex . Then compare results, switch callers and delete classic, and your idle hours stop showing up as compute on the bill.

Learn more

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article