pub struct OpenAiEmbedder { /* private fields */ }Expand description
An embedder that calls the OpenAI embeddings API.
Requires the reqwest crate (already a workspace dependency).
Implementations§
Source§impl OpenAiEmbedder
impl OpenAiEmbedder
Sourcepub fn new(api_key: String, model: String, dimensions: usize) -> Self
pub fn new(api_key: String, model: String, dimensions: usize) -> Self
Create a new OpenAI embedder.
model should be something like "text-embedding-3-small".
Sourcepub fn build_request_body(&self, input: &[&str]) -> Value
pub fn build_request_body(&self, input: &[&str]) -> Value
Build the JSON request body for the OpenAI embeddings endpoint.
Sourcepub fn parse_response(body: &Value) -> PunchResult<Vec<Vec<f32>>>
pub fn parse_response(body: &Value) -> PunchResult<Vec<Vec<f32>>>
Parse the embedding vectors from an OpenAI API response.
Trait Implementations§
Source§impl Debug for OpenAiEmbedder
impl Debug for OpenAiEmbedder
Source§impl Embedder for OpenAiEmbedder
impl Embedder for OpenAiEmbedder
Source§fn embed(&self, text: &str) -> PunchResult<Vec<f32>>
fn embed(&self, text: &str) -> PunchResult<Vec<f32>>
Compute an embedding vector for a single piece of text.
Source§fn embed_batch(&self, texts: &[&str]) -> PunchResult<Vec<Vec<f32>>>
fn embed_batch(&self, texts: &[&str]) -> PunchResult<Vec<Vec<f32>>>
Compute embedding vectors for a batch of texts.
Source§fn dimensions(&self) -> usize
fn dimensions(&self) -> usize
The dimensionality of vectors produced by this embedder.
Auto Trait Implementations§
impl Freeze for OpenAiEmbedder
impl RefUnwindSafe for OpenAiEmbedder
impl Send for OpenAiEmbedder
impl Sync for OpenAiEmbedder
impl Unpin for OpenAiEmbedder
impl UnsafeUnpin for OpenAiEmbedder
impl UnwindSafe for OpenAiEmbedder
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