2 Vector similarity search and hybrid search

 

This chapter covers

  • Introduction to embeddings, embedding models, vector space, and vector similarity search
  • How vector similarity fits in RAG applications
  • A practical walkthrough of a RAG application using vector similarity search
  • Adding full-text search to the RAG application to see how enabling a hybrid search approach can improve results

Creating a knowledge graph can be an iterative process where you start with unstructured data and then add structure to it. This is often the case when you have a lot of unstructured data and you want to start using it to answer questions.

This chapter will look at how we can use RAG to answer questions using unstructured data. We’ll look at how to use vector similarity search and hybrid search to find relevant information and how to use that information to generate an answer. In later chapters, we’ll look at what techniques we can use to improve the retriever and generator to get better results when there’s some structure to the data.

In data science and machine learning, embedding models and vector similarity search are important tools for handling complex data. This chapter looks at how these technologies turn complicated data, like text and images, into uniform formats called embeddings.

2.1 Components of a RAG architecture

2.1.1 The retriever

2.1.2 The generator

2.2 RAG using vector similarity search

2.2.1 Application data setup

2.2.2 The text corpus

2.2.3 Text chunking

2.2.4 Embedding model

2.2.5 Database with vector similarity search function

2.2.6 Performing vector search

2.2.7 Generating an answer using an LLM

2.3 Adding full-text search to the RAG application to enable hybrid search

2.3.1 Full-text search index

2.3.2 Performing hybrid search

2.4 Concluding thoughts

Summary