Chapter 7. Generative AI in SQL
In Chapter 6, we focused on SQL as a first-class environment for analytics and classic machine learning. We saw how platforms like BigQuery, Snowflake, and Redshift can train, evaluate, and serve models directly in the warehouse without shipping data out. Over the last few years, a new capability has joined that toolbox: generative AI applied as close as possible to governed data and existing analytical workloads.
This chapter focuses on GenAI workloads in SQL, primarily powered by large language models (LLMs): generating and interpreting text, working with embeddings and vector search, and orchestrating multistep retrieval and reasoning workflows. These capabilities change both what we build and how we operate it. Instead of predicting a numeric label or probability, we are often generating free-form text, grounding answers in recent data, and calling out to powerful external models. This introduces concerns such as prompt design, hallucination control, evaluation, and safety that touch architecture, governance, and cost as much as they touch modeling. The emphasis is on practical patterns and guardrails to run these workloads reliably from SQL over governed data.
Warehouses are rapidly adding native support for LLMs, embeddings, and vector search. Instead of exporting data into ad hoc scripts or separate services, teams can now summarize support tickets, classify feedback, extract entities, retrieve relevant documents, and even generate draft ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access