Struct bge::Bge

source ·
pub struct Bge { /* private fields */ }

Implementations§

source§

impl Bge

source

pub fn from_files<P>(tokenizer_file_path: P, model_file_path: P) -> Result<Self>
where P: AsRef<Path>,

Creates a new instance of Bge by loading a tokenizer and a model from the specified file paths.

§Arguments
  • tokenizer_file_path - A path to the file containing the tokenizer configuration.
  • model_file_path - A path to the ONNX model file.
§Returns

If successful, returns an Ok(Self) containing a new instance of Bge. On failure, returns an Err(anyhow::Error) detailing the error encountered during the loading process.

§Errors

This function can fail if:

  • The paths provided do not point to valid files.
  • The tokenizer or model file cannot be correctly parsed or loaded, possibly due to format issues or compatibility problems.
§Examples
let bge = bge::Bge::from_files("path/to/tokenizer.json", "path/to/model.onnx");
match bge {
    Ok(instance) => println!("Bge instance created successfully."),
    Err(e) => eprintln!("Failed to create Bge instance: {}", e),
}
source

pub fn create_embeddings(&self, input: &str) -> Result<[f32; 384], BgeError>

Generates embeddings for a given input text using the model.

This method tokenizes the input text, performs necessary preprocessing, and then runs the model to produce embeddings. The embeddings are normalized before being returned.

§Arguments
  • input - The text input for which embeddings should be generated.
§Returns

If successful, returns a Result containing a fixed-size array of f32 elements representing the generated embeddings. On failure, returns a BgeError detailing the nature of the error.

§Errors

This method can return an error in several cases:

  • BgeError::LargeInput if the input text produces more tokens than the model can accept.
  • BgeError::OnnxRuntimeError for errors related to running the ONNX model.
  • BgeError::Other for all other errors, including issues with tokenization or tensor extraction.
§Examples
let embeddings = bge.create_embeddings("This is a sample text.");
match embeddings {
    Ok(embeds) => println!("Embeddings: {:?}", embeds),
    Err(e) => eprintln!("Error generating embeddings: {}", e),
}

Auto Trait Implementations§

§

impl !Freeze for Bge

§

impl RefUnwindSafe for Bge

§

impl Send for Bge

§

impl Sync for Bge

§

impl Unpin for Bge

§

impl UnwindSafe for Bge

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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