Copyright IBM Corp. 2020, 2024
This is an example "question and answer" application built using watsonx.ai Flows Engine. You can recreate the content in this directory by following along this tutorial. The example uses a vector database to make a LLM context aware of a set of documents.
To deploy the RAG flows, make sure to install and authenticate the wxflows
CLI. Then add your credentials to watsonx.ai in the .env
file or use the shared "getting started" instance:
# Shared "getting started"
STEPZEN_WATSONX_HOST=shared
# Your own watsonx.ai credentials (optionally)
# STEPZEN_WATSONX_AI_APIKEY=
# STEPZEN_WATSONX_HOST=
# STEPZEN_WATSONX_PROJECTID=
The use of
STEPZEN_WATSONX_AI_TOKEN
is deprecated sincewxflows 1.0.0rc189
and up. Please update your CLI when you're on an older version.
Extract the file watsonxdocs.zip
, it contains a set of HTML documents that we'll prepare for upload to the vector database.
Run the command wxflows init --interactive
and follow the steps, use ./watsonxdocs
as the data source and watsonxdocs
as the collection name.
Uncomment the flow myRag
like this:
[wxflows.deployment]
# Example flows.
flows="""
// myPrompt = ragAnswerInput | topNDocs | promptFromTopN | ragInfo
myRag = ragAnswerInput | topNDocs | promptFromTopN | completion(parameters:myRag.parameters) | ragInfo
// myRagWithGuardrails = ragAnswerInput | topNDocs | promptFromTopN | completion(parameters:myRagWithGuardrails.parameters) | ragScoreInfo | hallucinationScore | ragScoreMessage | ragInfo
"""
The data needs to be uploaded to the vector database, which you can do by running wxflows collection deploy
. Running this command will take a couple of minutes to finish.
Then you can run the command wxflows deploy
to deploy your flows to a live endpoint.
You can run this application in the browser using the free service StackBlitz:
In the .env
file add the values generated by the following command:
echo VITE_WXFLOWS_ENDPOINT=https://$(wxflows whoami --account).$(wxflows whoami --domain)/wxflows-genai/watsonxdocs/graphql
echo VITE_WXFLOWS_APIKEY=$(wxflows whoami --apikey)
echo VITE_WXFLOWS_COLLECTION=watsonxdocs
You need to be logged into the wxflows
CLI to generate the above values!
- Follow the instructions to set up a RAG flow
You need to have Node.js (>16) installed on your machine, from the directory app
run:
npm install
This will install all the needed dependencies for the project.
Add your environment variables for watsonx.ai Flows Engine to a new .env
file, you need to be logged into the wxflows
CLI, by running:
echo VITE_WXFLOWS_ENDPOINT=https://$(wxflows whoami --account).$(wxflows whoami --domain)/wxflows-genai/watsonxdocs/graphql >> .env
echo VITE_WXFLOWS_APIKEY=$(wxflows whoami --apikey) >> .env
echo VITE_WXFLOWS_COLLECTION='watsonxdocs' >> .env
You can now start the application by running:
npm run dev
The location of the application will be shown in your terminal.
Make sure the flowName
variable on line 12 in /src/callWxflows.js
match your value in wxflows.toml
.
Please reach out to us on Discord if you have any questions or want to share feedback. We'd love to hear from you!