8 Postgres for generative AI
This chapter covers
- Exploring Postgres capabilities for generative artificial intelligence (AI)
- Using the pgvector extension to store and query vector embeddings
- Optimizing the similarity search with HNSW and IVFFlat indexes
- Implementing retrieval augmented generation (RAG) with Postgres
Generative artificial intelligence (AI) uses specialized models to produce text, images, videos, and other types of data. These generative models are trained on vast amounts of data and can generate new content based on patterns learned during training. For example, a large language model (LLM) is trained on diverse text data that can produce coherent text in response to user prompts in a natural language such as English or Japanese. An LLM can answer questions, engage in conversation, and perform various tasks by trying to understand the intent behind the prompts.
In this chapter, you learn to use Postgres with generative AI applications. You begin by exploring the ways to use Postgres with LLMs and embedding models. Next, you learn to work with the pgvector extension, which allows you to store vector embeddings and perform similarity searches. Finally, you explore how to expand an LLM’s knowledge base using retrieval-augmented generation (RAG). And you’ll do all this the developer way by transforming our movie recommendation service from Chapter 6 into a generative AI application.