import random
from actian_vectorai import VectorAIClient, PointStruct
DIMENSION = 128
COLLECTION = "products"
# Connect to VectorAI DB server
with VectorAIClient("localhost:50051") as client:
# Prepare update data
updates = [
{"id": 2, "name": "5G Smartphone", "category": "electronics", "price": 899.99, "updated": True},
{"id": 3, "name": "Pro Tablet", "category": "electronics", "price": 799.99, "updated": True},
{"id": 4, "name": "Premium T-Shirt", "category": "clothing", "price": 49.99, "updated": True}
]
# Create points with new data
points = [
PointStruct(
id=item["id"], # Point ID to update
vector=[random.gauss(0, 1) for _ in range(DIMENSION)], # New vector
payload={k: v for k, v in item.items() if k != "id"} # Extract payload fields (optional)
)
for item in updates
]
# Batch update all points
client.points.upsert(COLLECTION, points)
print(f"Updated {len(points)} points")