Skip to content

Instantly share code, notes, and snippets.

import boto3
s3_client = boto3.client('s3')
bucket_name = 'your-s3-bucket-name' # Replace with your actual bucket name
s3_key = 'embeddings/embeddings.json' # Optional path within bucket
# Upload local file to S3
s3_client.upload_file('embeddings.json', bucket_name, s3_key)
print(f'Uploaded embeddings.json to s3://{bucket_name}/{s3_key}')
import json
with open('embeddings.json', 'w') as f:
        json.dump(embeddings, f)
import os
folder_path = './sample-data'
embeddings = {}
for filename in os.listdir(folder_path):
       if filename.endswith('.txt'):
            filepath = os.path.join(folder_path, filename)
            with open(filepath, 'r') as file:
                    text = file.read()
import boto3
import json
client = boto3.client('sagemaker-runtime', region_name='your-region') # Repalce with the region you're using
endpoint_name = 'your-endpoint-name' # Repalce with your endpoint name
def get_embedding(text):
       response = client.invoke_endpoint(
               EndpointName=endpoint_name,
               ContentType='application/x-text',