Vector Store RAG
Build a Retrieval Augmented Generation (RAG) application with Astra DB and Langflow.
RAG applications level-up your chatbots with more specialized context loaded and retrieved from your own data.
This starter template contains two flows that must be run in order:
-
The Load Data flow loads data from a local file into the Astra DB vector store.
-
The Retriever flow generates responses to your queries from the documents stored in Astra DB.
This starter project highlights the use of Astra DB in a vector RAG application, but the Astra DB component is adaptable as a vector database for any Langflow project. For more information, see Create an Astra DB component in Langflow.
Prerequisites
-
An active Serverless (Vector) database
Open Langflow and start a new project
-
In the Astra Portal header, switch your active app from Astra DB Serverless to Langflow.
-
Click New Flow, and then select the Vector Store RAG project.
This opens a starter project with the necessary components to run a RAG application using Astra DB.
Run the load data flow
The load data flow ingests documents into the Astra DB database, and it has the following components:
-
A File component that uploads a text file to Langflow.
-
A Split Text component that splits the text into smaller chunks.
-
An OpenAI embeddings component that generates embeddings for the text chunks.
-
An Astra DB component that stores the embeddings in the Astra DB database.
To create the load data flow:
-
Add your credentials to the OpenAI components. The fastest way to complete these fields is with Langflow’s Global Variables.
-
In the OpenAI API Key field, click the
Globe icon, and then click Add New Variable. Alternatively, click your username in the top right corner and select Settings.
-
-
Click Global Variables, and then click Add New.
-
Name your variable. Paste your OpenAI API key (
sk-…
) in the Value field. -
In the Apply To Fields field, select the OpenAI API Key field to apply this variable to all OpenAI Embeddings components.
-
-
Add your credentials to the AstraDB component using the same Global Variables process.
-
In the Astra DB Application Token field, click the
and then click Add New Variable, or click your username in the top right corner and select Settings. -
Name your variable. Paste your Astra token (
AstraCS:…
) in the Value field. -
In the Apply To Fields field, select the Astra DB Application Token field to apply this variable to all Astra components.
-
-
In the Astra DB component, select the Database. If you don’t have a database, click Create new database to create one.
-
In the Astra DB component, select the Collection. If you don’t have a collection, click Create Collection to create one.
-
In the File component, upload a text file from your local machine with data you want to ingest into the Astra DB database.
-
In the Astra DB component, click
Play to start the load data flow. Your file passes through the Split Text component, which splits the text into smaller chunks. These chunks become units of meaning when the OpenAI Embeddings component embeds them as vectors into the database.
Run the retriever flow
The retriever flow generates responses to your queries from the embedded documents, and it has the following components:
-
The Chat Input component accepts user input to the chat.
-
An OpenAI embeddings component that generates embeddings from the user input, which is compared to the vector data in the database.
-
An Astra DB component that stores the embeddings in the Astra DB database.
-
The Parse Data component parses and converts data into plain text.
-
The Prompt component combines the user input with a user-defined prompt.
-
The OpenAI model component sends the user input and prompt to the OpenAI API and receives a response.
-
The Chat Output component prints the flow’s output to the chat.
If you used Langflow’s Global Variables feature, the RAG application flow components are already configured with the necessary credentials.
To run the retriever flow:
-
Click the
Playground to start a chat session. Because this flow includes Chat Input and Chat Output components, the Playground displays a Chat Input field and an Extracted Chunks output section. -
Enter a query, and then make sure the bot responds based on your uploaded data.