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:
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:
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:
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:
vector_store.similarity_search_with_score(
"adventures in space", filter={"genre": {"$eq": "family"}}
)