Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.vectoraidb.actian.com/llms.txt

Use this file to discover all available pages before exploring further.

Insert individual points or batches of points into your collection. Points can include optional payload metadata.
Before you begin, make sure you have a running VectorAI DB instance and an existing collection. Vectors must match the dimension configured for the collection. See Create a collection to set one up.

Insert a single point

The insert() method is an alias for upsert(). A new ID inserts a new point, while an existing ID updates the point with the new vector and payload.
import random
from actian_vectorai import VectorAIClient, PointStruct

DIMENSION = 128
COLLECTION = "products"

# Connect to VectorAI DB server
with VectorAIClient("localhost:6574") as client:
    # Generate vector from your embedding model
    vector = [random.gauss(0, 1) for _ in range(DIMENSION)]
    
    # Insert point with payload
    point = PointStruct(
        id=1,  # Point ID
        vector=vector,  # Vector embedding
        payload={  # Metadata (optional)
            "name": "Laptop",
            "category": "electronics",
            "price": 999.99,
            "in_stock": True
        }
    )
    
    # Upsert point to collection
    client.points.upsert(COLLECTION, [point])
    print("Point inserted successfully")
Payload is optional. You can insert points with only ID and vector:
point = PointStruct(id=1, vector=vector)  # No payload
client.points.upsert(COLLECTION, [point])

Batch insert points

Batch operations are significantly faster than individual inserts. Use batch sizes between one hundred and one thousand points for optimal performance. The upsert_points() method is an alias for batch_upsert().
import random
from actian_vectorai import VectorAIClient, PointStruct

DIMENSION = 128
COLLECTION = "products"

# Connect to VectorAI DB server
with VectorAIClient("localhost:6574") as client:
    random.seed(42)  # Reproducible random vectors
    
    # Prepare batch data
    products = [
        {"name": "Smartphone", "category": "electronics", "price": 699.99, "in_stock": True},
        {"name": "Tablet", "category": "electronics", "price": 499.99, "in_stock": True},
        {"name": "T-Shirt", "category": "clothing", "price": 29.99, "in_stock": True},
        {"name": "Jeans", "category": "clothing", "price": 79.99, "in_stock": False},
        {"name": "Coffee Beans", "category": "food", "price": 12.99, "in_stock": True},
        {"name": "Energy Bar", "category": "food", "price": 2.99, "in_stock": True},
        {"name": "Python Book", "category": "books", "price": 39.99, "in_stock": False},
        {"name": "AI Textbook", "category": "books", "price": 89.99, "in_stock": True},
        {"name": "Action Figure", "category": "toys", "price": 24.99, "in_stock": True},
        {"name": "Board Game", "category": "toys", "price": 49.99, "in_stock": False}
    ]
    
    # Create points with vectors and payloads
    points = [
        PointStruct(
            id=i + 1,  # Point ID
            vector=[random.gauss(0, 1) for _ in range(DIMENSION)],  # Generate vector
            payload=payload  # Attach metadata (optional)
        )
        for i, payload in enumerate(products)
    ]
    
    # Batch insert all points
    client.points.upsert(COLLECTION, points)
    
    print(f"Successfully inserted {len(points)} points")