pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: aminst (@aminst) <noreply+aminst@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #605: Product Quantization
Date: Thu, 04 Jul 2024 00:04:34 +0000
Message-ID: <gh-pgvector-pgvector-605-c2207585272@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-605@github.com>
References: <gh-pgvector-pgvector-605@github.com>

I read the IVF code to see how PQ can be implemented without adding a new index. I think it is possible, but I wanted to mention my ideas to ensure backward compatibility.
I'm thinking of the following changes to the current IVF implementation:

## Overall Page Structure
I don't think there is a need to change the structure of the list pages since PQ does not quantize the centroids from what I have understood from the paper and the Faiss implementation. However, the PQ implementation will need new pages to store subvector centroids. If we have M subvectors, and we want to create K centroids for each subspace, this will result in M * K centroids being stored in the new **codebook** pages.

## ivfflatbuild
There is no change for the Meta and List pages, but we should create codebook pages and run the current K-means M times for each subvector space. Please correct me if I'm wrong, but I also don't think we need to change the code to create the entry pages since the new PQ-encoded vector type will handle that. 

## ivfflatinsert
The `FindInsertPage` function will remain untouched since the ivf centroids are not quantized. We only need to encode and store the PQ-encoded version of the vector using the *codebook* pages.

## ivfscan
This can also remain unchanged since we are still doing IVF search, and the distance function should do the PQ distance functionality. There are many ways to do the distance calculation according to the Product Quantization paper itself, but I think some need more pages to precalculate distances between codebook centroids, which can be next step optimizations.

# Questions
* Will adding the new codebook pages cause any problems for the backward compatibility of the code?
* I tried to think a lot about how to implement this so there is no need for a new index type, and the complexity is manageable. Do you think the overall idea achieves this?
* I would appreciate any other comments you might have for the implementation.

Thanks.

view thread (6+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-605-c2207585272@github.com>
Permalink:  ../gh-pgvector-pgvector-605-c2207585272@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox