Skip to main content
Hello and welcome back. This guide demonstrates how to store sentence embeddings (vectors) in an S3 vector bucket and retrieve them using similarity search. The example uses a Jupyter notebook workflow to:
  • Configure the AWS client and import required packages.
  • Load a policy document and chunk it into paragraphs.
  • Convert chunks into embeddings with SentenceTransformer.
  • Validate the vector index dimension in the S3 vector bucket.
  • Upload vectors to the S3 vector index.
  • Query the index using a text query to retrieve nearest neighbors.
Prerequisites:
  • Python 3.8+
  • A working AWS account and credentials with access to the S3 Vectors API
  • The boto3 and sentence-transformers packages
Install dependencies (if needed):
Resources: Quick overview of the notebook sections: Setup — imports and AWS configuration
Load and chunk the document
  • For this demo we perform a simple paragraph split (split on double newlines). Depending on your data, you might prefer sentence splitting or a sliding window approach.
Convert paragraphs to embeddings
  • Use the same SentenceTransformer model that you will use for queries to ensure dimensional consistency.
Validate the S3 vector index dimension
  • The vector index must be created with the same vector dimension as the embeddings produced by your model. Query the index metadata and read the dimension field robustly to handle variations in the API response structure.
Always ensure the vector index dimension matches the embedding dimension produced by your model. A mismatch will cause put_vectors or query_vectors operations to fail.
If the index was created with an incorrect dimension (for example, 3 instead of 384), you must delete and recreate the index with the correct dimension value before uploading vectors.
Why is this check important?
  • Embedding vectors are fixed-length numeric arrays. If the index expects a different length, the underlying vector store cannot store or compare vectors correctly, and operations will error out.
Here is an example screenshot of deleting an index in the S3 console before recreating it with the correct dimension.
The image shows a screenshot of an Amazon S3 console with a pop-up window asking for confirmation to delete a vector index named "airline-policy-index" by typing "delete".
When creating the index in the S3 console, ensure you enter the dimension that matches your model (for example 384).
The image shows a web interface for creating a vector index in Amazon S3, with fields for entering the vector index name, dimension, and distance metric.
Upload: build the vector payload
  • Each entry needs a unique key, the vector under the supported numeric format (here float32), and optional metadata (we store the original paragraph text).
Put vectors into the S3 vector index
Query the index
  • Use the same model to encode the query text. Provide the query vector as float32 and request metadata and distance if you want to inspect results.
Notes about querying:
  • topK controls how many nearest neighbors are returned.
  • The queryVector must match the index dimension.
  • The response typically includes an array of vectors (hits); each hit contains key, distance, and whatever metadata you stored.
Example output (illustrative):
Summary and best practices
  • Convert text to embeddings using a single consistent model (e.g. sentence-transformers/all-MiniLM-L6-v2).
  • Always verify that the S3 vector index dimension matches the embedding vector length.
  • Upload vectors with put_vectors, including a stable key, the vector values (e.g. float32), and helpful metadata.
  • Query with query_vectors using the same model, correct topK, and request returnMetadata / returnDistance as needed.
  • If you encounter dimension mismatches, delete and recreate the index with the correct dimension.
The image shows a Jupyter Notebook environment with a text file open, displaying airline security policy guidelines for cabin crew and customer data management.
That is it for this demo.

Watch Video