Model

Struct Model 

Source
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 embeddings
  • TaskType::RetrievalDocument: Optimized for document storage
  • TaskType::RetrievalQuery: Optimized for query matching

Implementations§

Source§

impl<'c> Model<'c>

Source

pub fn new(client: &'c Client, name: &str) -> Self

Creates a new Model instance

§Arguments
  • client - Configured API client
  • name - Model identifier (e.g., “embedding-001”)
Source

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 storage
  • TaskType::RetrievalQuery: Optimized for query matching
Source

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

Source

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 tasks
  • parts - Content input that converts to parts
Source

pub fn new_batch(&self) -> Batch<'_>

Creates a new batch embedding context

Source

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?;
Source

pub async fn info(&self) -> Result<Info, Error>

returns information about the model.

Trait Implementations§

Source§

impl<'c> Debug for Model<'c>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic_veecore::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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