How to use Python V4 Api with Azure?

Hi all,

using Azure with Weaviate required defining the “moduleConfig” in the schema.

            "vectorizer": "text2vec-openai",
            "moduleConfig": {
                "text2vec-openai": {
                    "baseURL": "https://COMPANYINSTANCE.openai.azure.com/",
                    "resourceName": "COMPANYINSTANCE",
                    "deploymentId": "text-embedding-ada-002",
                },
            },

I would like to use the new Weaviate client V4. However, I cannot find any way to specify it with Azure e.g., when inserting data into a collection. Is that not possible yet? Or is there a way to similarly provide the ModuleConfig somewhere so that one can pass the baseURL and the deploymentId, which are needed to use the Azure instance?

I tried this:

azure_openai_key = os.getenv("AZURE_APIKEY")

weaviate_client = weaviate.WeaviateClient(
    connection_params=weaviate.ConnectionParams.from_params(
        http_host="0.0.0.0",
        http_port="8080",
        http_secure=False,
        grpc_host="0.0.0.0",
        grpc_port="50051",
        grpc_secure=False,
    ),
    auth_client_secret=weaviate.AuthApiKey(weaviate_secret_key),
    additional_headers={
        "X-Azure-Api-Key": azure_openai_key
    },
)


    parameters = {
        "collection_name": "Test_Collection",
        "vectorizer_config": wvc.Configure.Vectorizer.text2vec_openai(
            base_url="https://COMPANYINSTANCE.openai.azure.com/", model="ada"
        ),
        "properties": [
            wvc.Property(name="property1", data_type=wvc.DataType.TEXT),
            wvc.Property(name="property2", data_type=wvc.DataType.TEXT)
        ],
    }

    inserter = Inserter(weaviate_client, "weaviate", parameters)

    data_to_insert = {"property1": "value1", "property2": "value2"}

    inserter.insert_data(data_to_insert)

However, I get this error:

[{'message': 'update vector: API Key: no api key found neither in request header: X-Openai-Api-Key nor in environment variable under OPENAI_APIKEY'}]

The problem also happened before when using V3 and not providing the baseURL (see above config), so providing it is essential. But I have not found any documentation for v4 and Azure and I was wondering whether it is currently just not possible? We would also need to define the deploymentId and within the IDE it does not suggest me any parameter like this.

Many thanks in advance!

1 Like

Does anybody know whether one can use Azure with the V4 Python Client?

Hi @c-lara !!

Sorry for the delay here! :grimacing:

Azure Open Ai will require some different parameters (deploymentId, resource_name and base_url) when compared with “Vanilla” Open Ai

For that reason, in Weaviate python v4 client, we now have wvc.Configure.Vectorizer.text2vec_azure_openai

For defining it, you can do as follow:

client.collections.create(
    name="Collection Name",
    vectorizer_config=wvc.Configure.Vectorizer.text2vec_azure_openai(
        resource_name="",
        deployment_id="",
        vectorize_class_name=False,
        base_url="",
    )
)

As our Python V4 client is still in beta, we are yet to produce all the docs.

Let me know if this helps :slight_smile:

1 Like

Amazing, thank you @DudaNogueira! :slight_smile: That is really helpful and I hope the V4 will make it :raised_hands:

hi there. i’m not sure i have the entirely same problem, but i’ve encountered the same error upon trying to query data i’d ingested into my weaviate instance. i had in fact used the correct wvc.Configure.Vectorizer.text2vec_azure_openai vectorizer, but i think i’m not sure where to retrieve resource_name, deployment_id, or base_url in the azure openai studio dashboard.

@DudaNogueira do you know where I might find this?

Hi! After you deploy a mode in Azure OpenAI you get those informations.

I don’t have one handy here, but I’ll probably do next week.

right, but they have different names – the terms cited in the weaviate documentation don’t exist verbatim in azure openai. i’ve tried a few different combination,s but i’ve not been able to get it to work.

Hi @Nik,

I’m not totally sure what your question is referring to but maybe my code below helps you somewhat?

azure_openai_key = YOUR_KEY 


weaviate_client = weaviate.WeaviateClient(
    connection_params=ConnectionParams.from_params(
        http_host="weaviate",
        http_port="8080",
        http_secure=False,
        grpc_host="weaviate",
        grpc_port="50051",
        grpc_secure=False,
    ),
    auth_client_secret=weaviate.auth.AuthApiKey(weaviate_secret_key),
    additional_headers={
        "X-Azure-Api-Key": azure_openai_key,
    },
)

vectorizer_config = wvcc.Configure.Vectorizer.text2vec_azure_openai(
    resource_name="NAME-GIVEN-BY-YOUR-COMPANY",
    deployment_id="text-embedding-ada-002",
    base_url="https://NAME-GIVEN-BY-YOUR-COMPANY.openai.azure.com/",
)

generative_config = wvcc.Configure.Generative.azure_openai(
    resource_name="NAME-GIVEN-BY-YOUR-COMPANY",
    deployment_id="text-embedding-ada-002",
    base_url="https://NAME-GIVEN-BY-YOUR-COMPANY.openai.azure.com/",
    top_p=0.95, 
    max_tokens=800
)

Cheers!

@c-lara this looks amazingly helpful. thanks so much for sharing.

1 Like

You’re more than welcome :slight_smile:

1 Like
questions = client.collections.create(
    name="Questions",
    vectorizer_config=wvcc.Configure.Vectorizer.text2vec_azure_openai(
        base_url= 'https://xxx.domain.com/',
        deployment_id="text-embedding-3-large",
        resource_name="xxx"
), 
    generative_config=wvcc.Configure.Generative.azure_openai(
        base_url= 'https://xxx.domain.com/',
        deployment_id="text-embedding-3-large",
        resource_name="xxx"
    )  # Ensure the `generative-openai` module is used for generative queries
)

I have set all that is needed using wvc.Configure.Vectorizer.text2vec_azure_openai I still get below error while inserting,

WeaviateInsertManyAllFailedError: Every object failed during insertion. Here is the set of all errors: connection to: Azure OpenAI API failed with status: 401

hi! Welcome to our community :hugs:

This message indicates that the apikey may be wrong.

401 - is unauthorized code.

Can you make sure the apikey is correct?

For integrating it with Azure, it might still be a bit unclear how to pass the necessary configurations.

How to set another key for azure gpt as embedding and generative, has different keys : client = weaviate.connect_to_local(
host=‘146.122.25.252’,
port=8500,
headers={
‘X-Azure-Api-Key’: azure_api_key,
‘X-Azure-Api-Key’: azure_api_key_gpt, # how to do this?
})

hi @dror-pipano_SAGCP !! Welcome to our community :hugs:

I don’t think there is this distinction on different azure keys for embedding and generative :grimacing:

That’s an interesting edge case.

Thanks.
As far as I use it in different project, it’s like that, maybe it’s relates to the way I was provided with Azure resources within my company.

definitely. It is best to have one api key that will have access to all required resources.