Skip to main content

BQ vector compression

Added in v1.23

Binary quantization (BQ) is a technique that reduces the size of a vector index. BQ is available for the flat index type.

To use BQ, enable it as shown below and add data to the collection.

Additional information

Simple BQ configuration

Each collection can be configured to use BQ compression. BQ must be enabled at collection creation time, before data is added to it.

This can be done by setting the vector index config of the collection to enable BQ compression.

import weaviate.classes as wvc

client.collections.create(
name="YourCollection",
vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
vector_index_config=wvc.config.Configure.VectorIndex.flat(),
properties=[
wvc.config.Property(name="title", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(name="body", data_type=wvc.config.DataType.TEXT),
]
)

client.close()

BQ with custom settings

The following parameters are available for BQ compression, under vectorIndexConfig:

ParameterTypeDefaultDetails
bq : enabledbooleanfalseEnable BQ. Weaviate uses binary quantization (BQ) compression when true.

The Python client v4 does not use the enabled parameter. To enable BQ with the v4 client, set a quantizer in the collection definition.
bq : rescoreLimitinteger-1The minimum number of candidates to fetch before rescoring.
bq : cachebooleanfalseWhether to use the vector cache.
vectorCacheMaxObjectsinteger1e12Maximum number of objects in the memory cache. By default, this limit is set to one trillion (1e12) objects when a new collection is created. For sizing recommendations, see Vector cache considerations.

For example:

import weaviate.classes as wvc

client.collections.create(
name="YourCollection",
vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
vector_index_config=wvc.config.Configure.VectorIndex.flat(
distance_metric=wvc.config.VectorDistances.COSINE,
vector_cache_max_objects=1000000,
quantizer=wvc.config.Configure.VectorIndex.Quantizer.bq()
),
properties=[
wvc.config.Property(name="title", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(name="body", data_type=wvc.config.DataType.TEXT),
]
)

client.close()

Multiple vectors

Added in v1.24.0

Weaviate collections support multiple, named vectors.

Collections can have multiple, named vectors. Each vector is independent. Each vector space has its own index, its own compression, and its own vectorizer. This means you can create vectors for properties, use different vectorization models, and apply different metrics to the same object.

You do not have to use multiple vectors in your collections, but if you do, you need to adjust your queries to specify which vector you want to use.

Similarly, compression must be enabled independently for each vector. The procedure varies slightly by client language, but in each case the idea is the same. Each vector is independent and can use PQ, BQ, or no compression.