Connect, create a collection, insert vectors, search, retrieve, update, delete, and inspect collection info using the Python SDK.
This tutorial walks you through a complete Python workflow with VectorAI DB. You connect to the server, create a collection, insert vectors with metadata, search by similarity, retrieve points by ID, update and delete records, and inspect collection statistics.
Before diving into the tasks, understand these key concepts:Async client — The Python SDK uses AsyncVectorAIClient for non-blocking I/O. All SDK calls use async/await syntax and are run with asyncio.run(). There is no synchronous client; the async model keeps your application responsive while waiting on network operations.Points — Points are the individual records stored in a collection. Each point contains:
ID: A unique identifier (integer or UUID).
Vector: A list of floats matching the collection dimension.
Payload: An optional metadata dictionary for filtering and retrieval.
Upsert — Upsert inserts new points or updates existing ones with the same ID. It is the primary method for adding and modifying data.
Work through these tasks to create and manage your first collection in Python.The Python SDK is fully asynchronous. Every operation returns a coroutine that you await inside an async function. If you are new to Python async programming, asyncio.run() is the standard way to execute a top-level coroutine from synchronous code — there is no separate synchronous client.
import asynciofrom actian_vectorai import AsyncVectorAIClientasync def connect(): """Connect to VectorAI DB and verify connection.""" async with AsyncVectorAIClient("localhost:50051") as client: # List existing collections to verify connection collections = await client.collections.list() print(f"Connected! Found {len(collections)} existing collections") return Trueasyncio.run(connect())
A successful connection prints a message such as Connected! Found 0 existing collections. If you see this output, your client has reached the server and is ready for the next steps. If the command raises an error instead, see the Troubleshooting section below.
Use the AsyncVectorAIClient context manager to ensure connections are properly closed. This prevents resource leaks in production applications.
The following script combines all operations from the tasks above into a single runnable workflow.
import asynciofrom actian_vectorai import AsyncVectorAIClient, VectorParams, Distance, PointStructimport randomasync def complete_workflow(): """Complete VectorAI DB workflow demonstration.""" async with AsyncVectorAIClient("localhost:50051") as client: collection_name = "demo_collection" # 1. Create collection exists = await client.collections.exists(collection_name) if exists: await client.collections.delete(collection_name) await client.collections.create( collection_name, vectors_config=VectorParams(size=128, distance=Distance.Cosine) ) print("1. Created collection") # 2. Insert data points = [ PointStruct( id=i, vector=[random.gauss(0, 1) for _ in range(128)], payload={"index": i, "category": f"cat_{i % 3}"} ) for i in range(100) ] await client.points.upsert(collection_name, points=points) print("2. Inserted 100 points") # 3. Search query = [random.gauss(0, 1) for _ in range(128)] results = await client.points.search( collection_name, vector=query, limit=3, with_payload=True ) print("3. Search results:") for r in results: print(f" ID: {r.id}, Score: {r.score:.4f}") # 4. Get info count = await client.points.count(collection_name) print(f"4. Collection has {count.count} points") # 5. Cleanup (optional — uncomment to delete the collection after testing; # leave it commented out if you want to keep the data for later tasks) # await client.collections.delete(collection_name) # print("5. Deleted collection")asyncio.run(complete_workflow())
The following accordions cover common errors and how to resolve them.
Connection refused
Cause: VectorAI DB server not running.Solution: Start the server with docker run -p 50051:50051 actian/vectorai-db
Dimension mismatch
Cause: Vector size doesn’t match collection configuration.Solution: Verify vectors have the same dimension as the collection’s size parameter.
Collection not found
Cause: Collection name misspelled or doesn’t exist.Solution: Check exact collection name with client.collections.list().
Permission denied
Cause: Authentication is required by your VectorAI DB instance.Solution: Pass your credentials when initialising the client. See Security and authentication for the full configuration options.