From 45e57073c0a9ef33c4f67c9c88a0f8cc316f1f41 Mon Sep 17 00:00:00 2001 From: Liam Thompson <32779855+leemthompo@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:18:39 +0100 Subject: [PATCH] [DOCS] RAG overview (#119590) --- docs/reference/images/search/rag-schema.svg | 73 ++++++++++++++++++ .../images/search/rag-venn-diagram.svg | 19 +++++ .../retrieval-augmented-generation.asciidoc | 76 +++++++++++++++++++ .../search-your-data.asciidoc | 1 + 4 files changed, 169 insertions(+) create mode 100644 docs/reference/images/search/rag-schema.svg create mode 100644 docs/reference/images/search/rag-venn-diagram.svg create mode 100644 docs/reference/search/search-your-data/retrieval-augmented-generation.asciidoc diff --git a/docs/reference/images/search/rag-schema.svg b/docs/reference/images/search/rag-schema.svg new file mode 100644 index 0000000000000..f26edac6c0077 --- /dev/null +++ b/docs/reference/images/search/rag-schema.svg @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + Define how the model should + parse and render information + + Custom instructions + + + + + + Full-text, semantic + or hybrid search + + Search strategy + + + + + + + 1 + + + 2 + + + 3 + + + 4 + + + + + + User query + + + + Elasticsearch + + Retrieves relevant + documents + + + + Language model + Processes context & + + generates answer + + + + + + + + + Response + \ No newline at end of file diff --git a/docs/reference/images/search/rag-venn-diagram.svg b/docs/reference/images/search/rag-venn-diagram.svg new file mode 100644 index 0000000000000..9906aaefaba0c --- /dev/null +++ b/docs/reference/images/search/rag-venn-diagram.svg @@ -0,0 +1,19 @@ + + + + + + + + + Information + retrieval + + + Generative + AI + + + + RAG + \ No newline at end of file diff --git a/docs/reference/search/search-your-data/retrieval-augmented-generation.asciidoc b/docs/reference/search/search-your-data/retrieval-augmented-generation.asciidoc new file mode 100644 index 0000000000000..2958999ede91d --- /dev/null +++ b/docs/reference/search/search-your-data/retrieval-augmented-generation.asciidoc @@ -0,0 +1,76 @@ +[rag-elasticsearch] +== Retrieval augmented generation + +.🍿 Prefer a video introduction? +*********************** +Check out https://www.youtube.com/watch?v=OS4ZefUPAks[this short video] from the Elastic Snackable Series. +*********************** + +Retrieval Augmented Generation (RAG) is a technique for improving language model responses by grounding the model with additional, verifiable sources of information. It works by first retrieving relevant context from an external datastore, which is then added to the model's context window. + +RAG is a form of https://arxiv.org/abs/2301.00234[in-context learning], where the model learns from information provided at inference time. +Compared to fine-tuning or continuous pre-training, RAG can be implemented more quickly and cheaply, and offers several advantages. + +image::images/search/rag-venn-diagram.svg[RAG sits at the intersection of information retrieval and generative AI, align=center, width=500] + +RAG sits at the intersection of https://www.elastic.co/what-is/information-retrieval[information retrieval] and generative AI. +{es} is an excellent tool for implementing RAG, because it offers various retrieval capabilities, such as full-text search, vector search, and hybrid search, as well as other tools like filtering, aggregations, and security features. + +[discrete] +[[rag-elasticsearch-advantages]] +=== Advantages of RAG + +Implementing RAG with {es} has several advantages: + +* *Improved context:* Enables grounding the language model with additional, up-to-date, and/or private data. +* *Reduced hallucination:* Helps minimize factual errors by enabling models to cite authoritative sources. +* *Cost efficiency:* Requires less maintenance compared to fine-tuning or continuously pre-training models. +* *Built-in security:* Controls data access by leveraging {es}'s <> features, such as role-based access control and field/document-level security. +* *Simplified response parsing:* Eliminates the need for custom parsing logic by letting the language model handle parsing {es} responses and formatting the retrieved context. +* *Flexible implementation:* Works with basic <>, and can be gradually updated to add more advanced and computationally intensive <> capabilities. + +[discrete] +[[rag-elasticsearch-components]] +=== RAG system overview + +The following diagram illustrates a simple RAG system using {es}. + +image::images/search/rag-schema.svg[Components of a simple RAG system using Elasticsearch, align=center, role="stretch"] + +The workflow is as follows: + +. The user submits a query. +. Elasticsearch retrieves relevant documents using full-text search, vector search, or hybrid search. +. The language model processes the context and generates a response, using custom instructions. Examples of custom instructions include "Cite a source" or "Provide a concise summary of the `content` field in markdown format." +. The model returns the final response to the user. + +[TIP] +==== +A more advanced setup might include query rewriting between steps 1 and 2. This intermediate step could use one or more additional language models with different instructions to reformulate queries for more specific and detailed responses. +==== + +[discrete] +[[rag-elasticsearch-getting-started]] +=== Getting started + +Start building RAG applications quickly with Playground, which seamlessly integrates {es} with language model providers. +The Playground UI enables you to build, test, and deploy RAG interfaces on top of your {es} indices. + +Playground automatically selects the best retrieval methods for your data, while providing full control over the final {es} queries and language model instructions. +You can also download the underlying Python code to integrate with your existing applications. + +Learn more in the {kibana-ref}/playground.html[Playground documentation] and +try the https://www.elastic.co/demo-gallery/ai-playground[interactive lab] for hands-on experience. + +[discrete] +[[rag-elasticsearch-learn-more]] +=== Learn more + +Learn more about building RAG systems using {es} in these blog posts: + +* https://www.elastic.co/blog/beyond-rag-basics-semantic-search-with-elasticsearch[Beyond RAG Basics: Advanced strategies for AI applications] +* https://www.elastic.co/search-labs/blog/building-a-rag-system-with-gemma-hugging-face-elasticsearch[Building a RAG system with Gemma, Hugging Face, and Elasticsearch] +* https://www.elastic.co/search-labs/blog/rag-agent-tool-elasticsearch-langchain[Building an agentic RAG tool with Elasticsearch and Langchain] + + + diff --git a/docs/reference/search/search-your-data/search-your-data.asciidoc b/docs/reference/search/search-your-data/search-your-data.asciidoc index 90a273a8cfe4d..0828462fd1850 100644 --- a/docs/reference/search/search-your-data/search-your-data.asciidoc +++ b/docs/reference/search/search-your-data/search-your-data.asciidoc @@ -49,6 +49,7 @@ include::../../how-to/recipes.asciidoc[] include::retrievers-overview.asciidoc[] include::knn-search.asciidoc[] include::semantic-search.asciidoc[] +include::retrieval-augmented-generation.asciidoc[] include::search-across-clusters.asciidoc[] include::search-with-synonyms.asciidoc[] include::search-application-overview.asciidoc[]