惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
V
Vulnerabilities – Threatpost
T
Tenable Blog
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
WordPress大学
WordPress大学
Latest news
Latest news
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
C
Cisco Blogs
博客园 - 聂微东
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
小众软件
小众软件
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
Security Latest
Security Latest
Y
Y Combinator Blog
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 最新话题
月光博客
月光博客
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
S
Security Affairs
P
Proofpoint News Feed
D
DataBreaches.Net
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG

Analytics Vidhya

Handling Imbalanced Classification: What Works Better Than SMOTE GPT-5.6 Is Here: Sol, Terra, and Luna Loop Engineering for AI Agents: How /loop is Changing AI Workflows DeepSeek DSpark: The Speculative Decoding Trick Behind 400% Faster LLM OKF: Redefining Knowledge Bases for AI Agents Modern VLMs Explained: How GPT-4o, Gemini, Claude Vision, and Qwen-VL Work YOLO26 Tutorial: Object Detection, Pose Estimation & More Large Action Models (LAMs) vs Agentic LLMs: What's the Real Difference? Claude Sonnet 5: The Fable 5 at Home The Best $20 AI Plan: ChatGPT Plus vs Claude Pro vs Gemini Pro GraphRAG vs Vector RAG: Which Retrieval Method is Best? Using AI When You Don’t Trust AI The Self-Improving Loop in AI Agents: Architecture, Benefits, and How it Outperforms Traditional Agent Workflows Harness-1: The 20B Retrieval Subagent That Beats GPT-5.4 at Search Sakana Fugu: Multi-Agent System as a Model Claude's Hidden Art Skill: Making Illustrations With Code System Design for ML Interviews: 10 Real Problems Walked Through Most People Use ChatGPT Wrong: 10 Features and Tips That Changed How I Work OpenAI Just Launched 3 Free AI Courses with Certificates Autoregressive Models: Predicting the Future Using the Past Gemini Omni: AI Video Generation Inside Gemini DiffusionGemma: Google’s Diffusion-Based Open Model for Faster Text Generation Top 10 AI Engineering Tools Everyone is Using in 2026 I Tested Claude Fable 5: Can Anthropic’s Newest AI Deliver on the Hype? Prophet vs NeuralProphet vs TimeGPT vs Chronos: A Practical Comparison Build an Emergency Helpline Voice Agent with LangChain Choosing the Right Vector Database for RAG and AI Applications Google Gemma 4 12B: Architecture, Benchmarks, Access, and Hands-on Guide for Developers How to Choose the Right AI Model for Your Needs Agent Observability with LangSmith, Langfuse, and Arize: A Hands-On Comparison How to Use Claude Managed Agents? Google AI Studio vs Gemini App: What’s the Difference? AI Workflows for Sales Teams: Prospect Research, Lead Qualification, and CRM Updates on Autopilot Using LangGraph 25 Most Influential AI Pioneers to Meet at DataHack Summit 2026 Claude Opus 4.8: A Smarter Model in the Right Direction PySpark Optimization: 12 Proven Techniques to Speed Up Your Spark Jobs 10 Everyday Tasks You Can Automate with AI Today (With n8n Templates) Google Antigravity 2.0: The Full Developer Guide (I/O 2026) Build a Claude Cowork-Like Browser Agent Using Playwright MCP and Claude Desktop Pandas vs Polars vs DuckDB: Which Library Should You Choose? Qwen3.7-Max: Alibaba’s New Agent-First LLM for Coding, Reasoning, and Long-Horizon AI Workflows The Biggest Announcements from Google I/O 2026 Top 9 AI Events and Conferences in 2026 that you Must Attend Gemini 3.5 Flash: Frontier Intelligence with Speed Kimi WebBridge: Hands-on Guide to Kimi’s Browser Extension for AI Agents 40 Advanced SQL Window Functions Every Data Scientist Must Know(with examples) Top 10 AI Research Papers of 2025 6 Steps to Crack GenAI Case Study Interviews (With Real Examples) OpenAI Omni Moderation: How to Filter Text & Images for Free DataHack Summit 2026: You Just Cannot Skip This AI Event of the Year OpenAI’s New API Voice Models Will Change the Way You Use AI Hermes Agent Guide: What is it and How to Use it? Top 10 LLM Research Papers of 2026 Agent Memory Patterns in Cognitive Science and AI Systems 10 AI Agents Every AI Engineer Must Build (with GitHub Samples) 23 Tips for Smart Claude Code Token Saving and Workflow Optimization Feature Engineering with LLMs: Techniques & Python Examples ChatGPT is Now Inside Excel and Google Sheets: Here is How to Use it Top 10 Open-Source Libraries to Fine-Tune LLMs Locally ML Intern in Practice: From Prompt to a Shipped Hugging Face Model 15+ Solved Agentic AI Projects with Github Links How People are Figuring Out Life With Claude MemPalace Explained: Building Long-Term Memory for AI Agents Beyond RAG Grok Voice Think Fast 1.0: Build Voice AI Agents That Actually Think Compressing LSTM Models for Retail Edge Deployment: A Practical Comparison MCP vs Agent Skills: Different Altogether GPT 5.5 vs Opus 4.7: Which is the Best AI Model Today? What is Agentic AI? Claude Code vs Codex: A Detailed Terminal Agent Comparison Google Deep Research Max: Build Autonomous AI Research Agents in Minutes Meta Muse Spark Review: Is It Worth the Hype? ChatGPT Images 2.0 vs Nano Banana 2: Which is Better? Cursor V3 Explained: The AI Coding Agent That’s Replacing Traditional IDEs in 2026 DeepSeek-V4: The Most Powerful Open-Source Model Ever Is GPT Image 2 the Best Image Generation Model? Token Economics: Why AI is Getting “Cheaper” From Idea to Output: Claude Does the Design Work Opus 4.7 vs Opus 4.6: Should You Switch? Build Human-Like AI Voice App with Gemini 3.1 Flash TTS How to Structure a Claude Code Project that Thinks Like an Engineer Gemma 4 Tool Calling Explained: Build AI Agents with Function Calling (Step-by-Step Guide) Anthropic Launches Claude Opus 4.7 For “Most Difficult Tasks” Top 28 Claude Shortcuts that will 10X your Speed GPT-5.4-Cyber: Why OpenAI is Keeping its Most Powerful Model Under Lock and Key Google AI Studio Guide: Every Feature Explained Mastering Deep Agents: Context Engineering that Actually Works 21 Computer Vision Projects from Beginner to Advanced (2026 Guide) Excel 101: Excel Agent Mode Explained MiniMax M2.7 Goes Open-Weight to Let You Run Agents Locally Top 10 Gemma 4 Projects That Will Blow Your Mind GLM-5.1: Architecture, Benchmarks, Capabilities & How to Use It Understanding BERTopic: From Raw Text to Interpretable Topics From Karpathy’s LLM Wiki to Graphify: AI Memory Layers are Here 10 Most Important AI Concepts Explained Simply Project Glasswing is World’s Most Powerful AI in Action How to Run Gemma 4 on Your Phone Without Internet: A Hands-On Guide Running Claude Code for Free with Gemma 4 and Ollama LLM Wiki Revolution: How Andrej Karpathy’s Idea is Changing AI Rethinking Enterprise Search: How Cortex Search Turns Data into Business Impact Google’s Gemma 4: Is it the Best Open-Source Model of 2026?
Gemini API File Search: The Easy Way to Build RAG
Janvi Kumari · 2026-05-06 · via Analytics Vidhya

Building a RAG system just got much easier. Google’s File Search tool for the Gemini API now handles the heavy lifting of connecting LLMs to your data. Chunking, embedding, indexing are all managed for you. And with the latest update, it’s gone multimodal. You can now search through both text and images in a single pipeline, with custom metadata filtering and page-level citations built in. In this guide, we’ll walk through how File Search works and implement it with practical examples.

What File Search Does?

File Search helps Gemini access and use information from your data sources like reports, documents, research papers, code, and private knowledge bases.

When you upload a file, Gemini breaks it into smaller pieces called “chunks” and creates embeddings for them. These embeddings are numerical representations that capture the meaning of the content, helping Gemini understand the context. They are then stored in a File Search Store for easy retrieval.

When you ask a question, Gemini searches the stored embeddings for the most relevant chunks and uses them as context to generate answers. This is the essence of Retrieval Augmented Generation (RAG).

Gemini File Search goes beyond just text. It also supports multimodal RAG, allowing text and images to be indexed and searched together. This means you can retrieve information from PDFs, images, charts, screenshots, and more using natural language queries.

For multimodal tasks, Gemini uses gemini-embedding-2 for image and multimodal embeddings, while gemini-embedding-001 handles text embeddings. Note that audio and video formats are not supported yet.

Also Read: Building an LLM Model using Google Gemini API

How File Search Works?

File Search is powered by semantic vector search. Instead of matching on words directly, it will find information based on meaning and context. This means that File Search can find you relevant information even if the wording of the query is different. 

Time needed: 4 minutes

Here’s how it works step-by-step: 

  1. Upload a file

    The file will be broken up into smaller sections referred to as “chunks.” 

  2. Embedding generation

    Each chunk would be transformed into a numerical vector that represents the meaning of that chunk. 

  3. Storage

    The embeddings will be stored in a File Search Store, an embedded store designed specifically for retrieval. 

  4. Query

    When a user poses a question, File Search will transform that question into an embedding. 

  5. Retrieval

    The retrieval step will compare the question embedding with the stored embeddings and find which chunks are most similar (if any). 

  6. Grounding

    Relevant chunks are added to the prompt to the Gemini model so that the answer is grounded in the factual data from the documents. 

This entire process is handled under the Gemini API. The developer does not have to manage any additional infrastructure or databases. 

Setup Requirements 

To utilize the File Search Tool, developers will need a few fundamental components. They will need to have Python 3.9 or newer, the google-genai client library, and a valid Gemini API key that has access to either gemini-2.5-pro or gemini-2.5-flash. 

Install the client library by running: 

pip install google-genai -U 

Then, set your environment variable for the API key: 

export GOOGLE_API_KEY="your_api_key_here"

Creating a File Search Store 

A File Search Store is where Gemini stores and indexes embeddings created from your uploaded files. Once a file is uploaded and indexed, the indexed data remains available for retrieval until you manually delete it. 

For text-only RAG, you can create a normal File Search Store. For multimodal RAG, where you want to upload and search both documents and images, create the store with models/gemini-embedding-2. 

from google import genai 
from google.genai import types 
import time 
import os 
from pathlib import Path 

# Do not hardcode your API key in the notebook. 
# Set it as an environment variable instead. 
os.environ["GOOGLE_API_KEY"] = "enter_your_api_key" 

client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"]) 

file_search_store = client.file_search_stores.create(
    config={ 
        "display_name": "my_multimodal_rag_store", 
        "embedding_model": "models/gemini-embedding-2" 
    } 
)

print("File Search Store created:", file_search_store.name)

Output:

Creating a File Search Store | Gemini API File Search

This update is important because the official docs show embedding_model: models/gemini-embedding-2 while creating a File Search Store for multimodal usage.

Upload a File

After the File Search Store is created, you can upload files to it. When a file is uploaded, Gemini File Search automatically chunks the content, generates embeddings, and indexes it for fast retrieval.

For text-based RAG, File Search supports documents such as PDF, DOCX, TXT, JSON, and programming files like .py and .js.

For multimodal RAG, File Search also supports image files. This means you can upload documents and images into the same File Search Store and ask questions that require both textual and visual context. For example, you can upload a research paper, a product image, and a chart, then ask Gemini to summarize the paper and explain the related visual information.

For image uploads, make sure the File Search Store is created with models/gemini-embedding-2. According to the official documentation, supported image formats are PNG and JPEG. Image files must be at most 4K x 4K pixels, and a request can include a maximum of 6 images.

Upload a Document File

# Upload and import a document into the File Search Store.
# The display name will be visible in citations.

operation = client.file_search_stores.upload_to_file_search_store(
    file="/content/Paper2Agent.pdf",
    file_search_store_name=file_search_store.name,
    config={
        "display_name": "Paper2Agent.pdf",
    }
)

# Wait until import is complete
while not operation.done:
    time.sleep(5)
    operation = client.operations.get(operation)

print("Document successfully uploaded and indexed.")

Output:

Upload a document file | Gemini API File Search

After this step, the document is chunked, embedded, indexed, and ready for retrieval.

Upload an Image File for Multimodal Retrieval

You can also upload an image file to the same File Search Store. This is useful when your application needs to retrieve information from product images, screenshots, charts, diagrams, or other visual content.

# Upload an image file for multimodal retrieval.

operation = client.file_search_stores.upload_to_file_search_store(
    file="/content/product_image.jpg",
    file_search_store_name=file_search_store.name,
    config={
        "display_name": "product_image.jpg",
    }
)

# Wait until import is complete
while not operation.done:
    time.sleep(5)
    operation = client.operations.get(operation)

print("Image successfully uploaded and indexed."

Output:

Upload an Image File for Multimodal Retrieval

Once the image is indexed, Gemini can retrieve it during File Search when the user’s query is relevant to the image.

Upload Multiple Documents and Images

In real-world applications, you may want to upload multiple files at once. These files can include both text documents and images.

from pathlib import Path 
import time 

files_to_upload = [
    "/content/Paper2Agent.pdf",
    "/content/product_image.jpg",
    "/content/sales_chart.png"
]

for file_path in files_to_upload:
    operation = client.file_search_stores.upload_to_file_search_store(
        file=file_path,
        file_search_store_name=file_search_store.name,
        config={
            "display_name": Path(file_path).name,
        }
    )

    while not operation.done:
        time.sleep(5)
        operation = client.operations.get(operation)

    print(f"Uploaded and indexed: {file_path}")

Output:

After the upload step, all files are chunked, embedded, indexed, and ready for retrieval. If the File Search Store contains both documents and images, Gemini can retrieve relevant context from both sources while answering user questions.

Ask Questions About the File

Once your files are indexed, Gemini can answer questions using the uploaded documents and images as context. It searches the File Search Store, retrieves the most relevant chunks, and uses them to generate a grounded response.

For a text-only use case, you can ask a question about the uploaded PDF:

response = client.models.generate_content(
    model="gemini-3-flash-preview",
    contents="Summarize what is there in the research paper.",
    config=types.GenerateContentConfig(
        tools=[
            types.Tool(
                file_search=types.FileSearch(
                    file_search_store_names=[file_search_store.name]
                )
            )
        ]
    )
)

print("Model Response:\n")
print(response.text)

Output:

Ask Questions About the File | Gemini File Search

Here, File Search is being utilized as a tool inside generate_content(). The model first searches your stored embeddings, pulls the most relevant sections, and then generates an answer based on that context.

For a multimodal use case, you can ask a question that uses both the document and the image:

response = client.models.generate_content(
    model="gemini-3-flash-preview",
    contents=""" 
    Based on the uploaded research paper, and the images,  
    summarize the key idea from the paper and explain what the images shows.
    """,
    config=types.GenerateContentConfig(
        tools=[
            types.Tool(
                file_search=types.FileSearch(
                    file_search_store_names=[file_search_store.name]
                )
            )
        ]
    )
)

print("Multimodal Response:\n")
print(response.text)

Output:

Ask Questions About the File | File Search in Gemini

Here, File Search is used as a tool inside generate_content(). The model searches the stored embeddings, retrieves the most relevant text or image context, and then generates an answer based on that retrieved information.

Customize Chunking 

By default, File Search decides how to split files into chunks, but you can control this behavior for better search precision. 

operation = client.file_search_stores.upload_to_file_search_store( 
    file_search_store_name=file_search_store.name, 
    file='path/to/your/file.txt', 
    config={ 
        'chunking_config': { 
            'white_space_config': { 
                'max_tokens_per_chunk': 200, 
                'max_overlap_tokens': 20 
            } 
        } 
    } 
) 


This configuration sets each chunk to 200 tokens with 20 overlapping tokens for smoother context continuity. Shorter chunks give finer search results, while larger ones retain more overall meaning useful for research papers and code files. 

Show Citations for Retrieved Context

You can also print citation information to check which files or chunks Gemini used while generating the response. The official docs say citation information is available through grounding_metadata, and image references may include media citation details.

grounding_metadata = response.candidates[0].grounding_metadata

print("\nRetrieved Context:\n")

if grounding_metadata and grounding_metadata.grounding_chunks:
    for chunk in grounding_metadata.grounding_chunks:
        context = chunk.retrieved_context

        if context:
            print("Source:", getattr(context, "title", "Unknown"))
            print("Text:", getattr(context, "text", "No text available"))

            if getattr(context, "page_number", None):
                print("Page Number:", context.page_number)

            if getattr(context, "media_id", None):
                print("Media ID:", context.media_id)

            print("-" * 50)
else:
    print("No grounding metadata found.")

Output:

Show Citations for Retrieved Context

This makes the hands-on section stronger because readers can see not only the answer, but also the source context used by Gemini.

Manage Your File Search Stores 

You can easily list, view, and delete file search stores using the API. 

print("\n Available File Search Stores:") 

for s in client.file_search_stores.list(): 

print(" -", s.name)
Manage Your File Search Stores 
# Get detailed info 

details = client.file_search_stores.get(name=file_search_store.name) 

print("\n Store Details:\n", details
Store Details
# Delete the store (optional cleanup) 

client.file_search_stores.delete(name=file_search_store.name, config={'force': True}) 

print("File Search Store deleted.")
File Search Store Deleted

These management options help keep your environment organized. Indexed data remains stored until manually deleted, while files uploaded through the temporary Files API are automatically removed after 48 hours. 

Also Read: 12 Things You Can Do with the Free Gemini API

File Search Support and Limits

File Search is available with the following Gemini models: Gemini 3.1 Pro Preview, Gemini 3.1 Flash-Lite Preview, Gemini 3 Flash Preview, Gemini 2.5 Pro, and Gemini 2.5 Flash-Lite.

Gemini 3 models allow you to combine File Search with custom tools via function calling. However, File Search is not yet supported in the Live API and cannot be used with certain built-in tools like Grounding with Google Search or URL Context.

File Search supports a wide range of file formats, including PDFs, Word documents, spreadsheets, presentations, JSON, CSV, HTML, XML, Markdown, YAML, code files, ZIP files, and Jupyter notebooks. For multimodal RAG, it also supports PNG and JPEG images when the store is created with models/gemini-embedding-2.

File Size and Storage Limits

User Tier File Size Limit Store Capacity Limit
Free 100 MB per file 1 GB
Tier 1 100 MB per file 10 GB
Tier 2 100 MB per file 100 GB
Tier 3 100 MB per file 1 TB

Recommended: Keep each store under 20 GB for better retrieval performance and lower latency.

Regarding pricing, embeddings are charged at indexing time. Storage and query-time embeddings are free, and retrieved document tokens are billed as normal context tokens.

Also Read: How to Access and Use the Gemini API?

Conclusion 

File Search takes the infrastructure work out of building RAG systems. No external vector databases, no custom embedding pipelines. Just upload your files and start querying. With the new multimodal support, you can now search across documents and images together. Metadata filtering helps you scope results to exactly what’s relevant, and page-level citations make every answer traceable back to its source. Whether you’re prototyping or building for production, File Search gives you a solid, managed foundation to build on. Get started at Google AI Studio or through the Gemini API docs linked in the article.

Hi, I am Janvi, a passionate data science enthusiast currently working at Analytics Vidhya. My journey into the world of data began with a deep curiosity about how we can extract meaningful insights from complex datasets.