How can I create a vector embedding for a statement/sentence using the Titan embedding model on Bedrock?

0

Hi, I have been using the langchain library for LLM coding. Could someone share a simple code snippet that can be used to generate the vector embedding for a sentence stored in a string? I have no experience/ background using my AWS authentication in a Jupyter notebook and need guidance there. Thanks.

1개 답변
0

Hi Vishal! Thanks for reaching out.

Refer to the below snippet to generate a vector embedding for a sentence stored in a string:

from langchain.embeddings import BedrockEmbeddings

#create an Amazon Titan Text Embeddings client
embeddings_client = BedrockEmbeddings() 

#Define the text from which to create embeddings
text = "Can you please tell me how to get to the bakery?"

#Invoke the model
embedding = embeddings_client.embed_query(text)

#Print response
print(embedding)

This snippet was pulled from the "Getting started with Amazon Titan Text Embeddings in Amazon Bedrock" blog - https://aws.amazon.com/blogs/machine-learning/getting-started-with-amazon-titan-text-embeddings/

You'll be able to get the full example in the above link so please feel free to review this resource for additional, insightful information. This example uses the boto3 library which you can also use for authentication. That said, credentials can be configured in multiple ways so I'll point you to another relevant resource. You can choose which method is most appropriate given your specific use-case and/or needs which is helpful if you're working within a local Jupyter notebook - https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

Cheers!

AWS
지원 엔지니어
답변함 2달 전
profile picture
전문가
검토됨 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠