
Summary
Key points of this document
- 1. Two Hurdles Faced by Conventional Vector RAG
- 2. Approach A: High-Speed Search Layer for Handling Large Volumes of Documents at Low Cost (LanceDB + DuckDB + Gemini Flash-Lite)
- 3. Approach B: Precise Reading Layer for Long Structured Documents (PageIndex + Gemini Decision 1)
Overview
For small to medium-sized business systems and internal knowledge bases, the biggest challenge in building RAG (Retrieval-Augmented Generation) is balancing the "fixed costs of a persistent database" with the "search accuracy for long documents." This article explains the design and selective use of a hybrid RAG architecture that achieves both high-speed search of large volumes of documents and precise comprehension of long PDFs, all while keeping standby costs near zero without a persistent database server, by leveraging Google Cloud's serverless infrastructure.
1. Two Hurdles Faced by Conventional Vector RAG
Traditional RAG configurations centered around vector search face two structural challenges—infrastructure costs and search accuracy—when dealing with small to medium-sized systems or complex business documents.
Infrastructure Hurdle: Excessive Fixed Costs from Persistent Databases
When adopting Cloud SQL (pgvector) or managed dedicated vector databases, instances must be kept running constantly, regardless of search traffic. This incurs fixed monthly costs of tens of thousands of yen. For internal regulation searches or small to medium-sized services with usage around "several thousand to 10,000 queries per month," the infrastructure standby cost often dominates the actual token consumption cost.
Accuracy Hurdle: Context Disruption Due to Fixed-Length Chunking
Mechanically chunking long PDFs (e.g., policy manuals, contracts, financial reports, technical manuals) into fixed lengths (e.g., 500-1,000 tokens) leads to information loss, such as the following:
- Separation of Tables and Notes: Table headers and data rows, or numbers and footnotes, are split into different chunks, making them unintelligible when retrieved.
- Loss of Chapter Structure and Prerequisites: Hierarchical contextual prerequisites like "As an exception to Chapter 3..." or "However, excluding cases falling under the preceding paragraph" are cut off.
In validation areas like FinanceBench, a benchmark for financial reports, it has been pointed out that simple chunking-based vector search tends to suffer from accuracy degradation when referencing tables or numerical data and notes spanning multiple pages.
2. Approach A: High-Speed Search Layer for Handling Large Volumes of Documents at Low Cost (LanceDB + DuckDB + Gemini Flash-Lite)
For use cases requiring low-latency, low-cost search of large volumes of structured documents or short to medium-length texts, a serverless search layer built on Cloud Storage (GCS) as the storage foundation is effective.
Architecture: Lance Format on Cloud Storage and Zero-Copy Integration
In this approach, instead of setting up a persistent database server, vector data and metadata are placed in the columnar Lance format on Cloud Storage, an object storage service. The search API runs on Cloud Run (min-instances=0), launching containers only when a request is made.
During query execution, we combine DuckDB's lance extension, an in-process SQL engine, with zero-copy integration in memory via Apache Arrow. This allows the following to be completed within a single process:
- Metadata Filtering and Aggregation with SQL: Rapidly filter structured conditions such as date ranges, categories, department codes, and publication statuses using SQL.
- Concurrent Vector Similarity Search: Directly connect and execute nearest neighbor searches using LanceDB-formatted vector indexes on the filtered targets.
Cost Estimation and Applicable Domains
When operating min-instances=0 with and storing the data itself in Cloud Storage, the fixed cost during standby is only the GCS storage fee (a few yen per GB per month), and there are zero permanent DB server costs.
Regarding inference costs, by combining Gemini Embedding 2 for query embedding generation and a lightweight, high-speed Gemini Flash-Lite for summarizing extraction results and generating answers, it is possible to operate at an extremely low unit cost of approximately 0.08-0.3 yen per query (depending on text volume and prompt length).
- Strengths: Cases where a large volume of FAQs, knowledge articles, inquiry histories, system logs, chat records, etc., have independent contexts, and a fast answer is desired by combining metadata conditions and semantic search.
- Weaknesses: Reading tasks that require strict cross-referencing of "exception clauses" or "notes in attached tables" within contracts or regulations spanning tens to hundreds of pages.
3. Approach B: Precise Reading Layer for Long Structured Documents (PageIndex + Gemini Decision 1)
To accurately interpret long PDF documents with complex tables and chapters, an "inference-based hierarchical search" that does not rely on vectorization and chunking is effective.
Table of Contents/Hierarchical Tree Search with Vector-less RAG "PageIndex"
PageIndex is a vector-less RAG approach that does not use embedding vectors or fixed-length chunking, but instead stores the table of contents, section hierarchy, and page summaries of an entire document as tree.json structured .
When a question is input, instead of a search engine, the model's inference traces the table of contents tree from the root to determine "which section of Chapter 4 is likely to contain the answer to this question," identifying the relevant page range. This process directly replicates how a human would look at the table of contents of a thick manual to open to the relevant page, ensuring that tables, notes, and chapter prerequisites are not fragmented.
Accelerating and Reducing the Cost of Search with System One Model "Gemini Decision 1"
The weakness of PageIndex is that if a regular generative LLM is called every time each level of the tree is traversed, latency and token costs tend to increase. To address this, Gemini Decision 1, a System One model specialized in decision-making that does not generate text, is combined as the search engine .
Gemini Decision 1 has the following characteristics, which can resolve the bottlenecks in tree traversal and page determination .
- Decision-Specialized API (
noul/choice/score): Returns only discrete judgments and scoring, such as "Does it apply? (noul: Yes/No)", "Which branch to choose? (choice)", and "Degree of relevance (score)". - Zero Output Token Charges: Since no text is generated, there are no charges for output tokens.
- High Throughput / Batch Decision Making: Up to 1,000 questions (node decisions) can be evaluated in a single request, with response times typically within 150-250ms.
- Multimodal PDF Direct Input Support: PDF pages containing complex tables and charts that are prone to corruption during text extraction can be directly used as multimodal input for decision-making.
Cost Estimation and Asynchronous Index Construction (Cloud Run Jobs + Eventarc)
If the input unit price for Gemini Decision 1 is $0.10 / 1M tokens (free output), then even combining branch decisions for a table of contents tree (several thousand tokens) and relevance decisions for candidate PDF pages (tens of thousands of tokens), highly accurate evidence identification is possible for approximately $0.005 to $0.02 per query (a few yen or less, under 1 yen depending on the configuration).
Also, tree.json generation from PDFs is a heavy batch process, so it will not be placed on the online search API (Cloud Run). We will adopt a separation of concerns where PDF uploads to GCS are detected by Eventarc, and Cloud Run Jobs is asynchronously launched to perform analysis and tree.json storage.
4. Integrated Design: Hybrid Serverless Architecture
By integrating fast filtering from large volumes of documents (Approach A) and precise reading of lengthy documents (Approach B) as a three-stage pipeline, we can maximize the balance of cost, speed, and accuracy.
Overall Architecture Diagram
3-Stage Pipeline Processing Flow
- Stage 1 (DuckDB + LanceDB on GCS): First, from tens of thousands of documents, attribute filtering using SQL (e.g., year, category, target classification) and vector similarity search are executed in milliseconds at near-zero cost, narrowing down highly relevant candidate documents to a few (e.g., top 3-5 documents). For short FAQs or single knowledge items, this stage's information is passed to
Gemini Flash-Liteto return an immediate answer. - Stage 2 (PageIndex +
Gemini Decision 1): If the narrowed-down target is a structured PDF such as a long regulation manual or contract, refer to thetree.jsonof the relevant document.Gemini Decision 1useschoiceandscoreto identify relevant chapters and sections, and then performs a batch execution ofnoul(evidence presence determination) on the further narrowed actual PDF pages to confirm only the pages that truly contain the basis for the answer. - Stage 3 (Answer Generation by Gemini): Only pages verified as "containing evidence" in Stage 2 are passed as context to the Gemini model to generate the final answer and citation page numbers, suppressing hallucinations.
5. Comparison of Four Configuration Patterns
We compare traditional and the three serverless configurations discussed in this article, allowing you to select the appropriate configuration based on your use case and traffic scale.
| Comparison Item | Traditional Persistent Vector DB | LanceDB + Flash-Lite | PageIndex + Decision 1 | Hybrid Configuration (This Design) |
|---|---|---|---|---|
| Fixed Standby Cost | High (always-on instance billing) | Approx. 0 JPY (GCS storage fees only) | Approx. 0 JPY (GCS storage fees only) | Approx. 0 JPY (GCS storage fees only) |
| Data Segmentation Method | Fixed-length chunk segmentation | Fixed-length/semantic unit chunks | No chunk segmentation (tree.json) | Combined based on document type/stage |
| Search Approach | Vector similarity search-centric | SQL filter + vector search | Hierarchical tree inference + evidence determination | Coarse search (SQL/vector) + precise reading |
| Accuracy for Tables/Long Notes | Low-Medium (context often fragmented) | Medium (with metadata assistance) | High (maintains page/hierarchical context) | Highest (precise reading after narrowing down targets) |
| Estimated Cost per Query | Low (but fixed costs apply separately) | Approx. 0.08-0.3 JPY level | Approx. 0.5-several JPY level (input-dependent) | Optimal cost through path branching |
| Main Suitable Domain | Constant high load, low latency required | Large-scale FAQ, article, log search | Detailed review of thick contracts/regulations | Large-scale business knowledge base with mixed long texts |
6. Design Constraints, Trade-offs, and Verification Points During Implementation
Serverless configurations offer overwhelming cost advantages for small to medium scales, but other bottlenecks may emerge depending on traffic characteristics and document structure.
Cost Break-even Point: Thousands to tens of thousands of queries/month vs. hundreds of thousands of queries/month or more
- Small to Medium Scale (up to several thousand to 10,000 queries/month): Since it's entirely covered by pay-as-you-go billing and GCS storage fees, infrastructure costs can be significantly reduced compared to operating a persistent DB (like Cloud SQL).
- High Traffic (hundreds of thousands of queries/month or more): The number of GCS reads and data transfer volume per request, as well as Cloud Run's startup time and memory consumption, accumulate. At this scale, there's a break-even point where maintaining a persistent in-memory cache or dedicated vector DB becomes more advantageous in terms of cost per query and latency.
Separation of Responsibilities for Cold Starts and Heavy PDF Parsing
If Cloud Run is configured to min-instances=0, a cold start delay of several seconds will occur for the first request after a period of inactivity. This includes DuckDB initialization and metadata loading from GCS, so if strict latency is required, adjustments such as min-instances=1 during specific time slots are necessary.
Furthermore, co-locating text analysis of PDFs spanning hundreds of pages and tree.json generation with request processing can lead to timeouts and out-of-memory (OOM) errors. Heavy PDF analysis processes must always be offloaded to Cloud Run Jobs via Eventarc, completely separating the search path from the index construction path.
Suitability Differences Based on Document Structure
Hierarchical exploration using PageIndex is highly effective for PDFs with clear heading, chapter, and table of contents structures (manuals, contracts, terms and conditions, design documents). On the other hand, forcing the construction of tree.json for chat logs, fragmented meeting notes, or miscellaneous unstructured text groups will not improve search efficiency. For such unstructured data, it is more practical to process it with Approach A (DuckDB + LanceDB) and design the system to separate processing paths at the routing layer or with metadata.
Verification Points to Check During Implementation
Before deployment to production, quantitative measurements and verification of the following points are necessary.
| Verification Point | Risks/Constraints to Confirm | Specific Verification Method |
|---|---|---|
| Tree Search Accuracy Evaluation | Incorrect section selection if table of contents granularity is too coarse or too deep | Measure recall (reproducibility) of reaching the correct source page in the second stage using a set of expected questions |
| Token Limit (256K) Management | Exceeding context limits during batch determination or simultaneous input of multiple PDF pages | Pre-calculate the number of input tokens per Gemini Decision 1 call, and split batches by chunking if the limit is exceeded |
| GCS Read Latency | I/O delays when retrieving Lance files or PDFs over the network each time | Confirm region consistency between Cloud Run and GCS bucket, and measure p95 latency in both cold and warm states |
| Fallback on Misjudgment | Risk of no response if noul determines all pages as "no basis" | Confirm score thresholds and behavior like "fallback to top results from stage 1 and explicitly indicate no answer" in integration tests |
7. Summary: Decision Criteria for Practical Use
When adopting a hybrid serverless RAG without a permanent DB server, it is practical to determine the configuration based on the following three decision criteria.
- Assess by Traffic Volume: For traffic of several thousand to 10,000 queries per month, a Cloud Run (
min-instances=0) + GCS configuration maximizes the benefit of zero standby fixed costs. Consider migrating to a permanent DB only when monthly queries exceed several hundred thousand. - Differentiate Layers by Document Structure: Apply "DuckDB + LanceDB +
Gemini Flash-Lite" for independent FAQs, articles, and logs, and "PageIndex +Gemini Decision 1" for long PDFs where chapters and tables are crucial. - Offload Index Construction to Asynchronous Jobs: By dedicating the search API to reading and inference, and separating PDF analysis and
tree.jsonand Lance data updates into an asynchronous pipeline using Eventarc andCloud Run Jobs, stable responsiveness and operational maintainability can be achieved simultaneously.


