Skip to main content

Preparation

Create Weaviate Instance

For this unit, you will require your own instance of Weaviate.

If you do not have one, we recommend setting one up on the Weaviate Cloud (WCD). A free sandbox instance should be just fine.

Follow the "Get Started with WCD" section on this page and come back.

Access your Weaviate Instance

Now, let's make sure that you can access your Weaviate instance by following the example below.

What is your Weaviate instance address?

Make sure you know what your Weaviate instance address is - it should look like:

https://your-instance-name.weaviate.network

You can find it in your WCD dashboard.

The code to access depends on whether you have authentication turned on, or off. If you are not sure, go to your WCD dashboard and check what it says about "Authentication".

If authentication is on, you can instantiate your client as shown below.

import weaviate

client = weaviate.Client(
url="https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint
auth_client_secret=weaviate.auth.AuthApiKey(api_key="YOUR-WEAVIATE-API-KEY"), # Replace with your API Key for the Weaviate instance. Delete if authentication is disabled.
additional_headers={
"X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY",
},
)

client.is_ready() # This should return `True`

Without Authentication

If authentication is switched off in your instance, you do not need the authentication parameter.

import weaviate

client = weaviate.Client(
url="https://anon-endpoint.weaviate.network", # Replace with your Weaviate endpoint
additional_headers={
"X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY",
},
)

client.is_ready() # This should return `True`

Confirm access

Once your client is instantiated, you can confirm that you can write to your Weaviate instance by running the following code:

response = client.data_object.create({"name": "dummy"}, "TestClass")
print(response) # This should be a UUID, like "59340403-4bcd-479f-ae9c-de5da039ac0e"

You should see a long alphanumeric string printed on your screen, like "59340403-4bcd-479f-ae9c-de5da039ac0e".

If you do, you can access your Weaviate instance and have write access! Which means you are ready to move on.

Let's do one more thing before we move on, though, which is to clean up the test data that we've just created.

client.data_object.delete(response, class_name="TestClass")

We'll see you in the next section.

Review

Key takeaways

  • You need to create a Weaviate instance (e.g. on WCD) for this unit.
  • Access your Weaviate instance with API key authentication or without authentication as appropriate.
  • Confirm access to your Weaviate instance by running the provided code snippet.

Questions and feedback

If you have any questions or feedback, let us know in the user forum.