Configure HNSW parameters when creating a collection to balance search speed, accuracy, and memory usage. Custom parameters are useful when default settings do not meet your recall or latency requirements.
Before you begin, make sure you have a running VectorAI DB instance. HNSW parameters can only be set at collection creation and cannot be changed afterward.
Create a collection with custom parameters
The following example creates a collection with custom m and ef_construct values inside HnswConfigDiff.
from actian_vectorai import VectorAIClient, VectorParams, Distance, HnswConfigDiff
# Connect to VectorAI DB server (use context manager to ensure proper connection)
with VectorAIClient("localhost:50051") as client:
# Create collection with custom HNSW parameters
client.collections.create(
"my_collection", # Collection name
vectors_config=VectorParams(size=384, distance=Distance.Cosine), # Vector configuration
hnsw_config=HnswConfigDiff(
m=32, # More connections for better recall
ef_construct=200 # Higher quality index
)
)
print("✓ Collection 'my_collection' created successfully")
Higher parameter values improve accuracy at the cost of increased memory usage, slower index construction, and longer search times. Lower values prioritize speed and memory efficiency but can reduce recall.
Create a collection with default settings
When you omit hnsw_config, VectorAI DB applies balanced default settings that work well for general-purpose vector search. Test with your data to determine if custom parameters provide improvements.
from actian_vectorai import VectorAIClient, VectorParams, Distance
# Connect to VectorAI DB server
with VectorAIClient("localhost:50051") as client:
# Collection with default index settings
client.collections.create(
"my_collection", # Collection name
vectors_config=VectorParams(size=384, distance=Distance.Cosine) # Vector configuration
# hnsw_m=16 (default)
# hnsw_ef_construct=200 (default)
# hnsw_ef_search=50 (default)
)
print("✓ Collection created successfully")