pub struct VectorDb { /* private fields */ }Expand description
Vector database for storing and querying embedding vectors.
VectorDb provides a high-level API for ingesting vectors with metadata.
It handles internal details like ID allocation, centroid assignment,
and metadata index maintenance automatically.
Implementations§
Source§impl VectorDb
impl VectorDb
Sourcepub async fn open(config: Config) -> Result<Self>
pub async fn open(config: Config) -> Result<Self>
Open or create a vector database with the given configuration and centroids.
If the database already exists (centroids are already stored), the provided centroids are ignored and the stored centroids are used instead.
If the database is new, the provided centroids are written to storage and used to build the HNSW index.
§Arguments
config- Database configurationcentroids- Initial centroids to use if database is new
§Configuration Compatibility
If the database already exists, the configuration must be compatible:
dimensionsmust match exactlydistance_metricmust match exactly
Other configuration options (like flush_interval) can be changed
on subsequent opens.
pub async fn open_with_storage( config: Config, builder: StorageBuilder, ) -> Result<Self>
pub async fn open_with_centroids( config: Config, centroids: Vec<Vec<f32>>, builder: StorageBuilder, ) -> Result<Self>
Sourcepub async fn write(&self, vectors: Vec<Vector>) -> Result<()>
pub async fn write(&self, vectors: Vec<Vector>) -> Result<()>
Write vectors to the database.
This is the primary write method. It accepts a batch of vectors and returns when the data has been accepted for ingestion (but not necessarily flushed to durable storage).
§Atomicity
This operation is atomic: either all vectors in the batch are accepted,
or none are. This matches the behavior of TimeSeriesDb::write().
§Upsert Semantics
Writing a vector with an ID that already exists performs an upsert: the old vector is deleted and replaced with the new one. The system allocates a new internal ID for the updated vector and marks the old internal ID as deleted. This ensures index structures are updated correctly without expensive read-modify-write cycles.
§Validation
The following validations are performed:
- Vector dimensions must match
Config::dimensions - Attribute names must be defined in
Config::metadata_fields(if specified) - Attribute types must match the schema
Sourcepub async fn write_timeout(
&self,
vectors: Vec<Vector>,
timeout: Duration,
) -> Result<()>
pub async fn write_timeout( &self, vectors: Vec<Vector>, timeout: Duration, ) -> Result<()>
Write vectors to the database with a timeout.
This is the primary write method. It accepts a batch of vectors and returns when the data has been accepted for ingestion (but not necessarily flushed to durable storage).
The write may time out if the db is busy compacting or indexing.
§Atomicity
This operation is atomic: either all vectors in the batch are accepted,
or none are. This matches the behavior of TimeSeriesDb::write().
§Upsert Semantics
Writing a vector with an ID that already exists performs an upsert: the old vector is deleted and replaced with the new one. The system allocates a new internal ID for the updated vector and marks the old internal ID as deleted. This ensures index structures are updated correctly without expensive read-modify-write cycles.
§Validation
The following validations are performed:
- Vector dimensions must match
Config::dimensions - Attribute names must be defined in
Config::metadata_fields(if specified) - Attribute types must match the schema
Sourcepub async fn flush(&self) -> Result<()>
pub async fn flush(&self) -> Result<()>
Force flush all pending data to durable storage.
Flushes the in-memory delta to the storage memtable, then persists to durable storage. After this returns, data is both readable and durable.
§Atomic Flush
The flush operation is atomic:
- All pending writes are frozen into an immutable delta
- RecordOps are applied in one batch via
storage.apply() - The snapshot is updated for queries
- Data is flushed to durable storage
This ensures ID dictionary updates, deletes, and new records are all applied together, maintaining consistency.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Closes the vector database, flushing any pending data and releasing resources.
All written data is flushed to durable storage before the database is closed. For SlateDB-backed storage, this also releases the database fence.
pub fn num_centroids(&self) -> usize
Sourcepub async fn search_exact_nprobe(
&self,
query: &Query,
nprobe: usize,
) -> Result<Vec<SearchResult>>
pub async fn search_exact_nprobe( &self, query: &Query, nprobe: usize, ) -> Result<Vec<SearchResult>>
Search using brute-force centroid lookup (for diagnostics).
pub async fn snapshot(&self) -> Box<dyn VectorDbRead>
Trait Implementations§
Source§impl VectorDbRead for VectorDb
impl VectorDbRead for VectorDb
Source§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 Query,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 Query,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search_with_nprobe<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 Query,
nprobe: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for VectorDb
impl !RefUnwindSafe for VectorDb
impl Send for VectorDb
impl Sync for VectorDb
impl Unpin for VectorDb
impl UnsafeUnpin for VectorDb
impl !UnwindSafe for VectorDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);