pub struct GeminiClient { /* private fields */ }Expand description
HTTP client for interacting with Google’s Gemini Embeddings API.
This client provides methods to generate text embeddings using Google’s text-embedding-004 model. Embeddings are vector representations of text that can be used for semantic search, clustering, and similarity comparisons.
§Security
The API key is securely transmitted via the x-goog-api-key HTTP header,
not in the URL, to prevent accidental exposure in logs and proxies.
§Examples
use ceres_client::GeminiClient;
let client = GeminiClient::new("your-api-key")?;
let embedding = client.get_embeddings("Hello, world!").await?;
println!("Embedding dimension: {}", embedding.len()); // 768Implementations§
Source§impl GeminiClient
impl GeminiClient
Sourcepub fn new(api_key: &str) -> Result<Self, AppError>
pub fn new(api_key: &str) -> Result<Self, AppError>
Creates a new Gemini client with the specified API key.
Sourcepub async fn get_embeddings(&self, text: &str) -> Result<Vec<f32>, AppError>
pub async fn get_embeddings(&self, text: &str) -> Result<Vec<f32>, AppError>
Generates text embeddings using Google’s text-embedding-004 model.
This method converts input text into a 768-dimensional vector representation that captures semantic meaning.
§Arguments
text- The input text to generate embeddings for
§Returns
A vector of 768 floating-point values representing the text embedding.
§Errors
Returns AppError::ClientError if the HTTP request fails.
Returns AppError::Generic if the API returns an error.
Trait Implementations§
Source§impl Clone for GeminiClient
impl Clone for GeminiClient
Source§fn clone(&self) -> GeminiClient
fn clone(&self) -> GeminiClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for GeminiClient
impl !RefUnwindSafe for GeminiClient
impl Send for GeminiClient
impl Sync for GeminiClient
impl Unpin for GeminiClient
impl !UnwindSafe for GeminiClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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