How to get a basic Azure OpenAI collection queryable?

Description

Hi. I want to get a minimal working example of a collection in WCS that relies on Azure-OpenAI rather than core OpenAI, and is queryable using the coll.query.near_text('my query') method, using the Weaviate client library V4 for Python 3. I’ve tried various configurations but am failing with various errors, most recently.

Query call with protocol GRPC search failed with message explorer: get class: vectorize params: vectorize params: vectorize params: vectorize keywords: remote client vectorize: connection to: Azure OpenAI API failed with status: 404 error: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again..

This is my workflow:

client = wv.connect_to_wcs(
    cluster_url = os.getenv('WEAVIATE_SANDBOX_URL'),
    auth_credentials=wv.auth.AuthApiKey(api_key=os.getenv('WEAVIATE_SANDBOX_API_KEY')),
    headers = {
        "X-Azure-Api-Key": os.getenv('AZURE_OPENAI_API_KEY'),
        "X-OpenAI-BaseURL": os.getenv('AZURE_OPENAI_API_BASE'),
    },
)

VECTORIZER_CONFIG = wc.Configure.Vectorizer.text2vec_azure_openai(
    resource_name="text-embedding-ada-002",
    deployment_id=os.getenv('AZURE_OPENAI_EMBEDDINGS'),
    base_url=os.getenv('AZURE_OPENAI_API_BASE'),
)

GENERATIVE_CONFIG = wc.Configure.Generative.azure_openai(
    resource_name="gpt-4",
    deployment_id=os.getenv('AZURE_OPENAI_GENERATIVE_DEPLOYMENT'),
    base_url=os.getenv('AZURE_OPENAI_API_BASE'),
    top_p=0.95, 
    max_tokens=800
)

I then have some basic code to stream in data from a pandas dataframe into a weaviate collection, which translates pandas data types to weaviate data types, and uses the above constants as the vectorizer and generative config for our new collection.

with coll.batch.fixed_size(
    batch_size=self.weaviate_batch_size
) as batch:
    for i, row in df.iterrows():
        batch.add_object(
            properties=row.to_dict(),
            uuid=generate_uuid5(row.index)
        )

My theory is that I’ve wrongly defined the API key, deployment or model names somewhere, but it’s not clear to me where I’d find them. I’ve followed the instructions from this post, but that didn’t work. Then I ended up at my current configuration.

Server Setup Information

  • Weaviate Server Version: 1.24.13
  • Deployment Method: WCS
  • Multi Node? Number of Running Nodes: 1 – just a sandbox cluster to figure out how to build this
  • Client Language and Version: Python 3.11.3, Weaviate 4.6.1

Any additional Information

This is a screenshot of my Azure deployments. The names match my environment variables.

Hi @nik !

I was finally able to set my azure open ai again :slight_smile:

Thanks for joining our office hours!

This is how I got it working:

so resource_name is the resource under Azure Ai Services:

Now inside that duda-instance, I have two deployments. That I get to see the UI when clicking on Manage Models:

Also, inside the duda-instance I can get the API KEY and Endpoint:

And this is the code I got it tested with:

headers = {
    "X-Azure-Api-Key": "ed...asas",
}
client = weaviate.connect_to_wcs(
    cluster_url="https://duda-test-wt38ff5b.weaviate.network",
    auth_credentials=weaviate.auth.AuthApiKey("P.....kj"),
    headers=headers
)

client.collections.delete("Test")
col = client.collections.create(
    "Test",
vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_azure_openai(
        resource_name="duda-instance",
        deployment_id="my-openai-small",
        #model="text-embedding-3-small",
        base_url="https://duda-instance.openai.azure.com/",
    ),
    generative_config=wvc.config.Configure.Generative.azure_openai(
        resource_name="duda-instance",
        deployment_id="my-gpt3-openai",
        #model="gpt-35-turbo",
        base_url="https://duda-instance.openai.azure.com/"
    ),
    properties=[
        wvc.config.Property(name="text", data_type=wvc.config.DataType.TEXT)
    ]
)

Let me know if this helps :slight_smile:

@DudaNogueira - thank you so much. I’ve tested this extensively, and it’s totally worked. Looking forward to further exploring weaviate!

1 Like

Awesome!

Glad to hear that!

If you face any issues, we are here to help :slight_smile:

Enjoy the journey :wink: