Option 2: Local Docker instance
Here, we will show you how to create a Weaviate instance using Docker.
Download and run the docker-compose file
Install Docker on your machine. We recommend following the official Docker installation guide.
Create a new directory and navigate to it in your terminal. Then, create a new file called docker-compose.yml and add the following content:
---
services:
weaviate:
command:
- --host
- 0.0.0.0
- --port
- '8080'
- --scheme
- http
# Replace `1.33.1` with your desired Weaviate version
image: cr.weaviate.io/semitechnologies/weaviate:1.33.1
ports:
- 8080:8080
- 50051:50051
restart: on-failure:0
volumes:
- weaviate_data:/var/lib/weaviate
environment:
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
ENABLE_API_BASED_MODULES: 'true'
BACKUP_FILESYSTEM_PATH: '/var/lib/weaviate/backups'
CLUSTER_HOSTNAME: 'node1'
volumes:
weaviate_data:
...
Create a Weaviate instance
Run the following command to start Weaviate:
docker compose up
Your Weaviate instance details
Once the instance is created, you can access it at http://localhost:8080.
Connect to your Weaviate instance
To connect to the Weaviate instance, use the connect_to_local function.
Some Weaviate modules can use inference APIs for vectorizing data or generative AI model integration. You can provide the API keys for these services to Weaviate at instantiation.
This course uses Cohere, so you can provide the Cohere API key to Weaviate through headers={"X-Cohere-Api-Key": <YOUR_KEY>}.
Putting it together, connect to Weaviate with code like this shown below:
import weaviate
import os
headers = {
"X-Cohere-Api-Key": os.getenv("COHERE_APIKEY")
} # Replace with your Cohere API key
client = weaviate.connect_to_local(headers=headers)
Use this snippet every time you connect to your Weaviate instance in this course. For brevity, this is shown as follows in the subsequent lessons:
client = weaviate.connect_to_local(...)
You are now set up with a local, Docker-based Weaviate instance to use with Python and the Weaviate Python client library. Go to the subsequent lesson to see how to connect to Weaviate and verify the connection.