DiskIndexWriter

Struct DiskIndexWriter 

Source
pub struct DiskIndexWriter { /* private fields */ }
Expand description

DiskIndexWriter is used to write disk index data to the storage system. The storage system and data types are provided as parameters to methods that need them.

Implementations§

Source§

impl DiskIndexWriter

Source

pub fn new( dataset_file: String, index_path_prefix: String, associated_data_file: Option<String>, block_size: usize, ) -> ANNResult<Self>

Create DiskIndexWriter instance

Source

pub fn dataset_file(&self) -> &String

Source

pub fn index_path_prefix(&self) -> &String

Source

pub fn block_size(&self) -> usize

Source

pub fn create_disk_layout<Data, StorageProvider>( &self, storage_provider: &StorageProvider, ) -> ANNResult<()>
where Data: GraphDataType<VectorIdType = u32>, StorageProvider: StorageReadProvider + StorageWriteProvider,

Create disk layout. Block #1: GraphMetadata. Block #2..#n: num_nodes_per_block nodes in each block

GraphMetadata layout: |number_of_points (8 bytes)| dimensions (8 bytes) | medoid (8 bytes) | …| node_len (8 bytes) | num_nodes_per_sector (8 bytes) | vamana_frozen_point_num (8 bytes) | …| vamana_frozen_loc (8 bytes) | append_reorder_data (8 bytes) | disk_index_file_size (8 bytes) | …| associated_data_length (8 bytes) | block_size (8 bytes) | layout_version (8 bytes) |

The metadata layout is kept compatible with the C++ diskann codebase.

After the metadata structure, the graph is laid out as a sequence of vertices and relevant data including the vector, #out neighbors, list of out neighbors, associated_data and appropriate padding. | vector (dim * size_of<VectorDataType> bytes) | neighbor_count (4 bytes) | neighbors (neighbor_count * 4 bytes) | ... | filler | associated_data (associated_data_length * size_of<AssociatedDataType> bytes) |

The node_len and length of filler are calculated as follow:

node_length = (max_degree + 1) * size_of<u32> + dim * size_of<VectorDataType> + associated_data_length * size_of<AssociatedDataType>

filler length = node_len - (length of vector + 4 + 4 * neighbor_count + associated_data_length * size_of<AssociatedDataType>)

The filler is used to pad each node to node_len bytes on the disk, so it is possible to calculate the block number and offset of a node with its Id.

When node_len < disk block size, we pack as many nodes as possible in to the disk sector without splitting a node across a sector For example, if node_len is 600B, we can pack 6 of these on a 4KB sector, and we leave 4096-3600 = 496B unused.

When node_len > disk block size, we align start of node to block size. For example, if node_len is 6700B, then it would span two 4KB sectors beginning at the start of the first sector and end on the second sector and will be followed by 1492 bytes of padding to align the next node to block boundary.

§Arguments
  • storage_provider - the storage provider for I/O operations
Source

pub fn index_build_cleanup<StorageProvider>( &self, storage_provider: &StorageProvider, ) -> ANNResult<()>
where StorageProvider: StorageReadProvider + StorageWriteProvider,

Source

pub fn disk_index_file(&self) -> String

Source

pub fn get_pq_pivot_file(&self) -> String

Source

pub fn get_compressed_pq_pivot_file(&self) -> String

Source

pub fn get_disk_index_pq_pivot_file(&self) -> String

Source

pub fn get_disk_index_compressed_pq_file(&self) -> String

Source

pub fn get_index_path_prefix(&self) -> String

Source

pub fn get_dataset_file(&self) -> String

Source

pub fn get_associated_data_file(&self) -> Option<String>

Source

pub fn get_mem_index_file(&self) -> String

Source

pub fn get_merged_index_prefix(&self) -> String

Source

pub fn get_merged_index_subshard_id_map_file( prefix: &str, shard: usize, ) -> String

Source

pub fn get_merged_index_subshard_data_file(prefix: &str, shard: usize) -> String

Source

pub fn get_merged_index_subshard_prefix(prefix: &str, shard: usize) -> String

Source

pub fn get_merged_index_subshard_mem_index_file( prefix: &str, shard: usize, ) -> String

Source

pub fn get_merged_index_subshard_mem_dataset_file( subshard_mem_index_prefix: &str, ) -> String

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,