# Struct flechasdb::db::stored::Database

source ·

    pub struct Database<T, FS> { /* private fields */ }

Expand description

Stored database.

## Implementations§

source§

### impl<T, FS> Database<T, FS>where FS: FileSystem,

source

#### pub fn vector_size(&self) -> usize

Returns the vector size.

source

#### pub fn num_partitions(&self) -> usize

Returns the number of partitions.

source

#### pub fn num_divisions(&self) -> usize

Returns the number of subvector divisions.

source

#### pub fn num_codes(&self) -> usize

Returns the number of codes in each codebook.

source

#### pub fn subvector_size(&self) -> usize

Returns the subvector size.

source

#### pub fn get_partition_id(&self, index: usize) -> Option<&String>

Returns the ID of a partition.

`None` if `index` ≥ `num_partitions`.

source

#### 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>,

source

#### 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>,

source

#### 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.

source

#### 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,

source§

#### fn load_codebook(&self, index: usize) -> Result<BlockVectorSet<f32>, Error>where FS: FileSystem,

Loads a codebook.

Fails if:

- `index` exceeds 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,

source§

#### fn load_database<P>(fs: FS, path: P) -> Result<Database<f32, FS>, Error>where P: AsRef<str>,

Loads a database.

Fails if:

- `vector_size` is zero
- `num_divisions` is zero
- `num_partitions` is zero
- `num_codes` is zero
- `vector_size` is not a multiple of `num_divisions`
- `num_partitions` and `partitions_refs.len()` do not match
- `vector_size` and centroid size do not match
- `num_divisions` and `codebook_refs.len()` do not match

source§

### impl<FS> LoadPartition<f32> for Database<f32, FS>where FS: FileSystem,

source§

#### 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:

- `index` exceeds the number of partitions.
- `self.vector_size` and `p.vector_size` do not match
- `self.num_divisions` and `p.num_divisions` do not match
- `p.num_vectors` and `p.encoded_vectors.len()` do not match
- `p.num_vectors` and `p.vector_ids.len()` do not match
- `p.num_divisions` and encoded vector length do not match

source§

### impl<FS> LoadPartitionCentroids<f32> for Database<f32, FS>where FS: FileSystem,

source§

#### fn load_partition_centroids(&self) -> Result<BlockVectorSet<f32>, Error>

Loads partition centroids. Read more

## Auto Trait Implementations§

§

### impl<T, FS> !RefUnwindSafe for Database<T, FS>

§

### impl<T, FS> Send for Database<T, FS>where FS: Send, T: Send,

§

### impl<T, FS> !Sync for Database<T, FS>

§

### impl<T, FS> Unpin for Database<T, FS>where FS: Unpin, T: Unpin,

§

### impl<T, FS> UnwindSafe for Database<T, FS>where FS: UnwindSafe, T: UnwindSafe,

## Blanket Implementations§

source§

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

source§

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
source§

### impl<T> Borrow<T> for Twhere T: ?Sized,

source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

### impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

### impl<T> From<T> for T

source§

#### fn from(t: T) -> T

Returns the argument unchanged.

source§

### impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

#### 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 Twhere U: TryFrom<T>,

§

#### 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.
§

### impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

#### fn vzip(self) -> V