In this video, we'll be optimizing the image
search endpoint with a simple but powerful
Gemini API feature, the Media Resolution feature.
The Gemini API provides a Media Resolution
setting that you can add to the generation
configuration.
This setting helps control the processing
quality applied to the image and video inputs
sent to a multimodal Gemini model.
The primary benefit of this is the optimization
trade-off between cost and latency and detail
slash accuracy in the image interpretation.
For our travel companion, we can easily get
away with processing our images at medium
quality instead of high quality resolutions.
This is because it is easy for the model to
easily detect a landmark without needing too
much granular details in the image it is given.
The benefits of having our images processed
at lower resolutions include cost control.
Using a lower resolution setting generally
results in lower input token counts.
This directly translates to lower API costs
for processing image and video input.
Next is latency reduction.
Processing lower resolution images and videos
requires less computational time for the model.
This leads to faster response times, which
is especially crucial in real-time applications.
And finally, we have performance optimization.
For tasks that don't require eye detail, for
example, identifying the general subject of
an image or asking a question about a video's
scene change, using a lower resolution avoids
unnecessary processing overhead while still
maintaining sufficient accuracy.
With a good understanding of what this setting
is all about, let us implement it on our image
prompt request.
Let's open up that handler and if we scroll
down to the request code in the config section
of the image request, we can simply set the
image processing resolution to operate at
medium resolution.
So let's do that.
Here I'm going to simply set a media resolution
setting and that is set to types.mediaResolution
and the media resolution we're going to select
is the media resolution medium.
Awesome.
Now all our images are going to be processed
at medium resolution.
Now let's test the application to make sure
that everything works fine as expected.
We are also not going to be seeing any change
in the frontend but now we can know that tokens
are being saved.
Let's just pull up our command line, start
up our server, and now let's head over to
the browser.
Now here in the browser, let us go to our
image search section.
Select our London Eye image, which is of high
resolution, 4272 by 2848.
And search as we have always done.
After a few seconds, we get our response back,
just as before.
Now while nothing stands out in how the application
works, behind the scenes, we are rest assured
that images are being processed at medium
resolution.
So, even if a user uploads a very high-resolution
image, just like we've done, the processing
is done on a lower resolution and with this
simple setting, we are saving a lot of tokens.