Chapter 9. Vector Embeddings and Stores
At this point in the book, you know how to infer models by using the DJL library and consume them with LangChain4j. Moreover, Chapter 3 introduced RAG, a fundamental concept when developing AI applications.
RAG heavily relies on vector embedding calculations and mathematics (i.e., cosine similarity, squared Euclidean, etc.) for similarity search. In this chapter, you’ll learn the following key aspects of vector embeddings:
-
Calculating embeddings using the DJL
-
Calculating embeddings using in-process LangChain4j
-
Calculating embeddings with remote models
-
Using vector stores to implement advanced search features or caching
-
Preparing and ingesting documents for RAG
-
Implementing a simple RAG
-
Using advanced RAG (QueryRouter, ReRanking, etc.)
After this chapter, you’ll know how to calculate vectors with various approaches and gain a good understanding of embeddings, not only from the perspective of RAG but also of other use cases. Moreover, we’ll show you some algorithms for visualizing vectors with large dimensions or clustering them to automatically categorize them.
Calculating Vector Embeddings
As a reminder, a vector embedding (or an embedding) is an array of numbers used to describe elements like text, audio, or images, capturing the semantic relationships in the form of a vector.
For example “cat” could have the [1, 0, 1] vector, while “car” could have the [7, 3, 8] vector.
You do this calculation by using specialized models ...
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