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
Updated tutorial for Bedrock Serverless PDF Chat (#57)
* Updated tutorial for Bedrock Serverless PDF Chat: revised prerequisites to include uv, modified dependency installation instructions, clarified connection string requirements, and updated embedding model references. Fixed minor typos and improved clarity in several sections.
* Clarified connection string requirements in Bedrock Serverless PDF Chat tutorial by removing the `?tls_verify=none` part for improved accuracy.
Copy file name to clipboardExpand all lines: tutorial/markdown/python/bedrock-serverless-pdf-chat/bedrock-serverless-pdf-chat.md
+25-30Lines changed: 25 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,8 +40,7 @@ This tutorial will demonstrate how to -
40
40
41
41
## Prerequisites
42
42
43
-
-[Python](https://www.python.org/downloads/) 3.10 or higher installed.
44
-
- Ensure that the Python version is [compatible](https://docs.couchbase.com/python-sdk/current/project-docs/compatibility.html#python-version-compat) with the Couchbase SDK.
43
+
- Ensure [`uv`](https://docs.astral.sh/uv/) installed. `uv` helps us manage Python versions and create a lockfile for all the project's dependencies for ease of use.
45
44
- Couchbase Cluster (Self Managed or Capella) version 7.6.2+ with [Search Service](https://docs.couchbase.com/server/current/fts/fts-introduction.html) and [Eventing Service](https://docs.couchbase.com/server/current/eventing/eventing-overview.html)
46
45
47
46
> Note that this tutorial is designed to work with the latest Python SDK version (4.3.0+) for Couchbase. It will not work with the older Python SDK versions.
Any dependencies should be installed through `pip`, the default package manager for Python. You may use [virtual environment](https://docs.python.org/3/tutorial/venv.html) as well.
60
+
Dependencies for the project are installed via `uv` as mentioned earlier. You can install the dependencies using the following command:
> The [connection string](https://docs.couchbase.com/python-sdk/current/howtos/managing-connections.html#connection-strings) expects the `couchbases://` or `couchbase://` part.
201
+
> The [connection string](https://docs.couchbase.com/python-sdk/current/howtos/managing-connections.html#connection-strings) expects the `couchbases://` or `couchbase://` part. In the end, the connection string must look something like this: `couchbases://capella.connection.string.com`.
203
202
204
203
> For this tutorial, `CB_BUCKET = pdf-chat`, `CB_SCOPE = shared`, `CB_COLLECTION = docs` and `INDEX_NAME = pdf_search`.
205
204
@@ -209,22 +208,22 @@ We need to set up our AWS Environment and run all the necessary services.
209
208
210
209
#### Deploy Lambdas to ECR
211
210
212
-
We will need to use Lambdas deployed as docker container in the [AWS Elastic Container Registry Service](https://aws.amazon.com/ecr/). We have two lambdas in the application at directory `src/lambads`. For Each of the lambdas a new ECR Repository needs to be created.
211
+
We will need to use Lambdas deployed as docker container in the [AWS Elastic Container Registry Service](https://aws.amazon.com/ecr/). We have two lambdas in the application at directory `src/lambdas`. For Each of the lambdas a new ECR Repository needs to be created.
213
212
214
213
Firstly build the docker image for the two of them using `docker build` in the respective folder
215
214
216
215
```bash
217
216
docker build -t <lambda name>.
218
217
```
219
218
220
-
Lambda name will be chat and ingest for the respective folders.
219
+
Lambda name will be `chat` and `ingest` for the respective folders.
221
220
Then use [this guide from AWS](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html) to understand how to push an image to ECR.
222
221
223
222
Once it's pushed, we are ready for the next steps.
224
223
225
224
#### Enable Bedrock
226
225
227
-
You may need to allow access to models used in this example via [Amazon Bedrock](https://console.aws.amazon.com/bedrock). Click on get started to open Bedrock console. in the sidebar, there will be option of `Bedrock configurations`. Click on model access inside it. For this tutorial we are using models `Titan Multimodal Embeddings G1` and `Llama 3 70B Instruct`. You can change the lambda named chat if you need any other models. Click on modify model access and select models required. Accept terms and conditions and now the AI Model will be ready to use.
226
+
You may need to allow access to models used in this example via [Amazon Bedrock](https://console.aws.amazon.com/bedrock). Click on get started to open Bedrock console. in the sidebar, there will be option of `Bedrock configurations`. Click on model access inside it. For this tutorial we are using models `Titan Text Embedding v2` and `Llama 3 70B Instruct`. You can change the lambda named chat if you need any other models. Click on modify model access and select models required. Accept terms and conditions and now the AI Model will be ready to use.
228
227
229
228
#### Setup AWS CLI
230
229
@@ -247,10 +246,10 @@ You may enter a couple of `y` to approve the deployment. This step will ensure 2
247
246
We will need to update the environment file to include one more variable at the end of `.env` file we created at [Setup Environment Config](#setup-environment-config). The variable name is `CHAT_URL`
This variable must have the API gateway endpoint of the ChatBedrockStack which came as part of cdk deploy. The exact endpoint also includes `/chat` so append it to the back of URL.
252
+
This variable must have the API gateway endpoint of the CouchbaseChatStack which came as part of cdk deploy. The exact endpoint also includes `/chat` so append it to the back of URL.
254
253
255
254
### Setup Couchbase Eventing
256
255
@@ -260,7 +259,7 @@ We will use import function feature of couchbase eventing. Go to eventing tab in
260
259
261
260
> We are using _default scope and _default collection for storing eventing temp files, you may use some other collection of your choice.
262
261
263
-
Now, in the create bindings step, Change the `API_URL` variable to URL of the API gateway endpoint of `IngestBedrockStack`. The URL should be appended with `/send` to indicate exact endpoint of the function.
262
+
Now, in the create bindings step, Change the `API_URL` variable to URL of the API gateway endpoint of `CouchbaseBedrockStack`. The URL should be appended with `/send` to indicate exact endpoint of the function.
264
263
265
264
Once it's updated, click next, and you can see your JS eventing function. You may add any logging or any features you may require here. The default function sends data to API gateway which inside AWS calls SQS and Lambda which will update the file with necessary embeddings.
266
265
@@ -462,34 +461,30 @@ The first step will be connecting to Couchbase. Couchbase Vector Store is requir
462
461
The connection string and credentials are read from the environment variables. We perform some basic required checks for the environment variable not being set in the `.env`, and then proceed to connect to the Couchbase cluster. We connect to the cluster using [connect](https://docs.couchbase.com/python-sdk/current/hello-world/start-using-sdk.html#connect) method.
logging.error(f'Error while connecting: {str(e)}')
475
+
raise e
481
476
```
482
477
483
478
#### Get bedrock embeddings
484
479
485
-
This part of code uses AWS SDK to get bedrock. Then initializes the embedding object. For this example we are using `amazon.titan-embed-image-v1` embedding model.
480
+
This part of code uses AWS SDK to get bedrock. Then initializes the embedding object. For this example we are using `amazon.titan-embed-text-v2` embedding model.
486
481
487
482
```python
488
483
from langchain_aws.embeddings import BedrockEmbeddings
0 commit comments