Boost AI context with hybrid search in Spanner

By Google Cloud Tech

Share:

Key Concepts

  • Spanner Search: A multi-model search capability integrated directly into Google Cloud Spanner, supporting full-text, vector, and graph search.
  • Full-Text Search: Token-based search using inverted indexes, supporting fuzzy matching and synonym substitution.
  • Vector Search: AI-driven search that maps data to vectors to perform similarity computations (KNN and ANN).
  • Hybrid Search: Combining full-text and vector search to improve result relevance.
  • GraphRAG: Using knowledge graphs within Spanner to enhance Retrieval-Augmented Generation (RAG) by traversing relationships between data points.
  • SCAN (Scalable Nearest Neighbor): A specialized, high-performance vector indexing algorithm developed by Google.
  • Enhanced Search: A feature using Google’s proprietary AI to expand search queries with semantically related terms.
  • Reciprocal Rank Fusion (RRF): A method for merging and ranking results from multiple search retrievers.

1. Overview of Spanner Search

Spanner serves as a unified data platform that eliminates the need for separate search engines, ETL pipelines, and data duplication. By keeping search functionality within the operational database, users benefit from:

  • Zero Maintenance: No need to manage separate search infrastructure.
  • Scalability: Near-limitless horizontal scaling.
  • Availability: Best-in-class five-nines (99.999%) SLA.
  • Transactional Consistency: Search indexes are updated in real-time, ensuring no data lag.

2. Core Search Methodologies

Full-Text Search

  • Mechanism: Uses tokenization and inverted indexes.
  • Fuzzy Search: Implemented via n-grams (splitting text into 3-character substrings) to handle spelling variations and typos.
  • Enhanced Query: Automatically rewrites queries (e.g., "hair dye" expands to "hair," "color," "dyeing") using Google’s internal search intelligence.

Vector Search

  • Mechanism: Maps documents and queries into vector embeddings.
  • Algorithms: Supports KNN (K-Nearest Neighbors) for smaller, filtered datasets and ANN (Approximate Nearest Neighbor) using the SCAN algorithm for large-scale, high-performance requirements.
  • Integration: Directly integrates with Vertex AI and Gemini to generate embeddings via SQL.

Graph Search

  • Mechanism: Defines graph structures as an overlay on existing relational data.
  • Application: Enables complex traversals and GraphRAG, which provides better context and precision than standard vector-based RAG by leveraging explicit data relationships.

3. Real-World Application: Atteo

Atteo, an AI-native CRM, transitioned from PostgreSQL to Spanner to handle massive data scale.

  • The Challenge: Their previous architecture (Postgres + Algolia) suffered from significant ETL delays and high costs.
  • The Solution: By moving to Spanner’s unified stack, they achieved read-after-write consistency and eliminated ETL overhead.
  • Results:
    • Cost Efficiency: Saved $165,000 in FY26, with projected savings of over $500,000 in FY27.
    • Scale: Currently indexes 350 million documents, growing at 20% monthly, and serves over 1 billion documents with 50,000 reads per second.

4. Step-by-Step Implementation Framework

  1. Define Schema: Use DDL to define tables and columns.
  2. Create Indexes: Use CREATE SEARCH INDEX for full-text or CREATE VECTOR INDEX for AI-based search.
  3. Querying: Execute standard SQL queries that incorporate SEARCH or VECTOR_DISTANCE functions.
  4. Hybridization: Use Reciprocal Rank Fusion (RRF) or custom ORDER BY clauses to merge results from multiple search types (e.g., text + vector).

5. Notable Quotes

  • Jeff: "Traditionally... you had to run a whole separate platform... Spanner allows you to do this all in one place."
  • Alexander (Atteo): "Spanner proved to be an order of magnitude cheaper than our previous search solution."
  • Girish: "GraphRAG significantly outperforms RAG in terms of performance and recall and precision and quality of results."

6. Synthesis and Conclusion

Spanner Search represents a shift toward "all-in-one" data architecture. By integrating full-text, vector, and graph capabilities directly into the operational database, Google enables developers to build sophisticated, AI-powered search applications without the operational burden of managing disparate systems. The key takeaway is that transactional consistency and SQL-based search logic allow for faster development cycles, lower infrastructure costs, and higher-quality search results compared to traditional multi-platform architectures.

Chat with this Video

AI-Powered

Load the transcript when you're ready to chat so the initial page stays lighter.

Ready to summarize another video?

Summarize YouTube Video