Skip to main content

Connect and verify your setup

Here, we'll perform basic operations to communicate with Weaviate using the Python client library.

Check Weaviate status

You can check whether the Weaviate instance is up and ready to use by calling the is_ready method.

# Instantiate your client (not shown). e.g.:
# client = weaviate.connect_to_weaviate_cloud(...) or
# client = weaviate.connect_to_local(...)

assert client.is_ready() # This will raise an exception if the client is not ready

Retrieve server meta information

You can retrieve meta information about the Weaviate instance using the meta function.

import json

# Instantiate your client (not shown). e.g.:
# client = weaviate.connect_to_weaviate_cloud(...) or
# client = weaviate.connect_to_local(...)

metainfo = client.get_meta()
print(json.dumps(metainfo, indent=2)) # Print the meta information in a readable format

This will print the server meta information to the console. The output will look similar to the following. The modules list reflects whichever modules your own instance has enabled, so yours will differ. The abbreviated example below shows a few of them.

Example get_meta output
{
"hostname": "http://[::]:8080",
"modules": {
"generative-anthropic": {
"documentationHref": "https://docs.anthropic.com/en/api/getting-started",
"name": "Generative Search - Anthropic"
},
"generative-cohere": {
"documentationHref": "https://docs.cohere.com/reference/chat",
"name": "Generative Search - Cohere"
},
"generative-openai": {
"documentationHref": "https://platform.openai.com/docs/api-reference/completions",
"name": "Generative Search - OpenAI"
},
"reranker-cohere": {
"documentationHref": "https://txt.cohere.com/rerank/",
"name": "Reranker - Cohere"
},
"text2vec-cohere": {
"documentationHref": "https://docs.cohere.ai/embedding-wiki/",
"name": "Cohere Module"
},
"text2vec-openai": {
"documentationHref": "https://platform.openai.com/docs/guides/embeddings/what-are-embeddings",
"name": "OpenAI Module"
}
},
"version": "1.39.0"
}

Close the connection

After you have finished using the Weaviate client, you should close the connection. This frees up resources and ensures that the connection is properly closed.

The simplest way to do this is to use the client as a context manager. Python then closes the connection for you when you leave the with block, even if an exception is raised inside it.

import weaviate
import os

# Python closes the connection when you leave the `with` block,
# even if an exception is raised inside it.
with weaviate.connect_to_weaviate_cloud(
cluster_url=os.getenv("WEAVIATE_URL"), # Replace with your Weaviate Cloud URL
auth_credentials=os.getenv("WEAVIATE_API_KEY"), # Replace with your Weaviate Cloud key
) as client:
# Work with the client here - e.g.:
assert client.is_ready()

If you need the client to stay open across a wider scope than a single with block, call client.close() yourself from a finally clause, so that it runs whether or not the code before it succeeded.

import weaviate
import os

# Instantiate your client (not shown). e.g.:
# client = weaviate.connect_to_weaviate_cloud(...) or
# client = weaviate.connect_to_local(...)

try:
# Work with the client here - e.g.:
assert client.is_ready()

finally: # This will always be executed, even if an exception is raised
client.close() # Close the connection & release resources

For brevity, the remaining code snippets in this course do not show either pattern, but remember to close your connections in your own code.

What's next?

You have confirmed that your Weaviate instance is running and connected to the Python client library. You can now proceed to the next module to populate the Weaviate instance with data.

Login to track your progress