The Shift to Unified Search Architectures

Traditionally, developers maintained separate systems for transactional data (SQL), full-text search (e.g., Elasticsearch, Algolia), and vector storage. This architecture introduces significant operational overhead, including data duplication, complex ETL pipelines, and, most critically, data staleness. Google Cloud Spanner addresses this by integrating full-text, vector, and graph search directly into the relational database layer.

By keeping search indexes within the primary database, developers achieve read-after-write consistency. When an AI agent or user updates a record, the search and vector indexes are updated transactionally, ensuring that subsequent queries reflect the latest state of the data without lag.

Hybrid Search: Combining Text and Context

Spanner provides three primary search modalities that can be fused for superior results:

  • Full-Text Search: Uses tokenization and n-grams to handle keyword matching, including fuzzy search for spelling variants and synonyms.
  • Vector Search: Uses embeddings to understand the semantic meaning of data, allowing for context-aware retrieval that goes beyond exact keyword matches.
  • Hybrid Search: Employs Reciprocal Rank Fusion (RRF) to merge results from both text and vector indexes, providing the "best of both worlds" by balancing precise keyword relevance with broad semantic understanding.

Intelligent Query Expansion

Beyond basic fuzzy matching, Spanner incorporates "Enhanced Search," a feature leveraging Google’s proprietary query expansion technology. When enabled, the database automatically rewrites user queries to include synonyms, related terms, and semantic variations. For example, a search for "hair dye" is expanded to include terms like "coloring" or "dyeing," significantly increasing recall without requiring manual prompt engineering or complex application-side logic.

Scaling for AI-Native Applications

Attio, an AI-native CRM, serves as a case study for this architecture. After outgrowing PostgreSQL, they migrated to Spanner to handle massive, multi-tenant workloads. By moving from an external search provider (Algolia) to Spanner’s native search, they eliminated materialization delays and achieved significant cost savings—projecting over $500,000 in savings compared to their previous external search infrastructure. Their "Ask Attio" interface now handles over a billion documents and 50,000 reads per second, demonstrating that Spanner’s scale-out capabilities are sufficient for high-concurrency agentic workloads.

Key Takeaways

  • Eliminate ETL: By keeping search indexes inside your primary database, you remove the latency and complexity of syncing data to external search engines.
  • Leverage Transactional Consistency: Use Spanner's point-in-time reads and read-after-write consistency to ensure AI agents always operate on the most current data.
  • Use Hybrid Fusion: Always combine full-text and vector search via Reciprocal Rank Fusion (RRF) to capture both specific keyword matches and broad semantic intent.
  • Optimize with Query Hints: For complex multi-tenant workloads, use Spanner’s query hints to explicitly define join orders and parallelism, bypassing the limitations of standard query optimizers.
  • Enable Enhanced Search: Use built-in query expansion to handle multilingual data and synonym matching automatically, mirroring the intelligence of Google Search within your own applications.

Notable Quotes

  • "The beautiful thing about Spanner is that as a developer you can provide it with a query plan... your developers are able to premeditate the query plan that is going to best fit your workload." — Alexander Christie, on the control Spanner provides for complex, multi-tenant query performance.
  • "The basic model of external search is you send them a push request and they promise that they'll index that for search at some point between now and the end of the universe." — Alexander Christie, highlighting the latency issues inherent in traditional ETL-based search pipelines.
  • "Spanner search is just Spanner. So it benefits from all of the availability and uptime... as well as some of Spanner's cooler, more interesting features like point-in-time reads." — Alexander Christie, on the operational benefits of a unified data platform.