-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[DOCS] RAG overview #119590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[DOCS] RAG overview #119590
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e52188d
wip
leemthompo da060e9
Refactor, add workflow diagram, links
leemthompo 7b78a82
Highlight can start cheap
leemthompo d1b3362
LLM -> LM because it needn't be large
leemthompo f9d9e5f
We're not in Oxford anymore
leemthompo 6045d61
Tweak diagrams
leemthompo ca54e5b
Updates per review
leemthompo 2042bd2
Merge branch 'main' into rag
leemthompo 256ade8
Uncomment link
leemthompo 5049a29
Tweak USPs
leemthompo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions
76
docs/reference/search/search-your-data/retrieval-augmented-generation.asciidoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
leemthompo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * *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] | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cute