|
|
Google Spanner Graph for RAG
Author: Venkata Sudhakar
ShopMax India uses Google Cloud Spanner as its primary transactional database for inventory, orders, and supplier data. Spanner Graph (launched 2024) adds native graph query support (GQL) to existing Spanner tables, allowing an LLM agent to traverse product-supplier-claim relationships without migrating data to a separate graph database.
Spanner Graph defines a PROPERTY GRAPH over existing Spanner tables using a schema declaration. Nodes and edges are virtual views on top of regular tables. You query them using GQL (Graph Query Language) via the standard Spanner client. An LLM agent generates GQL queries from natural language, executes them using the Spanner Python client, and uses the results as context for a final answer.
The below example shows how ShopMax India queries product and supplier relationships using Spanner Graph with an LLM-generated GQL query via the Python client.
It gives the following output,
GQL:
GRAPH ShopMaxGraph
MATCH (s:Supplier)-[:Supplies]->(p:Product)-[:HasClaim]->(c:Claim)
WHERE c.city = 'Hyderabad' AND c.amount_rs > 10000
RETURN s.name, p.name, COUNT(c) AS high_value_claims
ORDER BY high_value_claims DESC
Results: [
{"name": "Mehta Electronics", "p.name": "Samsung 4K TV", "high_value_claims": 8},
{"name": "Sunrise Corp", "p.name": "LG OLED TV", "high_value_claims": 5}
]
Spanner Graph does not require a separate graph database - it works on existing Spanner tables, making adoption very low risk for ShopMax India. Define the PROPERTY GRAPH DDL once and it applies immediately. Validate LLM-generated GQL before execution by running an EXPLAIN first. Use parameterized queries for any user-supplied values to prevent injection. Spanner Graph is available in all Spanner regions where ShopMax India operates.
|
|