Skip to content

Commit

Permalink
Rename HnswIvf to Spann (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
hicder authored Dec 4, 2024
1 parent f9db81d commit 34bbb5d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rs/index_server/src/index_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl IndexProvider {
}
}
index_writer::config::IndexType::Ivf => todo!(),
index_writer::config::IndexType::HnswIvf => {
index_writer::config::IndexType::Spann => {
let reader = SpannReader::new(index_path);
match reader.read() {
Ok(index) => Some(Box::new(index)),
Expand Down
6 changes: 3 additions & 3 deletions rs/index_writer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum IndexType {
Ivf,

#[default]
HnswIvf,
Spann,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -75,7 +75,7 @@ pub struct HnswConfigWithBase {
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct HnswIvfConfig {
pub struct SpannConfigWithBase {
pub base_config: BaseConfig,
pub hnsw_config: HnswConfig,
pub ivf_config: IvfConfig,
Expand All @@ -85,7 +85,7 @@ pub struct HnswIvfConfig {
pub enum IndexWriterConfig {
Hnsw(HnswConfigWithBase),
Ivf(IvfConfigWithBase),
HnswIvf(HnswIvfConfig),
Spann(SpannConfigWithBase),
}

impl Default for IndexWriterConfig {
Expand Down
10 changes: 5 additions & 5 deletions rs/index_writer/src/index_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use quantization::pq_builder::{ProductQuantizerBuilder, ProductQuantizerBuilderC
use rand::seq::SliceRandom;

use crate::config::{
HnswConfigWithBase, HnswIvfConfig, IndexWriterConfig, IvfConfigWithBase, QuantizerType,
HnswConfigWithBase, SpannConfigWithBase, IndexWriterConfig, IvfConfigWithBase, QuantizerType,
};
use crate::input::Input;

Expand Down Expand Up @@ -167,7 +167,7 @@ impl IndexWriter {
fn do_build_ivf_hnsw_index(
&mut self,
input: &mut impl Input,
index_writer_config: &HnswIvfConfig,
index_writer_config: &SpannConfigWithBase,
) -> Result<()> {
// Directory structure:
// hnsw_ivf_config.base_config.output_path
Expand Down Expand Up @@ -281,7 +281,7 @@ impl IndexWriter {
Ok(self.do_build_hnsw_index(input, &hnsw_config)?)
}
IndexWriterConfig::Ivf(ivf_config) => Ok(self.do_build_ivf_index(input, &ivf_config)?),
IndexWriterConfig::HnswIvf(hnsw_ivf_config) => {
IndexWriterConfig::Spann(hnsw_ivf_config) => {
Ok(self.do_build_ivf_hnsw_index(input, &hnsw_ivf_config)?)
}
}
Expand Down Expand Up @@ -508,7 +508,7 @@ mod tests {
dimension,
max_memory_size: 1024 * 1024 * 1024, // 1 GB
file_size: 1024 * 1024 * 1024, // 1 GB
index_type: IndexType::HnswIvf,
index_type: IndexType::Spann,
};
let hnsw_config = HnswConfig {
num_layers: 2,
Expand All @@ -533,7 +533,7 @@ mod tests {
tolerance: 0.0,
max_posting_list_size: usize::MAX,
};
let config = IndexWriterConfig::HnswIvf(HnswIvfConfig {
let config = IndexWriterConfig::Spann(SpannConfigWithBase {
base_config,
hnsw_config,
ivf_config,
Expand Down
10 changes: 5 additions & 5 deletions rs/index_writer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;

use clap::Parser;
use index_writer::config::{
HnswConfigWithBase, HnswIvfConfig, IndexWriterConfig, IvfConfigWithBase,
HnswConfigWithBase, IndexWriterConfig, IvfConfigWithBase, SpannConfigWithBase,
};
use index_writer::index_writer::IndexWriter;
use index_writer::input::hdf5::Hdf5Reader;
Expand All @@ -12,7 +12,7 @@ use index_writer::input::hdf5::Hdf5Reader;
enum IndexTypeArgs {
Hnsw,
Ivf,
HnswIvf,
Spann,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -59,11 +59,11 @@ fn main() {
config.base_config.output_path = arg.output_path;
IndexWriterConfig::Ivf(config)
}
IndexTypeArgs::HnswIvf => {
let mut config: HnswIvfConfig =
IndexTypeArgs::Spann => {
let mut config: SpannConfigWithBase =
serde_yaml::from_str(&buf).expect("Failed to parse config");
config.base_config.output_path = arg.output_path;
IndexWriterConfig::HnswIvf(config)
IndexWriterConfig::Spann(config)
}
};

Expand Down
6 changes: 3 additions & 3 deletions rs/index_writer/src/scripts/write_index_writer_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use std::fs::File;
use std::io::Write;

use index_writer::config::{BaseConfig, HnswConfig, HnswIvfConfig, IvfConfig, QuantizerType};
use index_writer::config::{BaseConfig, HnswConfig, SpannConfigWithBase, IvfConfig, QuantizerType};

fn main() -> std::io::Result<()> {
let mut base_config = BaseConfig::default();
base_config.dimension = 128;
base_config.output_path = "NONE".to_string();
base_config.max_memory_size = 1024 * 1024 * 1024; // 1 GB
base_config.file_size = 1024 * 1024 * 1024; // 1 GB
base_config.index_type = index_writer::config::IndexType::HnswIvf;
base_config.index_type = index_writer::config::IndexType::Spann;

let mut ivf_config = IvfConfig::default();
ivf_config.num_clusters = 5;
Expand All @@ -28,7 +28,7 @@ fn main() -> std::io::Result<()> {
hnsw_config.ef_construction = 200;
hnsw_config.reindex = false;

let mut config = HnswIvfConfig::default();
let mut config = SpannConfigWithBase::default();
config.base_config = base_config;
config.ivf_config = ivf_config;
config.hnsw_config = hnsw_config;
Expand Down

0 comments on commit 34bbb5d

Please sign in to comment.