Using OpenAIEmbeddings and chroma with Azure Open AI

I want to use OpenAIEmbeddings with Azure Open AI (not Open AI). There is no definitive documentation on this.

says to use AzureOpenAIEmbeddings but it gives an error of

ImportError: cannot import name 'AzureOpenAIEmbeddings' from 'langchain.embeddings.openai'

How to configure LangChain to use Azure OpenAI in Python – NillsF blog mentions about using OPENAI_… settings instead of AZURE_OPENAI_… with that I am able to get OpenAIEmbeddings() working with my Azure Open AI subscription however when I go ahead and try:

docs = vectordb.similarity_search(question,k=3)

I get an error of:

AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: <my key>. You can find your API key at', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

[ ]:

which makes me believe that it is probably going to OpenAI instead of Azure OpenAI. Or do I need anything more in my Azure Open AI subscription to make it work? If so, what?
Any ideas?

Microsoft has a blog which does it. The actual APIs used there are a little different from the ones mentioned here. Though both of these seem to be doing the same thing.

Also not sure whether the code given here itself would work as it is in case of LangChain plus subscription as the notebook seems to hint here. It seems to be in beta and will wait for my invite I guess now that I am waitlisted.

I could get it working with langchain.embeddings.azure_openai.AzureOpenAIEmbeddings which I couldn’t figure out earlier because of its different namespace.

There is a great post on this around this Utilizing Azure OpenAI for Completing Generative AI Courses

Sharing it here since it has much more information than my answer and gives a very good insight into parity between Open AI and Azure Open AI in general.