Skip to main content
Amazon S3 Vectors is cloud object storage with native support for storing and querying vectors. It is built for large vector datasets that do not need the high-throughput, low-latency profile of an in-memory vector database, and it requires no infrastructure to provision.
This page covers how to use the AmazonS3Vectors vector store from the langchain-aws package.

Setup

Installation

AmazonS3Vectors requires langchain-aws>=0.2.31.

Create a vector bucket

You must create an S3 vector bucket before using this store. The vector index is created for you on first write unless you pass create_index_if_not_exist=False.
This requires the s3vectors:CreateVectorBucket permission. For more detail, see Getting started with S3 Vectors.

Credentials

The store uses the standard AWS credential chain. You can also pass region_name, credentials_profile_name, or an existing boto3 client.

Initialization

Index names must be 3 to 63 characters long, start and end with a letter or number, and contain only lowercase letters, numbers, hyphens and dots.

Manage vector store

Add items

You can also build the store and add texts in one call:

Delete items

Calling delete() without ids deletes the entire vector index and everything in it. Always pass ids unless you intend to drop the index.

Get items by ID

If any requested ID is missing, get_by_ids raises ValueError and returns nothing, rather than returning the subset it found.

Query

Similarity search with score

The score returned is a distance, so lower values indicate a closer match.

Metadata filtering

Filters use the S3 Vectors filter syntax:
See Metadata filtering for the supported operators.

Search by vector

Configuration

Distance metric

distance_metric accepts cosine (the default) or euclidean. It is fixed when the index is created, so changing it afterwards has no effect on an existing index.

Non-filterable metadata

Metadata keys listed in non_filterable_metadata_keys are stored and returned with the document, but cannot be used in filters. Filtering on one raises a ValidationException. This is set when the index is created.

Page content storage

By default the document text is stored in metadata under the _page_content key. Set page_content_metadata_key to change that key, or to None to embed the text without storing it, in which case retrieved documents have an empty page_content. Metadata is subject to the S3 Vectors limitations and restrictions, including a 40 KB total metadata limit per vector.

Use as a retriever

API reference

For detailed documentation of all features and configuration options, see the AmazonS3Vectors API reference.