Skip to content

unionai-oss/union-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Union RAG

UnionAI-native RAG applications.

Note

If you're here for the LLM RAG workshop, go here.

Setup

conda create -n union-rag python=3.11 -y
pip install -r requirements.txt

Create the Knowledge Base

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

Run the Simple RAG Workflow

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?'

Simple RAG Workflow Deployment

Deploy the workflow to Union with the following command:

union register union_rag/simple_rag.py

Run the Agentic RAG Workflow

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.'

Slack App Deployment

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.

  1. Follow the Bolt getting started guide to create a slack app.

    • Follow the instructions to create a SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET.
    • Create a UNIONAI_SERVERLESS_API_KEY using unionai create app union-rag
  2. 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>
    
  3. Export the secrets to your environment:

    export $(cat secrets.txt | xargs)
  4. Create the deploy.yaml file:

    cat template.yaml | envsubst > deploy.yaml
    
  5. Make sure your ~/.aws/credentials file is properly configured with your aws_access_key_id and aws_secret_access_key.

  6. Login to AWS ECR. First do aws configure sso, then:

    aws sso login --profile <PROFILE>
  7. Run sam build --template deploy.yaml to build the app.

  8. 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
    
  9. 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.

About

Doing RAG on Union

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages