UnionAI-native RAG applications.
Note
If you're here for the LLM RAG workshop, go here.
conda create -n union-rag python=3.11 -y
pip install -r requirements.txt
First create the knowledge base offline:
union run --remote union_rag/simple_rag.py create_knowledge_base \
--exclude_patterns '["/api/", "/_tags/"]' \
--embedding_type "openai" \
--limit 100
For quick iteration and development, you can run the workflow on Union with:
union run --remote union_rag/simple_rag.py ask --question 'what is flytekit?'
Deploy the workflow to Union with the following command:
union register union_rag/simple_rag.py
Run the agentic RAG workflow with a more complex question:
union run --remote union_rag/agentic_rag.py ask \
--question 'Write a flytekit workflow that trains an sklearn model on the wine dataset.'
Run the same workflow with feedback:
union run --remote union_rag/agentic_rag.py ask_with_feedback \
--question 'Write a flytekit workflow that trains an sklearn model on the wine dataset.'
Deployment instructions
Install sam cli.
We'll use bolt to create a slack bot and
sam cli
to deploy a lambda function that will serve as one of the backend
layers for our question-answering slackbot.
-
Follow the Bolt getting started guide to create a slack app.
- Follow the instructions to create a
SLACK_BOT_TOKEN
andSLACK_SIGNING_SECRET
. - Create a
UNIONAI_SERVERLESS_API_KEY
usingunionai create app union-rag
- Follow the instructions to create a
-
Create a
secrets.txt
file to store these credentials. This file is ignored by git and should look something like this:SLACK_BOT_TOKEN=<SLACK_BOT_TOKEN> SLACK_SIGNING_SECRET=<SLACK_SIGNING_SECRET> UNIONAI_SERVERLESS_API_KEY=<UNIONAI_SERVERLESS_API_KEY>
-
Export the secrets to your environment:
export $(cat secrets.txt | xargs)
-
Create the
deploy.yaml
file:cat template.yaml | envsubst > deploy.yaml
-
Make sure your
~/.aws/credentials
file is properly configured with youraws_access_key_id
andaws_secret_access_key
. -
Login to AWS ECR. First do
aws configure sso
, then:aws sso login --profile <PROFILE>
-
Run
sam build --template deploy.yaml
to build the app. -
Run
sam deploy --guided
to deploy the app to AWS. This will ask you a series of questions on specific values you want to use for the deployment. In the end you should see an output like this:CloudFormation outputs from deployed stack ----------------------------------------------------------------------------------------------------------------- Outputs ----------------------------------------------------------------------------------------------------------------- Key UnionRagApi Description API Gateway endpoint URL for Prod stage for union rag function Value https://xyz.execute-api.us-east-2.amazonaws.com/Prod/ Key UnionRagFunctionIamRole Description Implicit IAM Role created for union rag function Value arn:aws:iam::xyz:role/union-rag-UnionRagFunctionRole-xyz Key UnionRagFunction Description union rag Lambda Function ARN Value arn:aws:lambda:us-east-2:xyz:function:union-rag-UnionRagFunction-xyz ----------------------------------------------------------------------------------------------------------------- Successfully created/updated stack - union-rag in us-east-2
-
Now test your slack app by installing it in your slack workspace and typing
@flyte-attendant what is flytekit?
. You should see an initial response from the bot, followed by the answer to your question.