205: RAG on documents with LangChain and Elasticsearch
205: RAG on documents with LangChain and Elasticsearch
In this lab, you will review Jupyter notebooks that implement the Retrieval Augmented Generation (RAG) pattern of working with LLMs. We will be using Elasticsearch as the vector database.
Required software, access, and files
- To complete this lab you will need access to watsonx.ai
- A self-managed cluster using IBM Cloud® Databases for Elasticsearch.
- If you don't have a self-managed cluster from IBM, you can use an Elastic Cloud deployment instead. You can sign up here for a free trial.
- Some knowledge of Python
Why use elasticsearch as a vector database?
Elasticsearch is a proven industry-leading search engine that allows for similarity search on vector embeddings, BM25 search (also known as keyword or lexical search), and hybrid search which combines the two. Hybrid search has been shown to have greater relevance than using either in isolation.
In addition to these features, Elasticsearch offers efficient filtering on different metadata fields (like location, genre, category, etc) and easy aggregations for returning facets to filter result sets on further.
Finally, if you already have an Elasticsearch cluster, you won't need to go through the pain of setting up and maintaining a separate database just for vector search.
Setup the Jupyter notebook
To run the lab for this section we will start by logging into the watsonx platform; after navigating to the watsonx home page here, we will want to open the Notebook editor that we can use to run the notebook associated with this lab.
If you don't know how to acccess watsonx.ai or are unsure how to open to the notebook editor, follow this reference link which will walk you through the process for accessing watsonx.ai and opening the Jupyter notebook editor.
Use the following values for this lab:
Option 1: With a free trial of an Elastic Cloud deployment
- Name:
{uniqueid}-rag-elasticsearch-free
- Notebook URL:
https://raw.githubusercontent.com/ibm-build-lab/VAD-VAR-Workshop/main/content/labs/Watsonx/WatsonxAI/files/205/rag_elasticsearch_free.ipynb
Option 2: With a self-managed cluster using IBM Cloud® Databases for Elasticsearch
- Name:
{uniqueid}-rag-elasticsearch-cloud
- Notebook URL:
https://raw.githubusercontent.com/ibm-build-lab/VAD-VAR-Workshop/main/content/labs/Watsonx/WatsonxAI/files/205/rag_elasticsearch_cloud.ipynb
After your notebook is launched and created, you can follow along and run through each cell of the notebook to complete the lab. The notebook contains comments explaining what code in each cell does as well as any necessary input that you might need to provide to successfully run a cell.