Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions s3-lambda-bedrock-aoss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Important: this application uses various AWS services and there are costs associ
```
cd s3-lambda-bedrock-aoss
```
3. From the command line, run `build-layer.sh` that would download required dependencies used to create a Lambda Layer
3. Build the layers and prepare the application for deployment
```
./build-layer.sh
sam build
```
4. Use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
```
Expand Down
3 changes: 3 additions & 0 deletions s3-lambda-bedrock-aoss/dependencies/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
crhelper
opensearch-py
PyPDF2
22 changes: 21 additions & 1 deletion s3-lambda-bedrock-aoss/src/index_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,27 @@ def get_aoss_index_name(resource_properties):

#Function to use the opensearch-py library to create an index within an opensearch collection
def create_aoss_index(index_name, aos_client):
aos_client.indices.create(index=index_name)

index_body = {
"settings": {
"index.knn": True
},
"mappings": {
"properties": {
"page_vector": {
"type": "knn_vector",
"dimension": 1536
},
"page_text": {
"type": "text"
},
"page_number": {
"type" : "integer"
}
}
}
}
aos_client.indices.create(index=index_name, body=index_body)
print(f"Created index {index_name}")

#Handles create event of the CloudFormation resource
Expand Down
3 changes: 3 additions & 0 deletions s3-lambda-bedrock-aoss/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
crhelper
opensearch-py
PyPDF2
8 changes: 5 additions & 3 deletions s3-lambda-bedrock-aoss/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Parameters:
Type: String
Description: "The collection name to create for storing vector embeedings"
ConstraintDescription: "Must be a valid name for Amazon OpenSearch Service Collection."
Default: "example_collection"
Default: "example-collection"
AmazonOpenSearchIndexName:
Type: String
Description: "The index name to store vector embeedings"
ConstraintDescription: "Must be a valid Amazon OpenSearch Service Vector Index."
Default: "example_index"
Default: "example-index"
BedrockModelRegion:
Type: String
Description: Select the Bedrock service region from available options. Please make sure the model is access granted in the selected region Bedrock service. If your AOS service is in a region that is different than the bedrock service region, you may expect cross-region latency.
Expand Down Expand Up @@ -161,6 +161,8 @@ Resources:
ContentUri: dependencies/.
CompatibleRuntimes:
- python3.11
Metadata:
BuildMethod: python3.11

SourceBucket:
Type: AWS::S3::Bucket
Expand Down Expand Up @@ -222,4 +224,4 @@ Outputs:
Description: S3 Bucket for object storage
DocumentIngestionLambdaFunctionName:
Value: !Ref DocumentIngestionLambdaFunction
Description: Document Ingestion Lambda Function Name
Description: Document Ingestion Lambda Function Name