symfony/ai-s3vectors-store
Symfony AI Store integration for AWS S3 Vectors. Store embeddings in S3 vector buckets and run similarity queries via the S3 Vectors API (PutVectors/QueryVectors). Useful for retrieval and semantic search using managed AWS infrastructure.
Install the Package:
composer require symfony/ai-s3vectors-store
Configure the Store in config/packages/ai.yaml:
framework:
ai:
stores:
s3_vectors:
type: S3VectorsStore
bucket: your-bucket-name
region: us-east-1
aws:
credentials:
key: "%env(AWS_ACCESS_KEY_ID)%"
secret: "%env(AWS_SECRET_ACCESS_KEY)%"
Enable S3 Vectors on your bucket (via AWS CLI or Console):
aws s3api put-bucket-vector --bucket your-bucket-name --region us-east-1
First Usage (inject the store via Symfony’s DI or manually):
use Symfony\AI\Store\S3VectorsStore;
$store = new S3VectorsStore('your-bucket-name', 'us-east-1');
$store->putVectors([
'vector1' => [0.1, 0.2, 0.3], // Example vector
'vector2' => [0.4, 0.5, 0.6],
]);
$results = $store->queryVectors([0.15, 0.25, 0.35], 5); // Query with a vector, limit 5 results
S3VectorsStore class for method signatures and error handling.Semantic Search for a Blog:
$embeddings = $this->generateEmbeddings($userQuery);
$results = $this->ai->store('s3_vectors')->queryVectors($embeddings, 5);
$store->putVectors([
'post_1' => [0.1, 0.2, ...], // Vector ID as key
'post_2' => [0.3, 0.4, ...],
]);
$store->putVectors(['dynamic_id' => $vector]);
$results = $store->queryVectors($queryVector, 10); // Top 10 matches
['id' => 'vector_id', 'distance' => float].AiClient to abstract store operations:
$this->ai->store('s3_vectors')->putVectors($vectors);
$matches = $this->ai->store('s3_vectors')->queryVectors($query, 5);
try {
$results = $store->queryVectors($vector);
} catch (AwsException $e) {
$this->logger->error('S3 Vectors query failed', ['error' => $e->getMessage()]);
// Fallback logic (e.g., retry or return cached results)
}
%env% or AWS SDK’s default chain (e.g., ~/.aws/credentials).{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutBucketVector",
"s3:GetBucketVector",
"s3:PutObject",
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::your-bucket-name",
"arn:aws:s3:::your-bucket-name/*"
]
}
]
}
[0.1, 0.2, 0.3])."user_123", "post_456").Messenger or SymfonyConcurrent to parallelize queries.Aws\S3\S3Client with a mock bucket for unit tests:
$mock = new Aws\S3\MockS3Client();
$store = new S3VectorsStore('mock-bucket', 'us-east-1', $mock);
PutVectors latency (aim for <500ms for batches).QueryVectors throughput (aim for <1s for top-10 results).S3 Vectors Not Enabled:
InvalidArgumentException or 400 Bad Request when calling PutVectors.aws s3api get-bucket-vector --bucket your-bucket-name
Vector Size Limits:
PayloadTooLargeException if vectors exceed 1MB.gzip) or split into multiple objects.AWS SDK Version Mismatch:
ClassNotFoundException for Aws\S3\S3Client.aws/aws-sdk-php is installed (^3.0) and compatible with the package.Throttling:
ProvisionedThroughputExceededException during high-volume operations.$client->retryConfig->setMaxRetries(3);
Vector ID Collisions:
user_{id}_post_{id}).Cold Starts:
$client = new Aws\S3\S3Client([
'region' => 'us-east-1',
'debug' => true,
'logger' => new Aws\Log\NullLogger(), // Or Psr\Log\LoggerInterface
]);
PutVectors/QueryVectors API calls.AWS_REGION env var or us-east-1.How can I help you explore Laravel packages today?