LANGCHAIN AZURE OPENAI PROBLEM:The embeddings operation does not work with the specified model, gpt-4.

Anna Sukhanova 0 Reputation points
2024-09-30T15:06:01.8966667+00:00

I am trying to repeat code from Medium (https://medium.com/@kartik11721/implementing-retrieval-augmented-generation-rag-with-azure-openai-and-langchain-e2a6689ea52e), but i get a very weird error

BadRequestError: Error code: 400 - {'error': {'code': 'OperationNotSupported', 'message': 'The embeddings operation does not work with the specified model, gpt-4. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.'}}

import os
from dotenv import load_dotenv
# Correct imports based on your update
from langchain_community.document_loaders import TextLoader
from langchain_community.vectorstores import FAISS
from langchain_openai import AzureOpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
def create_vector_database(txt_path):
# Initialize TextLoader with the absolute path to the txt file
 loader = TextLoader(txt_path)
# Load documents from the file
 docs = loader.load()
# Split documents into chunks
 documents = RecursiveCharacterTextSplitter(
 chunk_size=1000, separators=["\n", "\n\n"], chunk_overlap=200
 ).split_documents(docs)
# Initialize embeddings with Azure OpenAI settings
 embeddings = AzureOpenAIEmbeddings(
 azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
 openai_api_version=os.environ.get("AZURE_OPENAI_API_VERSION"),
 )
# Create a FAISS index from the documents and embeddings
 db = FAISS.from_documents(
 documents=documents,
 embedding=embeddings
 )
# Save the FAISS database locally
 db.save_local("./faiss-db")
if __name__ == "__main__":
# Ensure that the environment variables are loaded (if using a .env file)
 load_dotenv()
# Define the absolute path to the txt file
 txt_path = '/home/anna/Desktop/simple_rag/ozimpic.txt'
# Call the function with the absolute path
 create_vector_database(txt_path)


Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daniel Fang 1,060 Reputation points MVP
    2024-10-07T04:56:38.3833333+00:00

    Hi Anna. Just had a quick look at the link you provided, the error seems to indicate that your deployed model in the Azure OpenAI service is not an embedding model. For example, text-embedding-3-large or any of the ada models on Azure are actually the embedding models.

    The attached error message 'The embeddings operation does not work with the specified model, gpt-4.' indicates that your deployment is likely a gpt-4 model, it could not be used for embedding generation. refer to below line of python:

    embeddings = AzureOpenAIEmbeddings( azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT"), ... )

    0 comments No comments

  2. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2024-10-16T06:45:28.0366667+00:00

    @Anna Sukhanova Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    .

    The embeddings operation in Azure OpenAI Service is supported by the models text-embedding-ada-002 (Version 2), text-embedding-3-large, and text-embedding-3-small. More info here.

    • Replace the gpt-4 model with a above mentioned model that supports embeddings.
    • Try with the sample mentioned here.

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.