liveBook · Manning

Chapter 2: Vector similarity search and hybrid search

What you will learn in chapter 2 of Essential GraphRAG

This chapter introduces using embeddings, vector similarity search, and hybrid search in a RAG application to answer questions from unstructured data.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces using embeddings, vector similarity search, and hybrid search in a RAG application to answer questions from unstructured data.

Key terms: RAG, unstructured data, knowledge graph, retriever, generator, embedding models, embeddings, vector space, vector similarity search, full-text search

2.1 Components of a RAG architecture

This section introduces the retriever and generator as the two main components of a RAG application and states their respective roles.

Key terms: RAG application, retriever, generator, vector similarity search

2.1.1 The retriever

This section explains how a RAG retriever prepares and searches embedded text chunks to supply relevant context to a generator.

Key terms: retriever, generator, retriever pipeline, query, source chunks, vector similarity search, vector index, approximate nearest neighbor search, brute-force search, nearest neighbors

2.1.2 The generator

This section explains how the RAG generator uses retrieved information to produce answers and why this allows smaller, faster, cheaper, and more grounded language models.

Key terms: generator, retriever, RAG application, response, base knowledge, RAG, language model, hallucinate, retrieved information, finetuning

2.2 RAG using vector similarity search

This section introduces the planned vector-similarity RAG application, its retriever-to-response flow, and its separation into data setup and query-time stages.

Key terms: RAG application, vector similarity search, retriever, response, data setup, query time

2.2.1 Application data setup

This section introduces the data-preparation components and embedding flow that make vector similarity search possible in a RAG application.

Key terms: text corpus, text-chunking function, embedding model, database with vector similarity search ability, text chunks, vector index, embeddings, vector similarity search, vector space

2.2.2 The text corpus

This subsection introduces the Einstein patent paper as a corpus for demonstrating how RAG handles specific questions better than an LLM alone.

Key terms: text corpus, Einstein’s Patents and Inventions, Caudhuri, 2017, RAG, LLM, specific questions, paper

2.2.3 Text chunking

This section explains how to split corpus text into overlapping, whitespace-aligned chunks to improve vector retrieval quality.

Key terms: text chunking, chunk size, context window, overlap, sliding window, 500 characters, 40 characters, index, retriever, embedding model

2.2.4 Embedding model

This section selects a text embedding model for chunk embeddings and explains why the same model must be used consistently with the vector index.

Key terms: embedding model, text-embedding model, OpenAI, all-MiniLM-L12-v2, Sentence Transformers, Hugging Face, vector index, vectors, repopulate the vector index

2.2.5 Database with vector similarity search function

This section stores text-chunk embeddings in Neo4j by defining a simple Chunk model, creating a dimension-matched vector index, and loading the chunk data.

Key terms: Chunk, text, embedding, vector index, pdf, cosine similarity, dimensions, Cypher, index

2.2.6 Performing vector search

This section embeds a user question and uses Cypher to retrieve and inspect the two most similar text chunks from the populated Neo4j vector index.

Key terms: embedding model, embed the question, text chunks, embeddings, vector similarity search, Cypher, vector index, top two, similar chunks, matched chunks

2.2.7 Generating an answer using an LLM

This section completes the vector-search RAG flow by giving an LLM the original question and retrieved chunk text so it can stream a grounded answer.

Key terms: system message, user message, text property, similar chunks, retriever, stream, LLM result

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

This section introduces hybrid search as a way to improve a vector-search RAG retriever by adding full-text search for production-quality results.

Key terms: vector similarity search, full-text search, hybrid search, retriever, RAG application

2.3.1 Full-text search index

This section distinguishes keyword-based full-text search from vector similarity search and adds a Neo4j full-text index to support hybrid search.

Key terms: full-text search, keywords, vector space, exact match, full-text search index, Neo4j, PdfChunkFulltext, text property, :Chunk nodes, hybrid search

2.3.2 Performing hybrid search

This section explains how hybrid search combines normalized vector-similarity and full-text-search results in a Cypher query to return deduplicated top-k matches.

Key terms: hybrid search, vector similarity search, full-text search, deduplicate, top k results, union Cypher query, normalize the scores, highest score, top result, second result

2.4 Concluding thoughts

This section concludes that hybrid retrieval combines vector similarity and full-text search for better results, but remains limited by retrieving from unstructured text.

Key terms: vector similarity search, full-text search, hybrid search, retriever, unstructured data, references, surrounding context, LLMs

2.5 Summary

This summary recaps a RAG pipeline, vector and hybrid retrieval, and the limits of these retrieval approaches as data becomes more complex.

Where this is used later

Concepts explained in this chapter

← Chapter 1: Improving LLM accuracy Chapter 3: Advanced vector retrieval strategies →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.