|
1 |
| -## My Project |
| 1 | +## Intelligent BI Demo |
2 | 2 |
|
3 |
| -TODO: Fill this README out! |
| 3 | +[中文文档](README_CN.md) |
4 | 4 |
|
5 |
| -Be sure to: |
| 5 | +## Deployment Guide |
6 | 6 |
|
7 |
| -* Change the title in this README |
8 |
| -* Edit your repository description on GitHub |
| 7 | +### 1. Prepare EC2 Instance |
| 8 | +Create an EC2 with following configuration: |
| 9 | + |
| 10 | + - Software Image (AMI): Amazon Linux 2023 |
| 11 | + - Virtual server type (instance type): t3.large or higher |
| 12 | + - Firewall (security group): Allow 22, 80 port |
| 13 | + - Storage (volumes): 1 GP3 volume(s) - 30 GiB |
| 14 | + |
| 15 | +### 2. Config Permission |
| 16 | +Bind an IAM Role to your EC2 instance. |
| 17 | +And attach an inline policy to this IAM Role with following permissions: |
| 18 | +```json |
| 19 | +{ |
| 20 | + "Version": "2012-10-17", |
| 21 | + "Statement": [ |
| 22 | + { |
| 23 | + "Sid": "VisualEditor0", |
| 24 | + "Effect": "Allow", |
| 25 | + "Action": [ |
| 26 | + "bedrock:*", |
| 27 | + "secretsmanager:GetSecretValue", |
| 28 | + "dynamodb:*" |
| 29 | + ], |
| 30 | + "Resource": "*" |
| 31 | + } |
| 32 | + ] |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Make sure you have enabled model access in AWS Console in us-west-2 (美国西部 (俄勒冈州)) region for Anthropic Claude model and Amazon Titan embedding model. |
| 37 | + |
| 38 | +### 3. Install Docker and Docker Compose |
| 39 | + |
| 40 | +On the EC2 instance, log in to the SSH command line as the ec2-user user or use the AWS EC2 Instance Connect feature in the EC2 console to log in to the command line. In the session, execute the following commands. If you are not this user, you can switch with the following command: |
| 41 | + |
| 42 | +Note: Execute each command one line at a time. |
| 43 | + |
| 44 | +```bash |
| 45 | +sudo su - ec2-user |
| 46 | +``` |
| 47 | + |
| 48 | +```bash |
| 49 | +# Install components |
| 50 | +sudo dnf install docker python3-pip git -y && pip3 install docker-compose |
| 51 | + |
| 52 | +# Fix docker python wrapper 7.0 SSL version issue |
| 53 | +pip3 install docker==6.1.3 |
| 54 | + |
| 55 | +# Configure components |
| 56 | +sudo systemctl enable docker && sudo systemctl start docker && sudo usermod -aG docker $USER |
| 57 | + |
| 58 | +# Exit the terminal |
| 59 | +exit |
| 60 | +``` |
| 61 | + |
| 62 | +### 4. Install the Demo Application |
| 63 | + |
| 64 | +Reopen a terminal session and continue executing the following commands: |
| 65 | + |
| 66 | +Note: Execute each command one line at a time. |
| 67 | + |
| 68 | +```bash |
| 69 | +# Log in as user ec2-user |
| 70 | + |
| 71 | +# Configure OpenSearch server parameters |
| 72 | +sudo sh -c "echo 'vm.max_map_count=262144' > /etc/sysctl.conf" && sudo sysctl -p |
| 73 | + |
| 74 | +# Clone the code |
| 75 | +git clone https://github.com/aws-samples/generative-bi-using-rag.git |
| 76 | + |
| 77 | +# Build docker images locally |
| 78 | +cd generative-bi-using-rag/application && cp .env.template .env && docker-compose build |
| 79 | + |
| 80 | +# Start all services |
| 81 | +docker-compose up -d |
| 82 | + |
| 83 | +# Wait 3 minutes for MySQL and OpenSearch to initialize |
| 84 | +sleep 180 |
| 85 | +``` |
| 86 | + Here is the English translation: |
| 87 | + |
| 88 | +### 5. Initialize MySQL |
| 89 | + |
| 90 | +In the terminal, continue executing the following commands: |
| 91 | + |
| 92 | +```bash |
| 93 | +cd initial_data && unzip init_mysql_db.sql.zip && cd .. |
| 94 | +docker exec nlq-mysql sh -c "mysql -u root -ppassword -D llm < /opt/data/init_mysql_db.sql" |
| 95 | +``` |
| 96 | + |
| 97 | +### 6. Initialize OpenSearch |
| 98 | + |
| 99 | +6.1 Initialize the index for the sample data by creating a new index: |
| 100 | + |
| 101 | +```bash |
| 102 | +docker exec nlq-webserver python opensearch_deploy.py |
| 103 | +``` |
| 104 | + |
| 105 | +If the script fails due to any errors, delete the index and rerun the previous command: |
| 106 | + |
| 107 | +```bash |
| 108 | +curl -XDELETE -k -u admin:admin "https://localhost:9200/uba" |
| 109 | +``` |
| 110 | + |
| 111 | +6.2 (Optional) Bulk import custom QA data by appending to an existing index: |
| 112 | + |
| 113 | +```bash |
| 114 | +docker exec nlq-webserver python opensearch_deploy.py custom false |
| 115 | +``` |
| 116 | + |
| 117 | +### 7. Access the Streamlit Web UI |
| 118 | + |
| 119 | +Open in your browser: `http://<your-ec2-public-ip>` |
| 120 | + |
| 121 | +Note: Use HTTP instead of HTTPS. |
| 122 | + |
| 123 | +## How to use custom data sources with the demo app |
| 124 | +1. First create the corresponding Data Profile in Data Connection Management and Data Profile Management. |
| 125 | +2. After selecting the Data Profile, start asking questions. For simple questions, the LLM can directly generate the correct SQL. If the generated SQL is incorrect, try adding more annotations to the Schema. |
| 126 | +3. Use the Schema Management page, select the Data Profile, and add comments to the tables and fields. These comments will be included in the prompt sent to the LLM. |
| 127 | + (1) For some fields, add values to the Annotation attribute, e.g. "Values: Y|N", "Values: Shanghai|Jiangsu". |
| 128 | + (2) For table comments, add domain knowledge to help answer business questions. |
| 129 | +4. Ask the question again. If still unable to generate the correct SQL, add Sample QA pairs to OpenSearch. |
| 130 | + (1) Using the Index Management page, select the Data Profile then you can add, view and delete QA pairs. |
| 131 | + |
| 132 | +5. Ask again. In theory, the RAG approach (PE uses Few shots) should now be able to generate the correct SQL. |
9 | 133 |
|
10 | 134 | ## Security
|
11 | 135 |
|
|
0 commit comments