Skip to content

Commit

Permalink
[DOCS] RAG overview (elastic#119590)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemthompo committed Jan 7, 2025
1 parent e3ea188 commit 59f005e
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
73 changes: 73 additions & 0 deletions docs/reference/images/search/rag-schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions docs/reference/images/search/rag-venn-diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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 <<authorization, user authorization>> 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 <<full-text-search,full-text search>>, and can be gradually updated to add more advanced and computationally intensive <<semantic-search,semantic search>> 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]



Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down

0 comments on commit 59f005e

Please sign in to comment.