Notebooks
W
Weaviate
PQ Compression Openai

PQ Compression Openai

vector-searchvector-databaseretrieval-augmented-generationllm-frameworksquantizationweaviate-featuresfunction-callingweaviate-recipesproduct-quantizationPythongenerative-ai

Open In Colab

Enabling Product Quantization(PQ) Vector Compression for your Class

In order to compress vectors using PQ you need:

1. Connect to a Weaviate instance and create a Collection

2. Add datapoints to the class - it is recommended to add atleast 10k-100k objects to Weaviate before enabling PQ

3. Enable PQ by updating the Collection config (This will take the datapoints and vectors already added to Weaviate and will train the PQ algorithm on them - learning centroids that can be used to compress current and any future added vectors):

a. You can specify the `trainingLimit` which will allow you to dictate how many of the added vectors will be used to train the centroids. By default this will take upto the first 100k objects added to Weaviate

b. You can specify the `segments` to use which will specify how many pieces to quantize the vectors into. This will dictate the compression rate.

1. Connect to the Weaviate instance:

[ ]

Create a collection

By default PQ will be disabled, as it needs to be enabled after enough data is loaded.

[ ]

2. Add data to the instance:

[ ]
[ ]
[ ]

Perform a vector search:

[ ]

3. Enable PQ by updating the Collection config:

[ ]

Your Weaviate instance will then enable compression and if you're monitoring the instance it will log the following:

product_quantization_compression-weaviate-1  | {"action":"compress","level":"info","msg":"switching to compressed vectors","time":"2023-11-13T21:10:52Z"}

product_quantization_compression-weaviate-1  | {"action":"compress","level":"info","msg":"vector compression complete","time":"2023-11-13T21:10:53Z"}

Re-run the same vector search now on PQ compressed vectors, (Rescoring is enabled by default)

[ ]