AZURE OPEN AI vectorizer not working any leads will be appreciated

Description

weaviate version 4.11.3

Server Setup Information

  • Weaviate Server Version:
  • Deployment Method: docker deployment
  • Multi Node? Number of Running Nodes: 1 Node
  • Client Language and Version:
  • Multitenancy?: No

Any additional Information

I have set up with azure base url, resource name, deployment id and keys.

While weaviate client connecting with azure embedding service, below are the errors showing. Tried multiple trial and errors still not able to fix.

CLient: Code

def weaviate_custom_client():
    try:
        client = weaviate.connect_to_custom(
            http_host="localhost",
            http_port=8080,
            http_secure=False,
            grpc_host="localhost",
            grpc_port=50051,
            grpc_secure=False,
            headers={
                "X-OpenAI-Baseurl": "https://resource_name.openai.azure.com/",
                "X-Azure-Api-Key": OpenAI_Api_Key,
                "X-Azure-Deployment-Id": "text-embedding-ada-002",
                "X-Azure-Resource-Name": "resource_name"

                #"X-OpenAI-Api-Key": OpenAI_Api_Key,  # Or any other inference API keys

            }
        )
    except Exception as error:
        print(error)
        client.close()
    return(client)

    if not client.collections.exists("Article"):
            bot = client.collections.create(
                name="Article",
                vectorizer_config=Configure.Vectorizer.text2vec_azure_openai(
                    base_url="https://resource_name.openai.azure.com/",  
                    model="text-embedding-3-large", 
                    vectorize_collection_name = False,
                    resource_name="resource_name",
                    deployment_id='text-embedding-ada-002',
                    

                ),
            generative_config=Configure.Generative.azure_openai(
                resource_name="resource_name",
                deployment_id="gpt-4o",
                base_url="https://resource_name.openai.azure.com/"
            ),
                properties=[
                    Property(
                        name="title",
                        data_type = DataType.TEXT,
                        vectorize_property_name=True  
                    ),
                    Property(
                        name="body",
                        data_type=DataType.TEXT,  
                        vectorize_property_name=True  
                    )
                ]
            )

    print("collection created")

except Exception as error:
    print("Exception block called.. ")
    print(error)
finally:
    client.close()
    del client


## Inserting data
try:
    client = weaviate_custom_client()

    jeopardy = client.collections.get("Article")
    print("collection test:" +str(jeopardy.exists()))

    uuid = jeopardy.data.insert({
        "title": "A delicious Riesling",
        "body": "This wine is a delicious Riesling which pairs well with seafood."
    })

    print("data inserted")
except Exception as er:
    print(er)

finally:
    client.close()

INFO:httpx:HTTP Request: POST http://localhost:8080/v1/objects “HTTP/1.1 500 Internal Server Error”
Object was not added! Unexpected status code: 500, with response body: {‘error’: [{‘message’: ‘vectorize target vector : update vector: connection to: Azure OpenAI API failed with status: 401 error: Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.’}]}

Hi @bibhutibhusan362,

Welcome to the community.

Let me start with sharing some resources with you to help you with your setup:

Now, let me break it step by step what you need.

Step 1 - connect

I see that you are connecting to a localhost instance, so I guess you are running your Weaviate instance with Docker. You can connect to your Weaviate instance with connect_to_local().
Also, to work with Azure, you only need "X-Azure-Api-Key" header. Like this:

import weaviate

AZURE_OPENAI_API_KEY = "my-azure-key-here"

client = weaviate.connect_to_local(
    headers = {
        "X-Azure-Api-Key": AZURE_OPENAI_API_KEY
    },
)

print("Connection Ready: " + client.is_ready())

Step 2 - create a collection

When you create a collection, I noticed that you try to provided model and deployment_id. With AzureOpenAI you define the model you want to use through the deployment_id, the model is not used.

Also, if your base_url is based on your resource_name, you don’t need to provide it, as it can be derived from context.

Here is an example of a collection config, I’ve just tested (btw. in my case, I have access to text-embedding-3-small):

from weaviate.classes.config import Configure
client.collections.create(
    name="Article",
    vectorizer_config=Configure.Vectorizer.text2vec_azure_openai(
        deployment_id="text-embedding-3-small",
        resource_name="my-azure-openai-resource",
    ),
    generative_config=Configure.Generative.azure_openai(
        deployment_id="text-embedding-3-small",
        resource_name="my-azure-openai-resource"
    )
)

Step 3 - test insert

article = client.collections.get("Article")
article.data.insert({
    "title": "Sample Object",
    "body": "hello world"
})

Reviewing your error message.

It looks like your Azure API key and Resource doesn’t have the permissions to use the embedding model (provided through deployment_id).
Can you check if you have access to text-embedding-ada-002?

Alternative

Btw. I’ve had some issues with using Ada-002 through Azure in the past.
I find it works better for me when I use text-embedding-3-large and text-embedding-3-small.

Is there any chance you could add deployment for text-embedding-3-small or text-embedding-3-large, and test it with these models?

Thanks @sebawita : Tested a sample code using below script. This error I am getting while data insertion where weaviate not able to connect to Azure Open AI for vector embedding.

client = weaviate.connect_to_local(
  headers={
    "X-Azure-Api-Key": AZURE_OPENAI_KEY
  }
)
print(client.is_ready())

if (client.collections.exists("JeopardyQuestion")):
    client.collections.delete("JeopardyQuestion")

client.collections.create(
    name="JeopardyQuestion",

    vectorizer_config=wc.Configure.Vectorizer.text2vec_azure_openai(
        resource_name="xyz", # name of your resource
        deployment_id="text-embedding-3-small", # model deployed
    ),

    properties=[ # defining properties (data schema) is optional
        wc.Property(name="Question", data_type=wc.DataType.TEXT), 
        wc.Property(name="Answer", data_type=wc.DataType.TEXT),
        wc.Property(name="Category", data_type=wc.DataType.TEXT, skip_vectorization=True), 
    ]
)

print("Successfully created collection: JeopardyQuestion.")


url = 'https://raw.githubusercontent.com/weaviate/weaviate-examples/main/jeopardy_small_dataset/jeopardy_tiny.json'
resp = requests.get(url)
data = json.loads(resp.text)

# Get a collection object for "JeopardyQuestion"
jeopardy = client.collections.get("JeopardyQuestion")

# Insert data objects
response = jeopardy.data.insert_many(data)

# Note, the `data` array contains 10 objects, which is great to call insert_many with.
# However, if you have a milion objects to insert, then you should spit them into smaller batches (i.e. 100-1000 per insert)

if (response.has_errors):
    print(response.errors)
else:
    print("Insert complete.")

Again Same error:
weaviate.exceptions.WeaviateInsertManyAllFailedError: Every object failed during insertion. Here is the set of all errors: connection to: Azure OpenAI API failed with status: 401 error: Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.

Yes, it is still the same error. So, there is something wrong with your Azure API key, resource, and deployment.

resource

Just to be clear. When you run this code, do you use a different value for the resource_name, or do you use "xyz"?

deployment_id

Also, can you verify that your Azure configuration has deployment for "text-embedding-3-small"?

API Key

Can you confirm if your API key is from Azure, or is that your standard OpenAI key?