Skip to main content
Each point can carry a JSON payload with metadata fields such as categories, prices, and timestamps. These fields become available for filtering during search.

Insert a point with payload

The payload parameter accepts any valid JSON structure. Include only the fields you need for filtering or displaying results. To create one point with metadata:
import random
from actian_vectorai import VectorAIClient, PointStruct

DIMENSION = 128
COLLECTION = "products"

# Connect to VectorAI DB server
with VectorAIClient("localhost:50051") 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 with payload created successfully")

Insert multiple points with payloads

Batch operations are more efficient than individual inserts. Each payload in the list corresponds to the point at the same index in the IDs and vectors lists. To create multiple points with metadata at once:
import random
from actian_vectorai import VectorAIClient, PointStruct

DIMENSION = 128
COLLECTION = "products"

# Connect to VectorAI DB server
with VectorAIClient("localhost:50051") as client:
    random.seed(42)  # Reproducible random vectors

    # Prepare batch data
    payloads = [
        {"category": "electronics", "price": 299.99, "in_stock": True},
        {"category": "electronics", "price": 599.99, "in_stock": True},
        {"category": "clothing", "price": 49.99, "in_stock": True},
        {"category": "clothing", "price": 79.99, "in_stock": False},
        {"category": "food", "price": 9.99, "in_stock": True},
        {"category": "food", "price": 4.99, "in_stock": True},
        {"category": "books", "price": 19.99, "in_stock": False},
        {"category": "books", "price": 24.99, "in_stock": True},
        {"category": "toys", "price": 39.99, "in_stock": True},
        {"category": "toys", "price": 59.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(payloads)
    ]

    # Batch insert all points
    client.points.upsert(COLLECTION, points)
    print(f"Batch inserted {len(points)} points with payloads")