Struct txtai::embeddings::Embeddings

source ·
pub struct Embeddings { /* private fields */ }
Expand description

Embeddings definition

Implementations§

source§

impl Embeddings

Embeddings implementation

source

pub fn new() -> Embeddings

Creates an Embeddings instance.

source

pub fn with_url(url: &str) -> Embeddings

Creates an Embeddings instance.

§Arguments
  • url - API url
source

pub fn with_url_token(url: &str, token: &str) -> Embeddings

Creates an Embeddings instance.

§Arguments
  • url - API url
  • token - API token
source

pub async fn query( &self, query: &str, limit: i32, weights: Option<f32>, index: Option<&str> ) -> APIResponse

Runs an Embeddings search. Returns Response. This method allows callers to customize the serialization of the response.

§Arguments
  • query - query text
  • limit - maximum results
  • weights - hybrid score weights, if applicable
  • index - index name, if applicable
source

pub async fn search( &self, query: &str, limit: i32, weights: Option<f32>, index: Option<&str> ) -> SearchResults

Finds documents in the embeddings model most similar to the input query. Returns a list of {id: value, score: value} sorted by highest score, where id is the document id in the embeddings model.

§Arguments
  • query - query text
  • limit - maximum results
  • weights - hybrid score weights, if applicable
  • index - index name, if applicable
source

pub async fn batchsearch( &self, queries: &Vec<&str>, limit: i32, weights: Option<f32>, index: Option<&str> ) -> SearchResultsBatch

Finds documents in the embeddings model most similar to the input queries. Returns a list of {id: value, score: value} sorted by highest score per query, where id is the document id in the embeddings model.

§Arguments
  • queries - queries text
  • limit - maximum results
  • weights - hybrid score weights, if applicable
  • index - index name, if applicable
source

pub async fn add<T: Serialize>(&self, documents: &Vec<T>) -> APIResponse

Adds a batch of documents for indexing.

§Arguments
  • documents - list of {id: value, text: value}
source

pub async fn index(&self) -> APIResponse

Builds an embeddings index for previously batched documents.

source

pub async fn upsert(&self) -> APIResponse

Runs an embeddings upsert operation for previously batched documents.

source

pub async fn delete(&self, ids: &Vec<&str>) -> Ids

Deletes from an embeddings index. Returns list of ids deleted.

§Arguments
  • ids - list of ids to delete
source

pub async fn reindex( &self, config: HashMap<&str, &str>, function: Option<&str> ) -> APIResponse

Recreates this embeddings index using config. This method only works if document content storage is enabled.

source

pub async fn count(&self) -> Count

Total number of elements in this embeddings index.

source

pub async fn similarity(&self, query: &str, texts: &Vec<&str>) -> IndexResults

Computes the similarity between query and list of text. Returns a list of {id: value, score: value} sorted by highest score, where id is the index in texts.

§Arguments
  • query - query text
  • texts - list of text
source

pub async fn batchsimilarity( &self, queries: &Vec<&str>, texts: &Vec<&str> ) -> IndexResultsBatch

Computes the similarity between list of queries and list of text. Returns a list of {id: value, score: value} sorted by highest score per query, where id is the index in texts.

§Arguments
  • queries - queries text
  • texts - list of text
source

pub async fn transform(&self, text: &str) -> Embedding

Transforms text into an embeddings array.

§Arguments
  • text - input text
source

pub async fn batchtransform(&self, texts: &str) -> EmbeddingBatch

Transforms list of text into embeddings arrays.

§Arguments
  • texts - lists of text

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more