Sitemap
TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Member-only story

Implementing Anthropic’s Contextual Retrieval for Powerful RAG Performance

13 min readOct 18, 2024

--

Retrieval augmented generation (RAG) is a powerful technique that utilizes large language models (LLMs) and vector databases to create more accurate responses to user queries. RAG allows LLMs to utilize large knowledge bases when responding to user queries, improving the quality of the responses. However, RAG also has some downsides. One downside is that RAG utilizes vector similarity when retrieving context to respond to a user query. Vector similarity is not always consistent and can, for example, struggle with unique user keywords. Furthermore, RAG also struggles because the text is divided into smaller chunks, which prohibits the LLM from utilizing the full contexts of documents when responding to queries. Anthropic’s article on contextual retrieval attempts to solve both problems by using BM25 indexing and adding contexts to chunks.

Learn how to implement Anthropic’s contextual retrieval RAG in this article. Image by ChatGPT.

Motivation

My motivation for this article is twofold. First, I would like to test out the newest models and techniques within machine learning. Keeping up to date with the latest trends within machine learning is critical for any ML engineer and data scientist to most…

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Eivind Kjosbakken
Eivind Kjosbakken

Written by Eivind Kjosbakken

Data scientist at Findable. Former CS Student at TU Delft and NTNU. I write articles about AI. Reach me at: https://www.linkedin.com/in/eivind-kjosbakken/