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 create_typed(
path: PathBuf,
name: &str,
collection_type: &CollectionType,
) -> Result<Self>
pub fn create_typed( path: PathBuf, name: &str, collection_type: &CollectionType, ) -> Result<Self>
Sourcepub fn create_metadata_only(path: PathBuf, name: &str) -> Result<Self>
pub fn create_metadata_only(path: PathBuf, name: &str) -> Result<Self>
Creates a new metadata-only collection (no vectors, no HNSW index).
Metadata-only collections are optimized for storing reference data,
catalogs, and other non-vector data. They support CRUD operations
and VelesQL queries on payload, but NOT vector search.
§Errors
Returns an error if the directory cannot be created or the config cannot be saved.
Sourcepub fn is_metadata_only(&self) -> bool
pub fn is_metadata_only(&self) -> bool
Returns true if this is a metadata-only collection.
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, or if attempting to insert vectors into a metadata-only collection.
Sourcepub fn upsert_metadata(
&self,
points: impl IntoIterator<Item = Point>,
) -> Result<()>
pub fn upsert_metadata( &self, points: impl IntoIterator<Item = Point>, ) -> Result<()>
Inserts or updates metadata-only points (no vectors).
This method is for metadata-only collections. Points should have empty vectors and only contain payload data.
§Errors
Returns an error if storage operations fail.
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 parallel HNSW insertion (rayon)
- Single flush at the end (not per-point)
- No HNSW index save (deferred for performance)
- ~15x faster than previous sequential approach on large batches (5000+)
- Benchmark: 25-30 Kvec/s on 768D vectors
§Errors
Returns an error if any point has a mismatched dimension.
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
Source§impl Collection
impl Collection
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,
or if this is a metadata-only collection (use query() instead).
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_with_filters(
&self,
queries: &[&[f32]],
k: usize,
filters: &[Option<Filter>],
) -> Result<Vec<Vec<SearchResult>>>
pub fn search_batch_with_filters( &self, queries: &[&[f32]], k: usize, filters: &[Option<Filter>], ) -> Result<Vec<Vec<SearchResult>>>
Performs batch search for multiple query vectors in parallel with metadata filtering. Supports a different filter for each query in the batch.
§Arguments
queries- List of query vector slicesk- Maximum number of results per queryfilters- List of optional filters (must match queries length)
§Returns
Vector of search results for each query, matching its respective filter.
§Errors
Returns an error if queries and filters have different lengths or dimension mismatch.
Sourcepub fn search_batch_with_filter(
&self,
queries: &[&[f32]],
k: usize,
filter: &Filter,
) -> Result<Vec<Vec<SearchResult>>>
pub fn search_batch_with_filter( &self, queries: &[&[f32]], k: usize, filter: &Filter, ) -> Result<Vec<Vec<SearchResult>>>
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 search for multiple query vectors in parallel.
This method is optimized for high throughput using parallel index traversal.
§Arguments
queries- List of query vector slicesk- 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 execute_query(
&self,
query: &Query,
params: &HashMap<String, Value>,
) -> Result<Vec<SearchResult>>
pub fn execute_query( &self, query: &Query, params: &HashMap<String, Value>, ) -> Result<Vec<SearchResult>>
Executes a VelesQL query on this collection.
This method unifies vector search, text search, and metadata filtering into a single interface.
§Arguments
query- ParsedVelesQLqueryparams- Query parameters for resolving placeholders (e.g., $v)
§Errors
Returns an error if the query cannot be executed (e.g., missing parameters).
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)
§Performance (v0.9+)
- Streaming RRF:
BinaryHeapmaintains top-k during fusion (O(n log k) vs O(n log n)) - Vector-first gating: Text search limited to 2k candidates for efficiency
FxHashMap: Faster hashing for score aggregation
§Errors
Returns an error if the query vector dimension doesn’t match.
Sourcepub fn search_with_filter(
&self,
query: &[f32],
k: usize,
filter: &Filter,
) -> Result<Vec<SearchResult>>
pub fn search_with_filter( &self, query: &[f32], k: usize, filter: &Filter, ) -> Result<Vec<SearchResult>>
Searches for the k nearest neighbors with metadata filtering.
Performs post-filtering: retrieves more candidates from HNSW, then filters by metadata conditions.
§Arguments
query- Query vectork- Maximum number of results to returnfilter- Metadata filter to apply
§Errors
Returns an error if the query vector dimension doesn’t match the collection.
Sourcepub fn text_search_with_filter(
&self,
query: &str,
k: usize,
filter: &Filter,
) -> Vec<SearchResult>
pub fn text_search_with_filter( &self, query: &str, k: usize, filter: &Filter, ) -> Vec<SearchResult>
Sourcepub fn hybrid_search_with_filter(
&self,
vector_query: &[f32],
text_query: &str,
k: usize,
vector_weight: Option<f32>,
filter: &Filter,
) -> Result<Vec<SearchResult>>
pub fn hybrid_search_with_filter( &self, vector_query: &[f32], text_query: &str, k: usize, vector_weight: Option<f32>, filter: &Filter, ) -> Result<Vec<SearchResult>>
Performs hybrid search (vector + text) with metadata filtering.
Uses Reciprocal Rank Fusion (RRF) to combine results from both searches, then applies metadata filter.
§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)filter- Metadata filter to apply
§Errors
Returns an error if the query vector dimension doesn’t match.
Sourcepub fn multi_query_search(
&self,
vectors: &[&[f32]],
top_k: usize,
fusion: FusionStrategy,
filter: Option<&Filter>,
) -> Result<Vec<SearchResult>>
pub fn multi_query_search( &self, vectors: &[&[f32]], top_k: usize, fusion: FusionStrategy, filter: Option<&Filter>, ) -> Result<Vec<SearchResult>>
Performs multi-query search with result fusion.
This method executes parallel searches for multiple query vectors and fuses the results using the specified fusion strategy. Ideal for Multiple Query Generation (MQG) pipelines where multiple reformulations of a user query are searched simultaneously.
§Arguments
vectors- Slice of query vectors (all must have same dimension)top_k- Maximum number of results to return after fusionfusion- Strategy for combining results (Average, Maximum, RRF, Weighted)filter- Optional metadata filter to apply to all queries
§Returns
Vector of SearchResult sorted by fused score descending.
§Errors
Returns an error if:
vectorsis empty- Any vector has incorrect dimension
- More than 10 vectors are provided (configurable limit)
§Example
use velesdb_core::fusion::FusionStrategy;
// Search with 4 query reformulations using weighted fusion
let results = collection.multi_query_search(
&[&query1, &query2, &query3, &query4],
10,
FusionStrategy::Weighted {
avg_weight: 0.6,
max_weight: 0.3,
hit_weight: 0.1,
},
None,
)?;Sourcepub fn multi_query_search_ids(
&self,
vectors: &[&[f32]],
top_k: usize,
fusion: FusionStrategy,
) -> Result<Vec<(u64, f32)>>
pub fn multi_query_search_ids( &self, vectors: &[&[f32]], top_k: usize, fusion: FusionStrategy, ) -> Result<Vec<(u64, f32)>>
Performs multi-query search returning only IDs and fused scores.
This is a faster variant of multi_query_search that skips fetching
vector and payload data. Use when you only need document IDs.
§Arguments
vectors- Slice of query vectorstop_k- Maximum number of resultsfusion- Fusion strategy
§Returns
Vector of (id, fused_score) tuples sorted by score descending.
§Errors
Returns an error if vectors is empty, exceeds max limit, or has dimension mismatch.
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);