Bedrock 임베딩
Bedrock 임베딩
AWS Bedrock의 임베딩 모델을 LlamaIndex에서 사용하는 예시예요. AWS 자격 증명으로 임베딩 모델을 만들고, 지원되는 모델 목록을 확인하며, Amazon/Cohere 모델로 텍스트를 벡터화하는 방법을 보여줘요.
출처: 문서
본문
colab에서 이 노트북을 열고 있다면 LlamaIndex 🦙를 설치해야 할 거예요.
%pip install llama-index-embeddings-bedrock
import os
from llama_index.embeddings.bedrock import BedrockEmbedding
embed_model = BedrockEmbedding(
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
aws_session_token=os.getenv("AWS_SESSION_TOKEN"),
region_name="<aws-region>",
profile_name="<aws-profile>",
)
embedding = embed_model.get_text_embedding("hello world")
지원 모델 목록 (List supported models)
LlamaIndex에서 Amazon Bedrock이 지원하는 모델 목록을 확인하려면 BedrockEmbedding.list_supported_models()를 호출해요.
from llama_index.embeddings.bedrock import BedrockEmbedding
import json
supported_models = BedrockEmbedding.list_supported_models()
print(json.dumps(supported_models, indent=2))
프로바이더: Amazon
Amazon Bedrock Titan 임베딩이에요.
from llama_index.embeddings.bedrock import BedrockEmbedding
model = BedrockEmbedding(model_name="amazon.titan-embed-g1-text-02")
embeddings = model.get_text_embedding("hello world")
print(embeddings)
프로바이더: Cohere
cohere.embed-english-v3
model = BedrockEmbedding(model_name="cohere.embed-english-v3")
coherePayload = ["This is a test document", "This is another test document"]
embed1 = model.get_text_embedding("This is a test document")
print(embed1)
embeddings = model.get_text_embedding_batch(coherePayload)
print(embeddings)
Cohere의 다국어 임베딩 (MultiLingual Embeddings from Cohere)
model = BedrockEmbedding(model_name="cohere.embed-multilingual-v3")
coherePayload = [
"This is a test document",
"తెలుగు అనేది ద్రావిడ భాషల కుటుంబానికి చెందిన భాష.",
"Esto es una prueba de documento multilingüe.",
"攻殻機動隊",
"Combien de temps ça va prendre ?",
"Документ проверен",
]
embeddings = model.get_text_embedding_batch(coherePayload)
print(embeddings)