pub struct Model<'c> {
pub task_type: Option<TaskType>,
/* private fields */
}
Expand description
A client for generating embeddings using Google’s embedding service
Provides both single and batch embedding capabilities with configurable task types.
§Example
use google_ai_rs::{Client, GenerativeModel};
let client = Client::new(auth).await?;
let embedding_model = client.embedding_model("embedding-001");
// Single embedding
let embedding = embedding_model.embed_content("Hello world").await?;
// Batch embeddings
let batch_response = embedding_model.new_batch()
.add_content("First text")
.add_content("Second text")
.embed()
.await?;
Fields§
§task_type: Option<TaskType>
Optional task type specification for embedding generation
Affects how embeddings are optimized:
None
: General purpose embeddingsTaskType::RetrievalDocument
: Optimized for document storageTaskType::RetrievalQuery
: Optimized for query matching
Implementations§
Source§impl<'c> Model<'c>
impl<'c> Model<'c>
Sourcepub fn new(client: &'c Client, name: &str) -> Self
pub fn new(client: &'c Client, name: &str) -> Self
Creates a new Model instance
§Arguments
client
- Configured API clientname
- Model identifier (e.g., “embedding-001”)
Sourcepub fn task_type(self, task_type: TaskType) -> Self
pub fn task_type(self, task_type: TaskType) -> Self
Optional task type specification for embedding generation
Affects how embeddings are optimized:
TaskType::RetrievalDocument
: Optimized for document storageTaskType::RetrievalQuery
: Optimized for query matching
Sourcepub async fn embed_content<T: TryIntoContent>(
&self,
content: T,
) -> Result<EmbedContentResponse, Error>
pub async fn embed_content<T: TryIntoContent>( &self, content: T, ) -> Result<EmbedContentResponse, Error>
Embeds content using the API’s embedding service.
Consider batch embedding for multiple contents
§Example
// Single text embedding
let embedding = model.embed_content("Hello world").await?;
// Multi-modal embedding
model.embed_content((
"Query about this image",
Part::blob("image/jpeg", image_data)
)).await?;
§Errors
Returns Error::Net
for transport-level errors or Error::Service
for service errors
Sourcepub async fn embed_content_with_title<T>(
&self,
title: &str,
content: T,
) -> Result<EmbedContentResponse, Error>where
T: TryIntoContent,
pub async fn embed_content_with_title<T>(
&self,
title: &str,
content: T,
) -> Result<EmbedContentResponse, Error>where
T: TryIntoContent,
Embeds content with optional title context
§Arguments
title
- Optional document title for retrieval tasksparts
- Content input that converts to parts
Sourcepub async fn embed_batch<I, T>(
&self,
contents: I,
) -> Result<BatchEmbedContentsResponse, Error>where
I: IntoIterator<Item = T>,
T: TryIntoContent,
pub async fn embed_batch<I, T>(
&self,
contents: I,
) -> Result<BatchEmbedContentsResponse, Error>where
I: IntoIterator<Item = T>,
T: TryIntoContent,
Embeds multiple contents as separate content items
§Example
let texts = vec!["First", "Second", "Third"];
let batch = model.embed_batch(texts).await?;
Trait Implementations§
Auto Trait Implementations§
impl<'c> Freeze for Model<'c>
impl<'c> !RefUnwindSafe for Model<'c>
impl<'c> Send for Model<'c>
impl<'c> Sync for Model<'c>
impl<'c> Unpin for Model<'c>
impl<'c> !UnwindSafe for Model<'c>
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic_veecore::Request