Skip to content

Operations Not allowed when I use AWS embedding model amazon.titan-embed-text-v2:0

0

Hi Team, I am building RAG model and I get the following error [ValueError: Error raised by inference endpoint: An error occurred (ValidationException) when calling the InvokeModel operation: Operation not allowed Traceback: File "/usr/local/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/usr/local/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 590, in code_to_exec exec(code, module.dict) File "/app/admin.py", line 96, in <module> main() File "/app/admin.py", line 85, in main result = create_vector_store(request_id, splitted_docs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/admin.py", line 38, in create_vector_store vectorstore_faiss=FAISS.from_documents(documents, bedrock_embeddings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain_core/vectorstores/base.py", line 835, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain_community/vectorstores/faiss.py", line 1041, in from_texts embeddings = embedding.embed_documents(texts) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain_community/embeddings/bedrock.py", line 173, in embed_documents response = self._embedding_func(text) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langchain_community/embeddings/bedrock.py", line 154, in _embedding_func raise ValueError(f"Error raised by inference endpoint: {e}") ValueError: Error raised by inference endpoint: An error occurred (ValidationException) when calling the InvokeModel operation: Operation not allowed]. I have granted access to the model on eu-west-2 region. But not sure why it gives me Operation Not allowed" error. Any insights would be hepful. Thanks

  • My code as follows import boto3 import streamlit as st import os import uuid

    s3_client

    s3_client = boto3.client("s3") BUCKET_NAME = os.getenv("BUCKET_NAME")

    Bedrock

    from langchain_community.embeddings import BedrockEmbeddings

    Text Splitter

    from langchain.text_splitter import RecursiveCharacterTextSplitter

    Pdf Loader

    from langchain_community.document_loaders import PyPDFLoader

    import FAISS

    from langchain_community.vectorstores import FAISS

    bedrock_client = boto3.client(service_name="bedrock-runtime",region_name='eu-west-2') bedrock_embeddings = BedrockEmbeddings(model_id="amazon.titan-embed-text-v2:0", client=bedrock_client)

    def get_unique_id(): return str(uuid.uuid4())

    Split the pages / text into chunks

    def split_text(pages, chunk_size, chunk_overlap): text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap) docs = text_splitter.split_documents(pages) return docs

    create vector store

    def create_vector_store(request_id, documents): print("1888888888888888888888888888") vectorstore_faiss=FAISS.from_documents(documents, bedrock_embeddings) print("9999999999999999999999") file_name=f"{request_id}.bin" print("1010101010101010101010101") folder_path="/tmp/" print("121212121212121212121212") vectorstore_faiss.save_local(index_name=file_name, folder_path=folder_path) print("13131313131313131313131313")

    ## upload to S3
    s3_client.upload_file(Filename=fol
    
1 Answer
0

Hello @Mits,

Based on the error message you are seeing, it appears that there's an issue with permissions or access to the Bedrock model you are trying to use for embeddings.

Here are a few things to check and try:

  1. IAM Permissions: Make sure the IAM role or user associated with your application has the necessary permissions to invoke the Bedrock model. The required permission is typically bedrock:InvokeModel.
  2. Region Configuration: Ensure that your AWS SDK or Bedrock client is configured to use the correct region (eu-west-2 in your case). Sometimes, the client might default to a different region if not explicitly set.
  3. Model Access: Double-check that you have indeed been granted access to the specific model you are trying to use. Sometimes there can be a delay between granting access and it becoming effective.
  4. Model Availability: Verify that the model you are trying to use is available in the eu-west-2 region. Not all models are available in all regions.
  5. Quota Limits: Check if you have hit any quota limits for the Bedrock service in your AWS account.
  6. AWS CLI Test: Try invoking the model using the AWS CLI to see if you get the same error. This can help isolate whether it's a code issue or a permissions/access issue.
 aws bedrock invoke-model --model-id <your-model-id> --body '{"prompt": "Hello"}' --region eu-west-2
  7. Bedrock Console: Try accessing the model through the AWS Bedrock console to see if you can use it there.
  8. Check AWS CloudTrail: Look at CloudTrail logs to see if there are any more detailed error messages or access denied events related to your Bedrock invocations.
  9. Bedrock Client Configuration: If you're using a Bedrock client in your code, make sure it's properly configured with the correct credentials and region.
  10. Retry with Exponential Backoff: Sometimes these errors can be transient. Implement a retry mechanism with exponential backoff in your code.
AWS

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.