Export
RAG Pipeline with LlamaIndex
In this notebook we will look into building RAG with LlamaIndex using MistralAI LLM and Embedding Model. Additionally, we will look into using Index as Retreiver.
- Basic RAG pipeline.
- Index as Retriever.
[ ]
Setup API Keys
[1]
Basic RAG pipeline
Following are the steps involved in Builiding a basic RAG pipeline.
- Setup LLM and Embedding Model
- Download Data
- Load Data
- Create Nodes
- Create Index
- Create Query Engine
- Querying
Query Engine combines Retrieval and Response Synthesis modules to generate response for the given query.
Setup LLM and Embedding Model
[2]
[3]
[4]
Download Data
We will use Uber 2021 10K SEC Filings for the demonstration.
[5]
--2024-03-29 13:12:05-- https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/10k/uber_2021.pdf Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.108.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1880483 (1.8M) [application/octet-stream] Saving to: ‘./uber_2021.pdf’ ./uber_2021.pdf 100%[===================>] 1.79M --.-KB/s in 0.1s 2024-03-29 13:12:05 (13.7 MB/s) - ‘./uber_2021.pdf’ saved [1880483/1880483]
Load Data
[6]
[7]
Create Nodes
[8]
[9]
Create Index
[10]
[11]
Create Query Engine
[12]
Querying
[13]
[14]
The total revenue for Uber in 2021 was $17,455 million. This includes revenue from various offerings such as Mobility, Delivery, Freight, and All Other revenue streams. The Mobility revenue was $6,953 million, Delivery revenue was $8,362 million, Freight revenue was $2,132 million, and All Other revenue was $8 million.
Index as Retriever
We can make use of created index as a Retriever. Retriever helps you to retrieve relevant chunks/ nodes for the given user query.
Create Retriever
[15]
Retrieve relevant nodes for a Query
[16]
[17]
[ ]