SDKs & CLIs
Vector Database
Python

Python

1. Install The Dependencies

Install the required library using pip:

pip install boto3

2. Setup The Environment

Set your AIOZ Storage credentials as environment variables. You can find these values in the AIOZ Storage dashboard (opens in a new tab).

export ACCESS_KEY=<your-access-key>
export SECRET_KEY=<your-secret-key>

3. Create a Vector Bucket

A vector bucket is a dedicated namespace that holds your vector indexes. Create one before creating any indexes:

import boto3
 
client = boto3.client(
    's3vectors',
    region_name='us-east-1',
    aws_access_key_id='YOUR_ACCESS_KEY',
    aws_secret_access_key='YOUR_SECRET_KEY',
    endpoint_url='AIOZ_STORAGE_ENDPOINT_URL'
)
 
client.create_vector_bucket(
    vectorBucketName='YOUR_BUCKET_NAME'
)

4. Create a Vector Index

A vector index is where your embeddings are stored. You must create one before inserting any vectors. Set the dimension to match the output size of your embedding model (e.g. 1536 for OpenAI text-embedding-3-small).

client.create_index(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    dataType='float32',
    dimension=1536,
    distanceMetric='cosine'
)

5. Put Vectors

Store vector embeddings along with optional metadata:

client.put_vectors(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    vectors=[
        {
            'key': 'doc-001',
            'data': {'float32': [0.12, 0.87, 0.45, ...]},
            'metadata': {'title': 'Introduction to AI', 'source': 'blog'}
        },
        {
            'key': 'doc-002',
            'data': {'float32': [0.33, 0.61, 0.72, ...]},
            'metadata': {'title': 'Vector Search Explained', 'source': 'docs'}
        }
    ]
)

6. Query Vectors

Find the most similar vectors to a given query embedding:

response = client.query_vectors(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    queryVector={'float32': [0.11, 0.85, 0.47, ...]},
    topK=5,
    includeMetadata=True
)
 
for match in response['vectors']:
    print(match['key'], match['distance'], match['metadata'])

7. Delete Vectors

Remove vectors from the index by their keys:

client.delete_vectors(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    keys=['doc-001', 'doc-002']
)

Minimal Code Example

import boto3
 
client = boto3.client(
    's3vectors',
    region_name='us-east-1',
    aws_access_key_id='YOUR_ACCESS_KEY',
    aws_secret_access_key='YOUR_SECRET_KEY',
    endpoint_url='AIOZ_STORAGE_ENDPOINT_URL'
)
 
# Create vector bucket
client.create_vector_bucket(
    vectorBucketName='YOUR_BUCKET_NAME'
)
 
# Create index
client.create_index(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    dataType='float32',
    dimension=3,
    distanceMetric='cosine'
)
 
# Store vectors
client.put_vectors(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    vectors=[
        {
            'key': 'doc-001',
            'data': {'float32': [0.12, 0.87, 0.45]},
            'metadata': {'title': 'Example document'}
        }
    ]
)
 
# Query similar vectors
response = client.query_vectors(
    vectorBucketName='YOUR_BUCKET_NAME',
    indexName='my-index',
    queryVector={'float32': [0.11, 0.85, 0.47]},
    topK=5,
    includeMetadata=True
)
 
for match in response['vectors']:
    print(match['key'], match['distance'], match['metadata'])