Bedrock 嵌入模型¶
如果您在 Colab 上打开此 Notebook,可能需要先安装 LlamaIndex 🦙。
In [ ]:
Copied!
%pip install llama-index-embeddings-bedrock
%pip install llama-index-embeddings-bedrock
In [ ]:
Copied!
import os
from llama_index.embeddings.bedrock import BedrockEmbedding
import os
from llama_index.embeddings.bedrock import BedrockEmbedding
In [ ]:
Copied!
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>",
)
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="",
profile_name="",
)
In [ ]:
Copied!
embedding = embed_model.get_text_embedding("hello world")
embedding = embed_model.get_text_embedding("hello world")
查看支持的模型列表¶
要查询 LlamaIndex 上 Amazon Bedrock 支持的所有模型列表,可调用 BedrockEmbedding.list_supported_models() 方法,操作如下。
In [ ]:
Copied!
from llama_index.embeddings.bedrock import BedrockEmbedding
import json
supported_models = BedrockEmbedding.list_supported_models()
print(json.dumps(supported_models, indent=2))
from llama_index.embeddings.bedrock import BedrockEmbedding
import json
supported_models = BedrockEmbedding.list_supported_models()
print(json.dumps(supported_models, indent=2))
服务提供商:亚马逊¶
Amazon Bedrock Titan 嵌入模型。
In [ ]:
Copied!
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)
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)
In [ ]:
Copied!
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)
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 的多语言嵌入技术¶
In [ ]:
Copied!
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)
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)