Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgreen42 committed Jan 22, 2025
2 parents 0c12de6 + d1b3d15 commit 87e908e
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 340 deletions.
4 changes: 2 additions & 2 deletions pgvectorscale/src/access_method/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ unsafe fn aminsert_internal(
&mut stats,
);
}
StorageType::SbqSpeedup | StorageType::SbqCompression => {
StorageType::SbqCompression => {
let bq = SbqSpeedupStorage::load_for_insert(
&heap_relation,
&index_relation,
Expand Down Expand Up @@ -286,7 +286,7 @@ fn do_heap_scan(

finalize_index_build(&mut plain, &mut bs, write_stats)
}
StorageType::SbqSpeedup | StorageType::SbqCompression => {
StorageType::SbqCompression => {
let mut bq =
SbqSpeedupStorage::new_for_build(index_relation, heap_relation, &meta_page);

Expand Down
2 changes: 0 additions & 2 deletions pgvectorscale/src/access_method/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ impl<QDM, PD> ListSearchResult<QDM, PD> {
tie_break_item_pointer,
candidates: BinaryHeap::with_capacity(search_list_size * neigbors),
visited: Vec::with_capacity(search_list_size * 2),
//candidate_storage: Vec::with_capacity(search_list_size * neigbors),
//best_candidate: Vec::with_capacity(search_list_size * neigbors),
inserted: HashSet::with_capacity(search_list_size * neigbors),
stats: GreedySearchStats::new(),
sdm: Some(sdm),
Expand Down
4 changes: 0 additions & 4 deletions pgvectorscale/src/access_method/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ pub fn label_vec_to_set(labels: Option<&[Label]>) -> LabelSet {
set
}

pub fn new_labelset() -> LabelSet {
[INVALID_LABEL; MAX_LABELS_PER_NODE]
}

pub struct LabeledVector {
vec: PgVector,
labels: Option<LabelVec>,
Expand Down
29 changes: 3 additions & 26 deletions pgvectorscale/src/access_method/meta_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,6 @@ impl MetaPage {
self.bq_num_bits_per_dimension
}

pub fn get_num_dimensions_for_neighbors(&self) -> u32 {
match StorageType::from_u8(self.storage_type) {
StorageType::Plain => {
error!("get_num_dimensions_for_neighbors should not be called for Plain storage")
}
StorageType::SbqSpeedup => self.num_dimensions_to_index,
StorageType::SbqCompression => 0,
}
}

/// Maximum number of neigbors per node. Given that we pre-allocate
/// these many slots for each node, this cannot change after the graph is built.
pub fn get_num_neighbors(&self) -> u32 {
Expand Down Expand Up @@ -204,24 +194,15 @@ impl MetaPage {

match self.get_storage_type() {
StorageType::Plain => None,
StorageType::SbqSpeedup | StorageType::SbqCompression => Some(self.quantizer_metadata),
StorageType::SbqCompression => Some(self.quantizer_metadata),
}
}

fn calculate_num_neighbors(
num_dimensions: u32,
num_bits_per_dimension: u8,
opt: &PgBox<TSVIndexOptions>,
) -> u32 {
fn calculate_num_neighbors(opt: &PgBox<TSVIndexOptions>) -> u32 {
let num_neighbors = (*opt).get_num_neighbors();
if num_neighbors == NUM_NEIGHBORS_DEFAULT_SENTINEL {
match (*opt).get_storage_type() {
StorageType::Plain => 50,
StorageType::SbqSpeedup => SbqNode::get_default_num_neighbors(
num_dimensions as usize,
num_dimensions as usize,
num_bits_per_dimension,
) as u32,
StorageType::SbqCompression => 50,
}
} else {
Expand Down Expand Up @@ -279,11 +260,7 @@ impl MetaPage {
num_dimensions,
num_dimensions_to_index,
storage_type: (*opt).get_storage_type() as u8,
num_neighbors: Self::calculate_num_neighbors(
num_dimensions,
bq_num_bits_per_dimension,
&opt,
),
num_neighbors: Self::calculate_num_neighbors(&opt),
bq_num_bits_per_dimension,
search_list_size: opt.search_list_size,
max_alpha: opt.max_alpha,
Expand Down
24 changes: 1 addition & 23 deletions pgvectorscale/src/access_method/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub unsafe fn init() {
pg_sys::add_string_reloption(
RELOPT_KIND_TSV,
"storage_layout".as_pg_cstr(),
"Storage layout: either memory_optimized, io_optimized, or plain".as_pg_cstr(),
"Storage layout: either memory_optimized or plain".as_pg_cstr(),
super::storage::DEFAULT_STORAGE_TYPE_STR.as_pg_cstr(),
Some(validate_storage_layout),
pg_sys::AccessExclusiveLock as pg_sys::LOCKMODE,
Expand Down Expand Up @@ -298,28 +298,6 @@ mod tests {
Ok(())
}

#[pg_test]
unsafe fn test_index_options_bq() -> spi::Result<()> {
Spi::run(
"CREATE TABLE test(encoding vector(3));
CREATE INDEX idxtest
ON test
USING diskann(encoding)
WITH (storage_layout = io_optimized);",
)?;

let index_oid =
Spi::get_one::<pg_sys::Oid>("SELECT 'idxtest'::regclass::oid")?.expect("oid was null");
let indexrel = PgRelation::from_pg(pg_sys::RelationIdGetRelation(index_oid));
let options = TSVIndexOptions::from_relation(&indexrel);
assert_eq!(options.get_num_neighbors(), NUM_NEIGHBORS_DEFAULT_SENTINEL);
assert_eq!(options.search_list_size, 100);
assert_eq!(options.max_alpha, DEFAULT_MAX_ALPHA);
assert_eq!(options.num_dimensions, NUM_DIMENSIONS_DEFAULT_SENTINEL);
assert_eq!(options.get_storage_type(), StorageType::SbqSpeedup);
Ok(())
}

#[pg_test]
unsafe fn test_index_options_plain() -> spi::Result<()> {
Spi::run(
Expand Down
Loading

0 comments on commit 87e908e

Please sign in to comment.