This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
with open('embeddings.json', 'w') as f: | |
json.dump(embeddings, f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |