-
Book Overview & Buying
-
Table Of Contents
AI-Ready PostgreSQL 18
By :
In this chapter, we took our database assistant from "it works" to "it holds up."
We built a practical chatbot workflow on top of the same PostgreSQL and pgvector foundation you've been developing throughout the book: embeddings stored alongside relational truth, similarity search performed with standard SQL, and responses grounded in evidence rows rather than free-form guesswork. Using api.sf_similar_items, we turned natural language into a query embedding with api.openai_embed, retrieved the closest products from embeddings.product_embedding, and returned structured results that can be safely consumed by both humans and applications. We then added an interpretation layer with api.sf_answer_with_openai, which converts returned rows into a readable, user-friendly response, while staying explicitly constrained to what the database actually produced.
From there, we focused on the production shape of the system. We treated database functions as...