pub struct Collection { /* private fields */ }Expand description
A collection of vectors with associated metadata.
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn create(
path: PathBuf,
dimension: usize,
metric: DistanceMetric,
) -> Result<Self>
pub fn create( path: PathBuf, dimension: usize, metric: DistanceMetric, ) -> Result<Self>
Creates a new collection at the specified path.
§Errors
Returns an error if the directory cannot be created or the config cannot be saved.
Sourcepub fn create_with_options(
path: PathBuf,
dimension: usize,
metric: DistanceMetric,
storage_mode: StorageMode,
) -> Result<Self>
pub fn create_with_options( path: PathBuf, dimension: usize, metric: DistanceMetric, storage_mode: StorageMode, ) -> Result<Self>
Creates a new collection with custom storage options.
§Arguments
path- Path to the collection directorydimension- Vector dimensionmetric- Distance metricstorage_mode- Vector storage mode (Full, SQ8, Binary)
§Errors
Returns an error if the directory cannot be created or the config cannot be saved.
Sourcepub fn open(path: PathBuf) -> Result<Self>
pub fn open(path: PathBuf) -> Result<Self>
Opens an existing collection from the specified path.
§Errors
Returns an error if the config file cannot be read or parsed.
Sourcepub fn config(&self) -> CollectionConfig
pub fn config(&self) -> CollectionConfig
Returns the collection configuration.
Sourcepub fn upsert(&self, points: impl IntoIterator<Item = Point>) -> Result<()>
pub fn upsert(&self, points: impl IntoIterator<Item = Point>) -> Result<()>
Inserts or updates points in the collection.
Accepts any iterator of points (Vec, slice, array, etc.)
§Errors
Returns an error if any point has a mismatched dimension.
Sourcepub fn upsert_bulk(&self, points: &[Point]) -> Result<usize>
pub fn upsert_bulk(&self, points: &[Point]) -> Result<usize>
Bulk insert optimized for high-throughput import.
§Performance
This method is optimized for bulk loading:
- Uses sequential HNSW insertion (reliable, no rayon conflicts)
- Single flush at the end (not per-point)
- No HNSW index save (deferred for performance)
- ~20-30% faster than previous parallel approach on large batches (5000+)
- Benchmark: 1.5-2.1 Kvec/s on 768D vectors
§Errors
Returns an error if any point has a mismatched dimension.
Sourcepub fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>
pub fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>
Searches for the k nearest neighbors of the query vector.
Uses HNSW index for fast approximate nearest neighbor search.
§Errors
Returns an error if the query vector dimension doesn’t match the collection.
Sourcepub fn search_with_ef(
&self,
query: &[f32],
k: usize,
ef_search: usize,
) -> Result<Vec<SearchResult>>
pub fn search_with_ef( &self, query: &[f32], k: usize, ef_search: usize, ) -> Result<Vec<SearchResult>>
Performs vector similarity search with custom ef_search parameter.
Higher ef_search = better recall, slower search.
Default ef_search is 128 (Balanced mode).
§Errors
Returns an error if the query vector dimension doesn’t match the collection.
Sourcepub fn search_ids(&self, query: &[f32], k: usize) -> Result<Vec<(u64, f32)>>
pub fn search_ids(&self, query: &[f32], k: usize) -> Result<Vec<(u64, f32)>>
Performs fast vector similarity search returning only IDs and scores.
Perf: This is ~3-5x faster than search() because it skips vector/payload retrieval.
Use this when you only need IDs and scores, not full point data.
§Arguments
query- Query vectork- Maximum number of results to return
§Returns
Vector of (id, score) tuples sorted by similarity.
§Errors
Returns an error if the query vector dimension doesn’t match the collection.
Sourcepub fn search_batch_parallel(
&self,
queries: &[&[f32]],
k: usize,
) -> Result<Vec<Vec<SearchResult>>>
pub fn search_batch_parallel( &self, queries: &[&[f32]], k: usize, ) -> Result<Vec<Vec<SearchResult>>>
Performs batch vector similarity search in parallel using rayon.
Perf: This is significantly faster than calling search in a loop
because it parallelizes across CPU cores and amortizes lock overhead.
§Arguments
queries- Slice of query vectorsk- Maximum number of results per query
§Returns
Vector of search results for each query, with full point data.
§Errors
Returns an error if any query vector dimension doesn’t match the collection.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of points in the collection.
Perf: Uses cached point_count from config instead of acquiring storage lock
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the collection is empty.
Perf: Uses cached point_count from config instead of acquiring storage lock
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Saves the collection configuration and index to disk.
§Errors
Returns an error if storage operations fail.
Sourcepub fn text_search(&self, query: &str, k: usize) -> Vec<SearchResult>
pub fn text_search(&self, query: &str, k: usize) -> Vec<SearchResult>
Sourcepub fn hybrid_search(
&self,
vector_query: &[f32],
text_query: &str,
k: usize,
vector_weight: Option<f32>,
) -> Result<Vec<SearchResult>>
pub fn hybrid_search( &self, vector_query: &[f32], text_query: &str, k: usize, vector_weight: Option<f32>, ) -> Result<Vec<SearchResult>>
Performs hybrid search combining vector similarity and full-text search.
Uses Reciprocal Rank Fusion (RRF) to combine results from both searches.
§Arguments
vector_query- Query vector for similarity searchtext_query- Text query for BM25 searchk- Maximum number of results to returnvector_weight- Weight for vector results (0.0-1.0, default 0.5)
§Errors
Returns an error if the query vector dimension doesn’t match.
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Collection
impl !RefUnwindSafe for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl !UnwindSafe for Collection
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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);