You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updates chatbot-rag-app and simplifies instructions
This updates chatbot-rag-app to the latest libraries and simplifies
instructions by delegating details of configuration to the .env file.
This also works around problems we found in DEBUG mode, by using
production mode regardless of task. Doing so notably will allow
tracing to work in the future.
Efforts here were thanks to many, despite me raising it, notably
@joemcelroy@ezimuel@xrmx and @anuraaga
Signed-off-by: Adrian Cole <[email protected]>
tar -xz --strip=2 elasticsearch-labs-main/example-apps/chatbot-rag-app
16
16
```
17
17
18
-
## Installing and connecting to Elasticsearch
19
-
20
-
### Install Elasticsearch
21
-
22
-
There are a number of ways to install Elasticsearch. Cloud is best for most use-cases. Visit the [Install Elasticsearch](https://www.elastic.co/search-labs/tutorials/install-elasticsearch) for more information.
18
+
## Make your .env file
23
19
24
-
### Connect to Elasticsearch
20
+
Copy [env.example](env.example) to `.env` and fill in values noted inside.
25
21
26
-
This app requires the following environment variables to be set to connect to Elasticsearch hosted on Elastic Cloud:
27
-
28
-
```sh
29
-
export ELASTIC_CLOUD_ID=...
30
-
export ELASTIC_API_KEY=...
31
-
```
32
-
33
-
You can add these to a `.env` file for convenience. See the `env.example` file for a .env file template.
34
-
35
-
#### Self-Hosted Elasticsearch
22
+
## Installing and connecting to Elasticsearch
36
23
37
-
You can also connect to a self-hosted Elasticsearch instance. To do so, you will need to set the following environment variables:
24
+
There are a number of ways to install Elasticsearch. Cloud is best for most
25
+
use-cases. Visit the [Install Elasticsearch](https://www.elastic.co/search-labs/tutorials/install-elasticsearch) for more information.
38
26
39
-
```sh
40
-
export ELASTICSEARCH_URL=...
41
-
```
27
+
Once you decided your approach, edit your `.env` file corresponding to your
28
+
Elastic Cloud or self-hosted Elasticsearch instance.
42
29
43
-
### Change the Elasticsearch index and chat_history index
30
+
### Elasticsearch index and chat_history index
44
31
45
-
By default, the app will use the `workplace-app-docs` index and the chat history index will be `workplace-app-docs-chat-history`. If you want to change these, you can set the following environment variables:
To use Vertex AI you need to set the following environment variables. More information [here](https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm).
112
-
113
-
```sh
114
-
export LLM_TYPE=vertex
115
-
export VERTEX_PROJECT_ID=<gcp-project-id>
116
-
export VERTEX_REGION=<gcp-region># Default is us-central1
To use Mistral AI you need to set the following environment variables. The app has been tested with Mistral Large Model deployed through Microsoft Azure. More information [here](https://learn.microsoft.com/en-us/azure/ai-studio/how-to/deploy-models-mistral).
123
-
124
-
```
125
-
export LLM_TYPE=mistral
126
-
export MISTRAL_API_KEY=...
127
-
export MISTRAL_API_ENDPOINT=... # should be of the form https://<endpoint>.<region>.inference.ai.azure.com
128
-
export MISTRAL_MODEL=... # optional
129
-
```
130
-
131
-
### Cohere
132
-
133
-
To use Cohere you need to set the following environment variables:
Once you have indexed data into the Elasticsearch index, there are two ways to run the app: via Docker or locally. Docker is advised for testing & production use. Locally is advised for development.
52
+
There are two ways to run the app: via Docker or locally. Docker is advised for
53
+
ease while locally is advised if you are making changes to the application.
144
54
145
-
### Through Docker
55
+
### Run with docker
146
56
147
-
Build the Docker image and run it with the following environment variables.
57
+
Docker compose is the easiest way, as you get one-step to:
58
+
* build the [frontend](frontend)
59
+
* ingest data into elasticsearch
60
+
* run the app, which listens on http://localhost:4000
148
61
149
-
```sh
150
-
docker build -f Dockerfile -t chatbot-rag-app .
62
+
```bash
63
+
docker compose up --build --force-recreate
151
64
```
152
65
153
-
#### Ingest data
66
+
*Note*: First time creating the index can fail on timeout. Wait a few minutes
67
+
and retry.
154
68
155
-
Make sure you have a `.env` file with all your variables, then run:
69
+
### Run locally
156
70
157
-
```sh
158
-
docker run --rm --env-file .env chatbot-rag-app flask create-index
159
-
```
71
+
If you want to run this example with Python and Node.js, you need to do a few
72
+
things listed in the [Dockerfile](Dockerfile).
160
73
161
-
See "Ingest data" section under Running Locally for more details about the `flask create-index` command.
74
+
**Make sure you have a `.env` file with all your variables**
162
75
163
-
#### Run API and frontend
76
+
#### Build the frontend
164
77
165
-
You will need to set the appropriate environment variables in your `.env` file. See the `env.example` file for instructions.
78
+
The web assets are in the [frontend](frontend) directory, and built with yarn.
166
79
167
-
```sh
168
-
docker run --rm -p 4000:4000 --env-file .env -d chatbot-rag-app
80
+
```bash
81
+
# Install and use a recent node, if you don't have one.
Note that if you are using an LLM that requires an external credentials file (such as Vertex AI), you will need to make this file accessible to the container in the `run` command above. For this you can use a bind mount, or you can also edit the Dockerfile to copy the credentials file to the container image at build time.
172
-
173
-
### Locally (for development)
174
-
175
-
With the environment variables set, you can run the following commands to start the server and frontend.
176
-
177
-
#### Pre-requisites
88
+
#### Configure your python environment
178
89
179
-
-Python 3.8+
180
-
- Node 14+
90
+
Before we can run the app, we need a working Python environment with the
91
+
correct packages installed:
181
92
182
-
#### Install the dependencies
183
-
184
-
For Python we recommend using a virtual environment.
185
-
186
-
_ℹ️ Here's a good [primer](https://realpython.com/python-virtual-environments-a-primer) on virtual environments from Real Python._
187
-
188
-
```sh
189
-
# Create a virtual environment
190
-
python -m venv .venv
191
-
192
-
# Activate the virtual environment
93
+
```bash
94
+
python3 -m venv .venv
193
95
source .venv/bin/activate
194
-
195
-
# Install Python dependencies
96
+
# install dev requirements for pip-compile and dotenv
97
+
pip install pip-tools "python-dotenv[cli]"
98
+
pip-compile
196
99
pip install -r requirements.txt
197
-
198
-
# Install Node dependencies
199
-
cd frontend && yarn &&cd ..
200
100
```
201
101
202
-
#### Ingest data
203
-
204
-
You can index the sample data from the provided .json files in the `data` folder:
102
+
#### Run the ingest command
205
103
206
-
```sh
207
-
flask create-index
104
+
First, ingest the data into elasticsearch:
105
+
```bash
106
+
$ dotenv run -- flask create-index
107
+
".elser_model_2" model not available, downloading it now
108
+
Model downloaded, starting deployment
109
+
Loading data from ./data/data.json
110
+
Loaded 15 documents
111
+
Split 15 documents into 26 chunks
112
+
Creating Elasticsearch sparse vector store in http://localhost:9200
208
113
```
209
114
210
-
By default, this will index the data into the `workplace-app-docs` index. You can change this by setting the `ES_INDEX` environment variable.
211
-
212
-
##### Indexing your own data
213
-
214
-
The ingesting logic is stored in `data/index-data.py`. This is a simple script that uses Langchain to index data into Elasticsearch, using the `JSONLoader` and `CharacterTextSplitter` to split the large documents into passages. Modify this script to index your own data.
215
-
216
-
Langchain offers many different ways to index data, if you cant just load it via JSONLoader. See the [Langchain documentation](https://python.langchain.com/docs/modules/data_connection/document_loaders)
115
+
*Note*: First time creating the index can fail on timeout. Wait a few minutes
116
+
and retry.
217
117
218
-
Remember to keep the `ES_INDEX` environment variable set to the index you want to index into and to query from.
118
+
#### Run the app
219
119
220
-
#### Run API and frontend
221
-
222
-
```sh
223
-
# Launch API app
224
-
flask run
225
-
226
-
# In a separate terminal launch frontend app
227
-
cd frontend && yarn start
120
+
Now, run the app, which listens on http://localhost:4000
121
+
```bash
122
+
$ dotenv run -- flask run
123
+
* Serving Flask app 'api/app.py'
124
+
* Debug mode: off
228
125
```
229
-
230
-
You can now access the frontend at http://localhost:3000. Changes are automatically reloaded.
0 commit comments