Skip to main content

S3Vectors provider for Stache AI

Project description

stache-ai-s3vectors

S3 Vectors provider for Stache AI - serverless vector database using Amazon S3 Vectors.

Installation

pip install stache-ai-s3vectors

Usage

Install the package and configure the provider in your settings:

from stache_ai.config import Settings

settings = Settings(
    vectordb_provider="s3vectors",
    s3vectors_bucket_name="my-vector-bucket",  # Required
    s3vectors_region="us-east-1",              # Optional, defaults to AWS_REGION
)

The provider will be automatically discovered via entry points.

Environment Variables

Variable Description Default
VECTORDB_PROVIDER Set to s3vectors Required
S3VECTORS_BUCKET_NAME S3 Vectors bucket name Required
S3VECTORS_REGION AWS region for S3 Vectors us-east-1
AWS_REGION Fallback region us-east-1

IAM Permissions

The S3 Vectors provider requires specific IAM permissions. Note that S3 Vectors uses its own service namespace (s3vectors:), not the standard S3 namespace.

Minimum Required Permissions

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3vectors:GetVectorBucket"
      ],
      "Resource": "arn:aws:s3vectors:REGION:ACCOUNT:vector-bucket/BUCKET_NAME"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3vectors:CreateIndex",
        "s3vectors:GetIndex",
        "s3vectors:ListIndexes",
        "s3vectors:PutVectors",
        "s3vectors:QueryVectors",
        "s3vectors:ListVectors",
        "s3vectors:DeleteVectors",
        "s3vectors:GetVectors"
      ],
      "Resource": "arn:aws:s3vectors:REGION:ACCOUNT:vector-bucket/BUCKET_NAME/index/*"
    }
  ]
}

SAM Template Example

Resources:
  S3VectorsBucket:
    Type: AWS::S3Vectors::VectorBucket
    Properties:
      VectorBucketName: !Sub '${AWS::StackName}-vectors'

  StacheFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          VECTORDB_PROVIDER: s3vectors
          S3VECTORS_BUCKET_NAME: !GetAtt S3VectorsBucket.VectorBucketName
      Policies:
        - Version: '2012-10-17'
          Statement:
            - Effect: Allow
              Action:
                - s3vectors:GetVectorBucket
              Resource:
                - !GetAtt S3VectorsBucket.VectorBucketArn
            - Effect: Allow
              Action:
                - s3vectors:CreateIndex
                - s3vectors:GetIndex
                - s3vectors:ListIndexes
                - s3vectors:PutVectors
                - s3vectors:QueryVectors
                - s3vectors:ListVectors
                - s3vectors:DeleteVectors
                - s3vectors:GetVectors
              Resource:
                - !Sub '${S3VectorsBucket.VectorBucketArn}/index/*'

Terraform Example

data "aws_iam_policy_document" "s3vectors" {
  statement {
    effect = "Allow"
    actions = [
      "s3vectors:GetVectorBucket"
    ]
    resources = [
      "arn:aws:s3vectors:${var.region}:${data.aws_caller_identity.current.account_id}:vector-bucket/${var.bucket_name}"
    ]
  }

  statement {
    effect = "Allow"
    actions = [
      "s3vectors:CreateIndex",
      "s3vectors:GetIndex",
      "s3vectors:ListIndexes",
      "s3vectors:PutVectors",
      "s3vectors:QueryVectors",
      "s3vectors:ListVectors",
      "s3vectors:DeleteVectors",
      "s3vectors:GetVectors"
    ]
    resources = [
      "arn:aws:s3vectors:${var.region}:${data.aws_caller_identity.current.account_id}:vector-bucket/${var.bucket_name}/index/*"
    ]
  }
}

Important Notes

Bucket Name vs ARN

The provider uses the bucket name (not the ARN) for API calls, but IAM policies require the full ARN format:

  • Environment variable: S3VECTORS_BUCKET_NAME=my-vectors-bucket (just the name)
  • IAM Resource: arn:aws:s3vectors:us-east-1:123456789012:vector-bucket/my-vectors-bucket (full ARN)

S3 Vectors bucket names are globally unique across AWS, so include your account ID or a unique prefix:

# SAM template example
VectorBucketName: !Sub '${AWS::StackName}-vectors-${AWS::AccountId}'

Metadata Limits

S3 Vectors has metadata size limits:

  • Filterable metadata: 2KB limit (used in query filters)
  • Non-filterable metadata: Part of 40KB total (returned but can't filter)

When creating indexes, specify large fields like text as non-filterable:

aws s3vectors create-index \
  --vector-bucket-name my-bucket \
  --index-name my-index \
  --dimension 1024 \
  --distance-metric cosine \
  --metadata-configuration 'nonFilterableMetadataKeys=["text"]'

list_vectors Limitation

The list_vectors API does NOT support metadata filtering - only query_vectors supports filtering. For operations that need to filter without a query vector, the provider lists all vectors and filters client-side.

Requirements

  • Python >= 3.10
  • stache-ai >= 0.1.0
  • boto3 >= 1.34.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stache_ai_s3vectors-0.1.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stache_ai_s3vectors-0.1.3-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file stache_ai_s3vectors-0.1.3.tar.gz.

File metadata

  • Download URL: stache_ai_s3vectors-0.1.3.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for stache_ai_s3vectors-0.1.3.tar.gz
Algorithm Hash digest
SHA256 33856fe3fed0aca2c92909fc62b1bea86197917f34c6ccbc0c489d4959374f0c
MD5 e852a688fa8a06bd739d2ee0285f537c
BLAKE2b-256 2dcd5b9e9c5fb48a753055883226831c36db4dbf7b46d46a03c9ff686fcd141d

See more details on using hashes here.

File details

Details for the file stache_ai_s3vectors-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for stache_ai_s3vectors-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e11aee62f6c64fba1152107c8dc0de3628239959cb0903537693c0095a04a2ff
MD5 8a5fb6e06b098cb0ed02190944735469
BLAKE2b-256 85657a3009eda59ac8a15b36d1d3733ad5949f2846052505e06b9eb1467eaca9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page