pub struct TextEmbedding<B: Backend = DefaultBackend> { /* private fields */ }Expand description
Minimal text embedding interface inspired by fastembed-rs.
Implementations§
Source§impl TextEmbedding<DefaultBackend>
impl TextEmbedding<DefaultBackend>
Sourcepub async fn new(options: TextEmbeddingOptions) -> Result<Self>
pub async fn new(options: TextEmbeddingOptions) -> Result<Self>
Loads a MiniLM text embedding model onto the default WGPU device.
Source§impl<B> TextEmbedding<B>where
B: Backend,
impl<B> TextEmbedding<B>where
B: Backend,
Sourcepub async fn new_with_device(
device: &B::Device,
options: TextEmbeddingOptions,
) -> Result<Self>
pub async fn new_with_device( device: &B::Device, options: TextEmbeddingOptions, ) -> Result<Self>
Loads a MiniLM text embedding model onto the provided device.
Sourcepub fn embed(&self, document: impl AsRef<str>) -> Result<Vec<f32>>
pub fn embed(&self, document: impl AsRef<str>) -> Result<Vec<f32>>
Embeds a single document and returns one embedding vector.
Sourcepub fn embed_query(&self, query: impl AsRef<str>) -> Result<Vec<f32>>
pub fn embed_query(&self, query: impl AsRef<str>) -> Result<Vec<f32>>
Embeds a search query using any model-specific retrieval prompt.
Some retrieval models train queries and documents with different text
prefixes. Use this when the text is the thing being searched for.
Use TextEmbedding::embed when the text is the content being indexed.
Sourcepub fn embed_batch<S: AsRef<str>>(
&self,
documents: &[S],
batch_size: Option<usize>,
) -> Result<Vec<Vec<f32>>>
pub fn embed_batch<S: AsRef<str>>( &self, documents: &[S], batch_size: Option<usize>, ) -> Result<Vec<Vec<f32>>>
Embeds documents in batches and returns one vector per input string.
Sourcepub fn embed_query_batch<S: AsRef<str>>(
&self,
queries: &[S],
batch_size: Option<usize>,
) -> Result<Vec<Vec<f32>>>
pub fn embed_query_batch<S: AsRef<str>>( &self, queries: &[S], batch_size: Option<usize>, ) -> Result<Vec<Vec<f32>>>
Embeds search queries in batches using model-specific retrieval prompts.
See TextEmbedding::embed_query for when query embeddings differ from
document embeddings.
Sourcepub fn model(&self) -> EmbeddingModel
pub fn model(&self) -> EmbeddingModel
Returns the loaded embedding checkpoint.
Trait Implementations§
Auto Trait Implementations§
impl<B = CubeBackend<WgpuRuntime, f32, i32, u32>> !Freeze for TextEmbedding<B>
impl<B = CubeBackend<WgpuRuntime, f32, i32, u32>> !RefUnwindSafe for TextEmbedding<B>
impl<B = CubeBackend<WgpuRuntime, f32, i32, u32>> !UnwindSafe for TextEmbedding<B>
impl<B> Send for TextEmbedding<B>
impl<B> Sync for TextEmbedding<B>
impl<B> Unpin for TextEmbedding<B>where
<B as BackendTypes>::Device: Unpin,
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
impl<B> UnsafeUnpin for TextEmbedding<B>where
<B as BackendTypes>::Device: UnsafeUnpin,
<B as BackendTypes>::FloatTensorPrimitive: UnsafeUnpin,
<B as BackendTypes>::QuantizedTensorPrimitive: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more