Skip to content
/ vq Public
generated from habedi/template-rust-project

A vector quantization library for Rust 🦀

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

habedi/vq

Vq

Tests Code Coverage CodeFactor Crates.io Docs.rs Downloads MSRV
Docs License

Vq (v[ector] q[uantizer]) is a Rust library that implements several popular vector quantization algorithms including binary, scalar, and product quantization algorithms. It provides a simple, efficient API for data compression that helps reduce memory usage and computational overhead.

Features

Installation

cargo add vq

Vq requires Rust 1.83 or later.

Documentation

Find the latest documentation on docs.rs.

Check out vq_examples.rs the tests directory for detailed examples of using Vq.

Quick Example

Here's a simple example using the SQ algorithm to quantize a vector:

use vq::sq::ScalarQuantizer;
use vq::vector::Vector;

fn main() {
    // Create a scalar quantizer for values in the range [0.0, 1.0] with 256 levels.
    let quantizer = ScalarQuantizer::fit(0.0, 1.0, 256);

    // Create an input vector.
    let input = Vector::new(vec![0.1, 0.5, -0.8, -0.3, 0.9]);

    // Quantize the input vector.
    let quantized_input = quantizer.quantize(&input);

    println!("Quantized input vector: {}", quantized_input);
}

Performance

Check out the notebooks directory for information on how to evaluate the performance of the implemented algorithms. Additionally, see the content of src/bin directory for the scripts used for the evaluation.

On a ThinkPad T14 laptop with an Intel i7-1355U CPU and 32GB of RAM, the performance of the PQ algorithm for quantizing one million vectors of 128 dimensions (into 16 subspaces with 256 centroids per subspace) is as follows:

  • Training Time: 232.5 seconds
  • Quantization Time: 34.1 seconds
  • Reconstruction Error: 0.02
  • Recall@10: 0.19

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details on contributing.

License

Vq is available under the terms of either of the following licenses: