# AmazonS3Vectors

> **Class** in `langchain_aws`

📖 [View in docs](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors)

S3Vectors is Amazon S3 Vectors database.

To use, you MUST first manually create a S3 vector bucket.
There is no need to create a vector index.
See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-getting-started.html

Pay attention to s3 vectors limitations and restrictions.
By default, metadata for s3 vectors includes page_content and metadata
for the Document.
See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-limitations.html

Examples:

The following examples show various ways to use the AmazonS3Vectors with
LangChain.

For all the following examples assume we have the following:

    ```python
    from langchain_aws.embeddings import BedrockEmbeddings
    from langchain_aws.vectorstores.s3_vectors import AmazonS3Vectors

    embedding = BedrockEmbeddings()
    ```

Initialize, create vector index if it does not exist, and add texts:

    ```python
    vector_store = AmazonS3Vectors.from_texts(
        ["hello", "developer", "wife"],
        vector_bucket_name="<vector bucket name>",
        index_name="<vector index name>",
        embedding=embedding,
    )
    ```

Initialize, create vector index if it does not exist, and add Documents:
    ```python
    from langchain_core.documents import Document

    vector_store = AmazonS3Vectors(
        vector_bucket_name="<vector bucket name>",
        index_name="<vector index name>",
        embedding=embedding,
    )
    vector_store.add_documents(
        [
            Document("Star Wars", id="key1", metadata={"genre": "scifi"}),
            Document("Jurassic Park", id="key2", metadata={"genre": "scifi"}),
            Document("Finding Nemo", id="key3", metadata={"genre": "family"}),
        ]
    )
    ```

Search with score(distance) and metadata filter:
    ```python
    vector_store.similarity_search_with_score(
        "adventures in space", filter={"genre": {"$eq": "family"}}
    )
    ```

## Signature

```python
AmazonS3Vectors(
    self,
    *,
    vector_bucket_name: str,
    index_name: str,
    data_type: Literal['float32'] = 'float32',
    distance_metric: Literal['euclidean', 'cosine'] = 'cosine',
    non_filterable_metadata_keys: list[str] | None = None,
    page_content_metadata_key: Optional[str] = '_page_content',
    create_index_if_not_exist: bool = True,
    relevance_score_fn: Optional[Callable[[float], float]] = None,
    embedding: Optional[Embeddings] = None,
    query_embedding: Optional[Embeddings] = None,
    region_name: Optional[str] = None,
    credentials_profile_name: Optional[str] = None,
    aws_access_key_id: Optional[str] = None,
    aws_secret_access_key: Optional[str] = None,
    aws_session_token: Optional[str] = None,
    endpoint_url: Optional[str] = None,
    config: Any = None,
    client: Any = None,
    **kwargs: Any = {},
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `vector_bucket_name` | `str` | Yes | The name of an existing S3 vector bucket |
| `index_name` | `str` | Yes | The name of the S3 vector index. The 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. |
| `data_type` | `Literal['float32']` | No | The data type of the vectors to be inserted into the vector index. Default is "float32". (default: `'float32'`) |
| `distance_metric` | `Literal['euclidean', 'cosine']` | No | The distance metric to be used for similarity search. Default is "cosine". (default: `'cosine'`) |
| `non_filterable_metadata_keys` | `list[str] \| None` | No | Non-filterable metadata keys (default: `None`) |
| `page_content_metadata_key` | `Optional[str]` | No | Key of metadata to store page_content in Document. If None, embedding page_content but stored as an empty string. Default is `_page_content`. (default: `'_page_content'`) |
| `create_index_if_not_exist` | `bool` | No | Automatically create vector index if it does not exist. Default is True. (default: `True`) |
| `relevance_score_fn` | `Optional[Callable[[float], float]]` | No | The 'correct' relevance function. (default: `None`) |
| `embedding` | `Optional[Embeddings]` | No | Embedding function to use for indexing documents. (default: `None`) |
| `query_embedding` | `Optional[Embeddings]` | No | Separate embedding function to use for queries. If not provided, the `embedding` parameter is used for both indexing and querying. This is useful for embedding providers that require different task types for documents vs queries. (default: `None`) |
| `region_name` | `Optional[str]` | No | The aws region where the Sagemaker model is deployed, eg. `us-west-2`. (default: `None`) |
| `credentials_profile_name` | `Optional[str]` | No | The name of the profile in the ~/.aws/credentials or ~/.aws/config files, which has either access keys or role information specified. If not specified, the default credential profile or, if on an EC2 instance, credentials from IMDS will be used. See: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html (default: `None`) |
| `aws_access_key_id` | `Optional[str]` | No | AWS access key id. If provided, aws_secret_access_key must also be provided. If not specified, the default credential profile or, if on an EC2 instance, credentials from IMDS will be used. See: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html If not provided, will be read from `AWS_ACCESS_KEY_ID` environment variable. (default: `None`) |
| `aws_secret_access_key` | `Optional[str]` | No | AWS secret_access_key. If provided, aws_access_key_id must also be provided. If not specified, the default credential profile or, if on an EC2 instance, credentials from IMDS will be used. See: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html If not provided, will be read from `AWS_SECRET_ACCESS_KEY` environment variable. (default: `None`) |
| `aws_session_token` | `Optional[str]` | No | AWS session token. If provided, aws_access_key_id and aws_secret_access_key must also be provided. Not required unless using temporary credentials. See: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html If not provided, will be read from `AWS_SESSION_TOKEN` environment variable. (default: `None`) |
| `endpoint_url` | `Optional[str]` | No | Needed if you don't want to default to us-east-1 endpoint (default: `None`) |
| `config` | `Any` | No | An optional `botocore.config.Config` instance to pass to the client. (default: `None`) |
| `client` | `Any` | No | Boto3 client for s3vectors (default: `None`) |
| `kwargs` | `Any` | No | Additional keyword arguments. (default: `{}`) |

## Extends

- `VectorStore`

## Constructors

```python
__init__(
    self,
    *,
    vector_bucket_name: str,
    index_name: str,
    data_type: Literal['float32'] = 'float32',
    distance_metric: Literal['euclidean', 'cosine'] = 'cosine',
    non_filterable_metadata_keys: list[str] | None = None,
    page_content_metadata_key: Optional[str] = '_page_content',
    create_index_if_not_exist: bool = True,
    relevance_score_fn: Optional[Callable[[float], float]] = None,
    embedding: Optional[Embeddings] = None,
    query_embedding: Optional[Embeddings] = None,
    region_name: Optional[str] = None,
    credentials_profile_name: Optional[str] = None,
    aws_access_key_id: Optional[str] = None,
    aws_secret_access_key: Optional[str] = None,
    aws_session_token: Optional[str] = None,
    endpoint_url: Optional[str] = None,
    config: Any = None,
    client: Any = None,
    **kwargs: Any = {},
)
```

| Name | Type |
|------|------|
| `vector_bucket_name` | `str` |
| `index_name` | `str` |
| `data_type` | `Literal['float32']` |
| `distance_metric` | `Literal['euclidean', 'cosine']` |
| `non_filterable_metadata_keys` | `list[str] \| None` |
| `page_content_metadata_key` | `Optional[str]` |
| `create_index_if_not_exist` | `bool` |
| `relevance_score_fn` | `Optional[Callable[[float], float]]` |
| `embedding` | `Optional[Embeddings]` |
| `query_embedding` | `Optional[Embeddings]` |
| `region_name` | `Optional[str]` |
| `credentials_profile_name` | `Optional[str]` |
| `aws_access_key_id` | `Optional[str]` |
| `aws_secret_access_key` | `Optional[str]` |
| `aws_session_token` | `Optional[str]` |
| `endpoint_url` | `Optional[str]` |
| `config` | `Any` |
| `client` | `Any` |


## Properties

- `vector_bucket_name`
- `index_name`
- `data_type`
- `distance_metric`
- `non_filterable_metadata_keys`
- `page_content_metadata_key`
- `create_index_if_not_exist`
- `relevance_score_fn`
- `client`
- `embeddings`

## Methods

- [`add_texts()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/add_texts)
- [`delete()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/delete)
- [`get_by_ids()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/get_by_ids)
- [`similarity_search()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/similarity_search)
- [`similarity_search_with_score()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/similarity_search_with_score)
- [`similarity_search_by_vector()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/similarity_search_by_vector)
- [`as_retriever()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/as_retriever)
- [`from_texts()`](https://reference.langchain.com/python/langchain-aws/vectorstores/s3_vectors/base/AmazonS3Vectors/from_texts)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-aws/blob/285069d4f44907e10aaf7743888689ea39c98fe3/libs/aws/langchain_aws/vectorstores/s3_vectors/base.py#L22)