# Easiest Way to use RAG

Source: https://www.youtube.com/watch?v=--1AJEZ8BFM
Recap page: https://rapidrecap.app/video/--1AJEZ8BFM
Generated: 2025-11-13T14:07:03.517+00:00

---
## Quick Overview

The video demonstrates how to implement Retrieval Augmented Generation (RAG) using the Gemini API's File Search tool, walking through setting up a project, uploading documents like PDFs, configuring ranking strategies, and querying the system to retrieve specific answers, as well as showing integration with Clerk for multi-tenancy user management and Firebase Firestore for data storage.

**Key Points:**
- Google introduced File Search in the Gemini API, enabling RAG systems to retrieve information from user-uploaded files (JSON, JS, PDF, DOCX, TXT) via an embedding model (e.g., 'gemini-001-embedding-004').
- The File Search API has rate limits based on user tier, with the Free tier limited to 1 GB of total project file search stores, while Tier 1 allows 10 GB.
- The implementation involves creating a file search store, uploading files (like 'DeepSeek_V3.pdf'), and using the store as a tool in the generate_content API call.
- The system architecture includes an offline indexing process (Documents -> File Storage -> Embedding Model -> Database) and a real-time querying process involving Gemini deciding whether to use external knowledge.
- The custom application demonstrated integrates Clerk for authentication and multi-tenancy (organizations) and Firebase Firestore for storing user data.
- Advanced configuration options for file indexing include choosing a Ranking Strategy (Semantic, Keyword, Hybrid) and Chunking Strategy (Automatic or Manual with custom chunk size/overlap).
- The total training cost for DeepSeek-V3 was $5.576 million, broken down into Pre-Training ($5.538 million), Context Extension ($0.238 million), and Post-Training ($0.01 million).

![Screenshot at 00:06: The core diagram illustrating the File Search in Gemini API workflow, showing JSON, JS, and PDF files being processed via Python code into a neural network structure for advanced retrieval-augmented generation.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-06.png)

**Context:** This video tutorial explains how to build smarter Retrieval Augmented Generation (RAG) systems using the Gemini API's File Search feature, which allows the LLM to ground its answers in custom documents. The presenter, Muhammad Farooq (aka Prompt Engineering), builds a multi-tenant SaaS application using this technology, integrating it with authentication via Clerk and data storage using Firebase Firestore to demonstrate a complete, production-ready RAG solution.

## Detailed Analysis

The video details the implementation of Retrieval Augmented Generation (RAG) using the Gemini API's File Search tool. The initial setup involves creating a file search store using Python code to upload documents like PDFs, which are then processed offline by an embedding model and stored in a database. The querying process involves Gemini deciding whether to generate queries based on external knowledge retrieval. The presenter shows how to use the file search store as a tool during the generation call, passing the store name to retrieve context. Key pricing notes include that developers are charged for embeddings at indexing time ($0.15 per 1M tokens), but storage and query time embeddings are free. The video also demonstrates building a multi-tenant architecture using Clerk for authentication and organization management, showing how users can switch between organizations ('prompt.org' vs 'personal account'). The custom application uses Firebase Firestore for user data storage and showcases advanced indexing configurations like Hybrid ranking strategy and manual chunking settings. A specific data point revealed is that the total training cost for DeepSeek-V3 was $5.576 million, detailed across its pre-training, context extension, and post-training stages.

### Gemini File Search Setup

- Uploading files (JSON, JS, PDF) via Python to the File Search API
- Using client.file_search_stores.upload_to_file_search_store
- Waiting for operations to complete via client.operations.get(operation)

### RAG Architecture Overview

- Two main phases: Offline Indexing (Documents -> Embedding Model -> Database) and Realtime Querying (Gemini decides to use external knowledge -> Query Embedding Model -> Gemini generates final answer)

### Custom Application Architecture

- React Application (User Interface/Main App Logic) interacts with External Services (Clerk Auth for authentication, Firebase Firestore for data storage, Gemini AI Platform for RAG & File Operations).

### Indexing Customization

- Advanced settings allow selecting Ranking Strategy (Semantic, Keyword, Hybrid) and Chunking Strategy (Automatic or Manual with custom chunk size/overlap).

### Pricing and Limits

- Free tier allows 1 GB total storage; Tier 1 allows 10 GB; Indexing embeddings cost $0.15 per 1M tokens; Storage and query embeddings are free.

### Multi-Tenancy with Clerk

- Demonstrates creating organizations ('prompt.org') and inviting members, allowing seamless switching between organizational contexts within the application.

![Screenshot at 00:00: Initial diagram showing different file types \(JSON, JS, PDF\) being fed into the Gemini API via Python for File Search.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-00.png)
![Screenshot at 00:06: The initial diagram illustrating the RAG workflow, split into Knowledge Base Creation and Generation Part.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-06.png)
![Screenshot at 00:16: Python code snippet showing how to initialize the Gemini client and upload a file to a file search store using client.file\_search\_stores.upload\_to\_file\_search\_store.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-16.png)
![Screenshot at 00:30: The application welcome screen prompting the user to create a knowledge base or start a new chat.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-30.png)
![Screenshot at 00:49: Detailed flow chart of the Querying Process in Realtime, highlighting the decision point for using external knowledge.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-49.png)
![Screenshot at 00:55: Screenshot of the Gemini API documentation detailing rate limits, including free tier storage of 1 GB.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-00-55.png)
![Screenshot at 04:44: The application showing the 'DeepSeek-v1' Knowledge Base overview with file count and embedding model selected.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-04-44.png)
![Screenshot at 07:29: The chat interface showing the retrieved answer for the question about DeepSeek-V3 training cost, complete with source citations.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-07-29.png)
![Screenshot at 11:08: The Clerk organization management screen showing the 'prompt.org' organization with 2 members.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-11-08.png)
![Screenshot at 11:48: Code snippet illustrating how to use metadata filters \(e.g., author='Robert Graves'\) during content generation.](https://ss.rapidrecap.app/screens/--1AJEZ8BFM/00-11-48.png)
