Struct vec_embed_store::SimilaritySearch
source · pub struct SimilaritySearch<'a> { /* private fields */ }
Expand description
A builder-style struct for performing similarity searches on the embeddings.
Implementations§
source§impl<'a> SimilaritySearch<'a>
impl<'a> SimilaritySearch<'a>
sourcepub fn new(embed_db: &'a EmbeddingsDb, similar_text: &str) -> Self
pub fn new(embed_db: &'a EmbeddingsDb, similar_text: &str) -> Self
Creates a new SimilaritySearch
instance.
§Example
use vec_embed_store::{EmbeddingsDb, EmbeddingEngineOptions, TextChunk, SimilaritySearch};
let embed_db = EmbeddingsDb::new("path/to/db", EmbeddingEngineOptions::default()).await?;
let embed_text = "Example text";
let search = SimilaritySearch::new(&embed_db, embed_text);
sourcepub fn threshold(self, threshold: f32) -> Self
pub fn threshold(self, threshold: f32) -> Self
Sets the similarity threshold for the search.
§Example
use vec_embed_store::{EmbeddingsDb, EmbeddingEngineOptions, TextChunk, SimilaritySearch};
let search = SimilaritySearch::new(&embed_db, embed_text)
.threshold(0.8);
sourcepub fn limit(self, limit: usize) -> Self
pub fn limit(self, limit: usize) -> Self
Sets the maximum number of results to return.
§Example
use vec_embed_store::{EmbeddingsDb, EmbeddingEngineOptions, TextChunk, SimilaritySearch};
let search = SimilaritySearch::new(&embed_db, embed_text)
.limit(10);
sourcepub async fn execute(self) -> Result<Vec<ComparedTextBlock>, EmbedDbError>
pub async fn execute(self) -> Result<Vec<ComparedTextBlock>, EmbedDbError>
Executes the similarity search and returns the results.
§Example
use vec_embed_store::{EmbeddingsDb, EmbeddingEngineOptions, TextChunk, SimilaritySearch};
let results = SimilaritySearch::new(&embed_db, embed_text)
.threshold(0.8)
.limit(10)
.execute()
.await?;
let results = SimilaritySearch::new(&embed_db, embed_text) .threshold(0.8) .limit(10) .execute() .await?;
Auto Trait Implementations§
impl<'a> Freeze for SimilaritySearch<'a>
impl<'a> !RefUnwindSafe for SimilaritySearch<'a>
impl<'a> Send for SimilaritySearch<'a>
impl<'a> Sync for SimilaritySearch<'a>
impl<'a> Unpin for SimilaritySearch<'a>
impl<'a> !UnwindSafe for SimilaritySearch<'a>
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more