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!

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: