Skip to main content
In this tutorial, we’ll demonstrate how to use Upstash Vector with LlamaIndex to perform RAG (Retrieval-Augmented Generation). We will upload a document about global warming and generate responses to our questions based on the contents of the document.

Installation and Setup

First, we need to create a Vector Index in the Upstash Console. Make sure to set the index dimensions to 1536 and the distance metric to Cosine. Once we have our index, we will copy the UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN and paste them into our .env file. To learn more about index creation, you can check out our getting started page. Add the following content to your .env file (replace with your actual URL, token and API key):
We now need to install the following libraries via PyPI:

Code

We will load our environment variables, initialize the index, and configure it to use the specified dimensions and distance metric.
Next, we will query the document:

Sample Output

Here is the output of the queries:

Notes

  • Namespaces can be used to separate different types of documents. You can specify a namespace when creating the UpstashVectorStore instance: