S3 Vectors via SDK Best Practices
This is the checklist to run before and after taking an S3 Vectors workload to production from the SDK.
Busque em todas as páginas da documentação
This is the checklist to run before and after taking an S3 Vectors workload to production from the SDK.
Each item is a rule stated positively, with a one-line rationale. Work top to bottom - the groups run from how you design the index, through writing and querying, to cost and security. Most rules apply whether you call S3 Vectors from boto3 or the AWS SDK v3. Because this is a 2026 API, several rules end with a reminder to verify specifics against current docs.
dimension must equal it exactly or writes fail.cosine for most text embeddings, euclidean for some others - and it is fixed at creation.nonFilterableMetadataKeys so they store but do not bloat the filterable set.Create the index deliberately - it is the one decision you cannot walk back cheaply.
# --- Python (boto3) ---
import boto3
sv = boto3.client("s3vectors")
sv.create_index(
vectorBucketName="my-vectors", indexName="docs",
dataType="float32", dimension=1024, distanceMetric="cosine",
metadataConfiguration={"nonFilterableMetadataKeys": ["raw_text"]},
)
# Verify operation/parameter names against current boto3 docs (2026 API surface).// --- TypeScript (AWS SDK v3) ---
import { S3VectorsClient, CreateIndexCommand } from "@aws-sdk/client-s3vectors";
const sv = new S3VectorsClient({});
await sv.send(new CreateIndexCommand({
vectorBucketName: "my-vectors", indexName: "docs",
dataType: "float32", dimension: 1024, distanceMetric: "cosine",
metadataConfiguration: { nonFilterableMetadataKeys: ["raw_text"] },
}));
// Verify operation/parameter names against current @aws-sdk/client-s3vectors docs (2026 API surface).s3vectors:GetVectors.filter prunes candidates in search, returning the true top-k of the matching subset rather than filtering after.Ask only for what you use - metadata and distance are opt-in.
# --- Python (boto3) ---
res = sv.query_vectors(
vectorBucketName="my-vectors", indexName="docs",
topK=5, queryVector={"float32": q},
filter={"topic": "iam"}, # verify filter grammar at build time (2026 API)
returnMetadata=True, returnDistance=True,
)// --- TypeScript (AWS SDK v3) ---
const res = await sv.send(new QueryVectorsCommand({
vectorBucketName: "my-vectors", indexName: "docs",
topK: 5, queryVector: { float32: q },
filter: { topic: "iam" }, // verify filter grammar at build time (2026 API)
returnMetadata: true, returnDistance: true,
}));put_vectors and paged reads lower the per-request bill that dominates high-volume work.s3vectors client shares the connection pool and resolved credentials.Tune retries once on the client rather than wrapping every call.
# --- Python (boto3) ---
import boto3
from botocore.config import Config
sv = boto3.client("s3vectors", config=Config(retries={"max_attempts": 10, "mode": "adaptive"}))// --- TypeScript (AWS SDK v3) ---
import { S3VectorsClient } from "@aws-sdk/client-s3vectors";
const sv = new S3VectorsClient({ maxAttempts: 10, retryMode: "adaptive" });encryptionConfiguration with sseType: aws:kms for a customer-managed key instead of default SSE-S3.s3vectors actions on your exact resources, not s3vectors:* on *.returnMetadata require s3vectors:GetVectors on top of QueryVectors - do not grant it broadly.The index dimension and distance metric. Both are immutable, must match your embedding model, and changing either forces a new index and a full reload of every vector.
Batch many per put_vectors call rather than one per request, use stable deterministic keys so re-runs upsert, and retry with backoff. Size the batch to the service maximum, which you should verify against current docs.
They are opt-in. Set returnMetadata and returnDistance to true, and include s3vectors:GetVectors in your IAM policy, which metadata access requires alongside QueryVectors.
Batch writes to cut request count, keep topK and returned metadata minimal, delete stale vectors, and estimate Bedrock embedding cost separately since batching does not reduce it. Use S3 Vectors for the latency-tolerant workloads it is priced for.
Encrypt sensitive data with SSE-KMS, scope IAM to specific bucket/index ARNs, grant GetVectors narrowly, keep secrets out of returnable metadata, and isolate tenants by index or an enforced metadata filter.
Use a deterministic key derived from the source id or a content hash. Writing the same key overwrites in place, so reprocessing a corpus upserts rather than creating duplicates.
The habits hold, but specifics move. Verify operation names, the put_vectors batch maximum, and the metadata filter grammar against current docs before you depend on them - this is a 2026 API surface.
When you need consistently low-single-digit-millisecond queries, very high QPS, or hybrid keyword-plus-vector search. Those belong on OpenSearch, Pinecone, or pgvector - see the comparison page.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+). Amazon S3 Vectors is a fast-moving 2026 API - verify exact operation and parameter names against current docs.
Revisado por Chris St. John·Última atualização: 23 de jul. de 2026