Agentic AI in Action — Part 28 — A Geospatial Store Intelligence Agent in Snowflake
Snowflake Cortex Analyst combined with Semantic Views enables plain-English geospatial queries without external services, translating natural language into SQL over governed dimensions and metrics A clean architectural pattern emerges: Cortex Analyst handles attribute filtering and aggregation while native Snowflake geography functions (ST_DWITHIN, H3_POINT_TO_CELL_STRING) handle spatial geometry Synthetic store data across four US cities (New York, Chicago, Austin, Seattle) with ~80 locations d
Analysis
TL;DR
- Snowflake Cortex Analyst combined with Semantic Views enables plain-English geospatial queries without external services, translating natural language into SQL over governed dimensions and metrics
- A clean architectural pattern emerges: Cortex Analyst handles attribute filtering and aggregation while native Snowflake geography functions (ST_DWITHIN, H3_POINT_TO_CELL_STRING) handle spatial geometry
- Synthetic store data across four US cities (New York, Chicago, Austin, Seattle) with ~80 locations demonstrates the full pipeline from natural language question to rendered map within a single Snowflake Notebook
- H3 hexagonal grid aggregation provides a territorial rollup view, transforming individual store queries into regional planning insights like underserved territory identification
- The entire workflow runs inside Snowflake using only built-in capabilities and default Python packages (pandas, matplotlib), with no data leaving the account
Why It Matters
This article demonstrates a practical, production-ready pattern for combining generative AI query capabilities with native geospatial functions inside a single cloud data platform, eliminating the need for external mapping services or complex data pipelines. For AI practitioners, it shows how Semantic Views can govern Cortex Analyst's SQL generation to ensure consistent, business-aligned query results while keeping spatial logic in the hands of native SQL where it belongs.
Technical Details
- Data Model: A single
STORE_LOCATIONStable with columns for store ID, city, footfall_last_month, and a GEOGRAPHY column constructed from latitude/longitude coordinates; ~80 synthetic stores jittered around four city centers - Semantic View Architecture:
STORE_SEMANTIC_VIEWexposescityandstore_nameas dimensions andavg_footfallandstore_countas metrics, deliberately excluding geographic columns to keep Cortex Analyst scoped to attribute filtering only - Spatial Functions: Snowflake's native
ST_DWITHINperforms radius-based distance queries, whileH3_POINT_TO_CELL_STRING(location, resolution)maps points to Uber's H3 hexagonal grid for territorial aggregation at configurable resolutions - Cortex Analyst Integration: A Python function
ask_cortex_analyst()sends natural language questions via the Cortex Analyst REST API, returning both the generated SQL and query results; the function handles authentication through Snowpark session tokens - Rendering Pipeline: Results are joined back to coordinates from the base table and rendered using matplotlib (default) or optionally pydeck with H3HexagonLayer for interactive mapping, all within a single Snowflake Notebook session
Industry Insight
- The deliberate separation of concerns—natural language for attribute filtering, native SQL for geometry—represents a scalable design pattern that can be adapted across domains (logistics, banking, healthcare) by simply swapping the underlying table and Semantic View definitions
- Organizations should invest in well-governed Semantic Views before deploying Cortex Analyst at scale; the article shows that scoped views prevent the model from improvising SQL and ensure consistent aggregation logic across queries
- The H3 territorial aggregation approach transforms granular store-level data into business-friendly regional insights, suggesting that geospatial AI agents should offer both point-level and zone-level views to serve different stakeholder needs
Disclaimer: The above content is generated by AI and is for reference only.