New Jobs Simplified, AI University
← Back to courses

RAG — Retrieval-Augmented Generation

Hybrid & Advanced Retrieval

This lesson covers hybrid and advanced retrieval techniques in AI, including semantic search, retrieval-augmented generation, and reranking. We'll explore how to improve search results using language models and dense retrieval. We'll also discuss the importance of hybrid search and the trade-offs between different retrieval methods.

Why It Matters

In the real world of AI, hybrid search and retrieval techniques are crucial for building effective search systems that can handle complex queries and provide accurate results. By understanding these concepts, developers can create search systems that are more relevant and useful to users. This is particularly important in applications like search engines, chatbots, and recommendation systems.

Key Points

Dense Retrieval: Dense retrieval uses text embeddings to find the most similar documents to a query. This method is useful for finding relevant documents, but it can be less effective for finding exact matches.
Hybrid Search: Hybrid search combines keyword search and dense retrieval to provide a more comprehensive search experience. This approach is useful for handling both simple and complex queries.
Reranking: Reranking involves using a reranker to re-order the search results based on their relevance to the query. This step can improve the accuracy of search results.
Retrieval-Augmented Generation (RAG): RAG systems use a retriever to find relevant documents and then generate a response based on those documents. This approach can improve the accuracy and relevance of search results.
Embedding Methods: There are different embedding methods used in dense retrieval, including averaging chunks of text and aggregating them into a single vector.
Reranking Models: Reranking models use language models to re-rank search results based on their relevance to the query. This step can improve the accuracy of search results.
Hybrid Search vs Vector Databases: Hybrid search and vector databases are two different approaches to search. Hybrid search combines keyword search and dense retrieval, while vector databases use embeddings to find the most similar documents.
Reranking with Sentence Transformers: Reranking with sentence transformers involves using a library like Sentence Transformers to re-rank search results based on their relevance to the query.

Key Concepts

Dense Retrieval

A retrieval method that uses text embeddings to find the most similar documents to a query.

Hybrid Search

A search approach that combines keyword search and dense retrieval to provide a more comprehensive search experience.

Reranking

The process of re-ordering search results based on their relevance to the query.

Retrieval-Augmented Generation (RAG)

A system that uses a retriever to find relevant documents and then generates a response based on those documents.

Text Embeddings

A representation of text as a numerical vector that can be used for similarity calculations.

Code Examples

Keyword search with reranking

def keyword_and_reranking_search(query, top_k=3, num_candidates=10):

Reranking with sentence transformers

from sentence_transformers import SentenceTransformer
From the books
“the user with the best info they can get and leave it up to the user to decide if it’s relevant or not. 234 | Chapter 8: Semantic Search and Retrieval-Augmented Generation Tracking the information of …”
“capabilities to reduce hallucinations, increase factuality, and/or ground the gen‐ eration model on a specific dataset. Figure 8-3. A RAG system formulates an answer to a question and (preferably) cit…”
“metrics. Retrieval-Augmented Generation (RAG) | 257 Summary In this chapter, we looked at different ways of using language models to improve existing search systems and even be the core of new, more p…”

Quick Quiz

1. What is hybrid search?

A) A search approach that only uses keyword search.
B) A search approach that combines keyword search and dense retrieval.
C) A search approach that only uses dense retrieval.
D) A search approach that uses vector databases.

2. What is reranking?

A) The process of finding relevant documents.
B) The process of re-ordering search results based on their relevance to the query.
C) The process of generating a response based on relevant documents.
D) The process of indexing documents.

3. What is retrieval-augmented generation (RAG)?

A) A system that uses a retriever to find relevant documents and then generates a response based on those documents.
B) A system that uses a retriever to find relevant documents and then ranks them based on their relevance.
C) A system that uses a retriever to find relevant documents and then stores them in a database.
D) A system that uses a retriever to find relevant documents and then discards them.