Skip to content

AWS S3 Vectors Bridge

Edit this page

The AWS S3 Vectors bridge provides vector storage and similarity search integration using AWS S3 Vectors.

Requirements

  • An AWS account with access to S3 Vectors
  • The AsyncAws S3Vectors client

Installation

Install the bridge package:

1
$ composer require symfony/ai-s3vectors-store

Basic Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
use AsyncAws\S3Vectors\S3VectorsClient;
use Symfony\AI\Store\Bridge\S3Vectors\Store;

$client = new S3VectorsClient([
    'region' => 'us-east-1',
]);

$store = new Store(
    client: $client,
    vectorBucketName: 'my-vector-bucket',
    indexName: 'my-index',
    filter: [], // Optional: default filter for queries
    topK: 3, // Optional: default number of results
);

Setup the Vector Store

Before using the store, you need to initialize it with the appropriate configuration:

1
2
3
4
5
6
7
8
// Setup the vector bucket and index
$store->setup([
    'dimension' => 1536,
    'distanceMetric' => \AsyncAws\S3Vectors\Enum\DistanceMetric::COSINE, // Optional
    'dataType' => \AsyncAws\S3Vectors\Enum\DataType::FLOAT32, // Optional
    'encryption' => ['kmsKeyId' => 'your-kms-key-id'], // Optional
    'tags' => ['env' => 'production'], // Optional
]);

Add Documents

1
2
3
4
5
6
7
8
9
10
11
use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\Component\Uid\Uuid;

$document = new VectorDocument(
    id: Uuid::v4(),
    vector: new Vector([0.1, 0.2, 0.3, ...]),
    metadata: new Metadata(['title' => 'My Document'])
);
$store->add($document);

Query Similar Vectors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Store\Query\VectorQuery;

$results = $store->query(
    query: new VectorQuery(new Vector([0.1, 0.2, 0.3, ...])),
    options: [
        'topK' => 5,
        'filter' => ['category' => 'documentation'],
    ]
);

foreach ($results as $result) {
    echo $result->getMetadata()['title'] . ' (score: ' . $result->getScore() . ')' . PHP_EOL;
}

Remove Documents

1
$store->remove(['id1', 'id2']);

Drop the Store

1
2
// Drop the index and bucket
$store->drop();

Features

  • Full CRUD operations for vector documents
  • Similarity search with configurable distance metrics (cosine, euclidean)
  • Metadata filtering support
  • KMS encryption support
  • Tag management
  • Batch operations

Distance Metrics

The bridge supports the following distance metrics:

  • COSINE - Cosine distance (default)
  • EUCLIDEAN - Euclidean distance
  • DOT_PRODUCT - Dot product distance

Data Types

The bridge supports the following data types for vectors:

  • FLOAT32 - 32-bit floating point (default)
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version