pub struct Database<T, FS> { /* private fields */ }Expand description
Stored database.
Implementations§
source§impl<T, FS> Database<T, FS>where
FS: FileSystem,
impl<T, FS> Database<T, FS>where FS: FileSystem,
sourcepub fn vector_size(&self) -> usize
pub fn vector_size(&self) -> usize
Returns the vector size.
sourcepub fn num_partitions(&self) -> usize
pub fn num_partitions(&self) -> usize
Returns the number of partitions.
sourcepub fn num_divisions(&self) -> usize
pub fn num_divisions(&self) -> usize
Returns the number of subvector divisions.
sourcepub fn subvector_size(&self) -> usize
pub fn subvector_size(&self) -> usize
Returns the subvector size.
sourcepub fn get_partition_id(&self, index: usize) -> Option<&String>
pub fn get_partition_id(&self, index: usize) -> Option<&String>
Returns the ID of a partition.
None if index ≥ num_partitions.
sourcepub fn get_codebook_id(&self, index: usize) -> Option<&String>
pub fn get_codebook_id(&self, index: usize) -> Option<&String>
Returns a code vector in a specified division.
None if index ≥ num_divisons.
source§impl<T, FS> Database<T, FS>where
FS: FileSystem,
Self: LoadPartition<T>,
impl<T, FS> Database<T, FS>where FS: FileSystem, Self: LoadPartition<T>,
sourcepub fn get_attribute<K>(
&self,
vector_id: &Uuid,
key: &K
) -> Result<Option<AttributeValueRef<'_>>, Error>where
String: Borrow<K>,
K: Hash + Eq + ?Sized,
pub fn get_attribute<K>( &self, vector_id: &Uuid, key: &K ) -> Result<Option<AttributeValueRef<'_>>, Error>where String: Borrow<K>, K: Hash + Eq + ?Sized,
Returns an attribute value of a given vector.
The first call to this function will take longer because it loads all
the attributes.
If you want to get attributes of your query results, please use
QueryResult::get_attribute instead.
None if the vector exists but no value is associated with key.
Fails if no vector is associated with vector_id.
source§impl<T, FS> Database<T, FS>where
T: Scalar,
FS: FileSystem,
Self: LoadPartition<T> + LoadCodebook<T> + LoadPartitionCentroids<T>,
impl<T, FS> Database<T, FS>where T: Scalar, FS: FileSystem, Self: LoadPartition<T> + LoadCodebook<T> + LoadPartitionCentroids<T>,
sourcepub fn query<'a, V>(
&'a self,
v: &V,
k: NonZeroUsize,
nprobe: NonZeroUsize
) -> Result<Vec<QueryResult<'a, T, FS>>, Error>where
V: AsSlice<T> + ?Sized,
pub fn query<'a, V>( &'a self, v: &V, k: NonZeroUsize, nprobe: NonZeroUsize ) -> Result<Vec<QueryResult<'a, T, FS>>, Error>where V: AsSlice<T> + ?Sized,
Queries k-nearest neighbors (k-NN) of a given vector.
The first call to this function will take longer because it lazily loads partition centroids, and codebooks.
sourcepub fn query_with_events<'a, V, EventHandler>(
&'a self,
v: &V,
k: NonZeroUsize,
nprobe: NonZeroUsize,
event: EventHandler
) -> Result<Vec<QueryResult<'a, T, FS>>, Error>where
V: AsSlice<T> + ?Sized,
EventHandler: FnMut(QueryEvent),
pub fn query_with_events<'a, V, EventHandler>( &'a self, v: &V, k: NonZeroUsize, nprobe: NonZeroUsize, event: EventHandler ) -> Result<Vec<QueryResult<'a, T, FS>>, Error>where V: AsSlice<T> + ?Sized, EventHandler: FnMut(QueryEvent),
Queries k-nearest neighbors (k-NN) of a given vector.
The first call to this function will take longer because it lazily loads partition centroids, and codebooks.
Trait Implementations§
source§impl<FS> LoadCodebook<f32> for Database<f32, FS>where
FS: FileSystem,
impl<FS> LoadCodebook<f32> for Database<f32, FS>where FS: FileSystem,
source§fn load_codebook(&self, index: usize) -> Result<BlockVectorSet<f32>, Error>where
FS: FileSystem,
fn load_codebook(&self, index: usize) -> Result<BlockVectorSet<f32>, Error>where FS: FileSystem,
Loads a codebook.
Fails if:
indexexceeds the number of codebooks.- codebook file cannot be loaded.
- vector size does not match the subvector size of the database.
- number of vectors does not match that of the database.
source§impl<FS> LoadDatabase<f32, FS> for Database<f32, FS>where
FS: FileSystem,
impl<FS> LoadDatabase<f32, FS> for Database<f32, FS>where FS: FileSystem,
source§fn load_database<P>(fs: FS, path: P) -> Result<Database<f32, FS>, Error>where
P: AsRef<str>,
fn load_database<P>(fs: FS, path: P) -> Result<Database<f32, FS>, Error>where P: AsRef<str>,
Loads a database.
Fails if:
vector_sizeis zeronum_divisionsis zeronum_partitionsis zeronum_codesis zerovector_sizeis not a multiple ofnum_divisionsnum_partitionsandpartitions_refs.len()do not matchvector_sizeand centroid size do not matchnum_divisionsandcodebook_refs.len()do not match
source§impl<FS> LoadPartition<f32> for Database<f32, FS>where
FS: FileSystem,
impl<FS> LoadPartition<f32> for Database<f32, FS>where FS: FileSystem,
source§fn load_partition(&self, index: usize) -> Result<Partition<f32>, Error>
fn load_partition(&self, index: usize) -> Result<Partition<f32>, Error>
Loads a partition.
Loads a Protocol Buffers message (p) from the file system.
Fails if:
indexexceeds the number of partitions.self.vector_sizeandp.vector_sizedo not matchself.num_divisionsandp.num_divisionsdo not matchp.num_vectorsandp.encoded_vectors.len()do not matchp.num_vectorsandp.vector_ids.len()do not matchp.num_divisionsand encoded vector length do not match