8 Postgres for generative AI
This chapter covers
- Exploring Postgres’s capabilities for generative AI
- Using the pgvector extension to store and query vector embeddings
- Optimizing the similarity search with HNSW and IVFFlat indexes
- Implementing RAG with Postgres
Generative artificial intelligence (gen 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.
Let’s explore Postgres’s capabilities for generative AI as we continue building the movie recommendation service that lets users find movies they like or might want to watch. We’ll learn to turn movie descriptions into vector embeddings, store them in Postgres, and use vector similarity search and retrieval-augmented generation (RAG) to provide users with more sophisticated and personalized recommendations.