pythonlangchainlarge-language-modelembeddingamazon-bedrock

Embedding using the LangChain_AWS is giving None value


I am trying to embed a text using the langchain_aws BedrockEmbeddings, but when I invoke the function, I get a list with the None values.

Here's the code:

from langchain_community.llms.bedrock import Bedrock 
from langchain_aws import BedrockEmbeddings
import boto3

# Initialize the Bedrock client
bedrock_client = boto3.client(service_name='bedrock-runtime')

# Initialize Bedrock Embeddings
bedrock_embeddings = BedrockEmbeddings(
    model_id="amazon.titan-text-express-v1",
    credentials_profile_name="default",
    client=bedrock_client,
    region_name="ap-south-1"
)


embed_data=bedrock_embeddings.embed_documents(["This is a content of the document", "This is another document"])

print(embed_data)

Output:

[None, None]

Solution

  • amazon.titan-text-express-v1 is not embedding model. Its a text generation model.

    Use amazon.titan-embed-text-v2:0