Skip to content

Commit

Permalink
Merge pull request #7 from oramasearch/feat/implements-pq-residual
Browse files Browse the repository at this point in the history
feat: implements PQ Residual
  • Loading branch information
micheleriva authored Dec 5, 2024
2 parents adff73a + 18b03bd commit 9aa9a08
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 7 deletions.
119 changes: 119 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ log = "0.4.22"
thiserror = "2.0.3"
env_logger = "0.11.5"
serde = { version = "1.0.215", features = ["derive"] }
numpy = "0.23.0"
num-traits = "0.2.19"

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down
18 changes: 18 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ use crate::pq::CodeType;
use ndarray::Ix;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum PQResidualError {
#[error("Must use at least one product quantizer")]
MissingProductQuantizer,

#[error("Missing dataset name")]
MissingDatasetName,

#[error("Model not trained. Call fit() before calling this method")]
ModelNotTrained,

#[error("I/O error: {0}")]
Io(#[from] std::io::Error),

#[error("PQ Residual error: {0}")]
Pq(#[from] PQError),
}

#[derive(Error, Debug)]
pub enum PQError {
#[error("Number of clusters (ks) must be between 1 and 2**32 - 1. Got {0}")]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod errors;
pub mod pq;
mod pq_residual;
mod utils;
14 changes: 7 additions & 7 deletions src/pq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use log::{info, trace, warn};
use ndarray::parallel::prelude::*;
use ndarray::{s, Array2, Array3, Axis};

#[derive(Debug, Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum CodeType {
U8,
U16,
U32,
}

pub struct PQ {
m: usize,
ks: u32,
code_dtype: CodeType,
codewords: Option<Array3<f32>>,
ds: Option<Vec<usize>>,
dim: Option<usize>,
pub m: usize,
pub code_dtype: CodeType,
pub ks: u32,
pub codewords: Option<Array3<f32>>,
pub ds: Option<Vec<usize>>,
pub dim: Option<usize>,
}

impl PQ {
Expand Down
Loading

0 comments on commit 9aa9a08

Please sign in to comment.