Weaviate is an open-source vector search engine that allows developers to build scalable and intelligent search applications. Setting up Weaviate can be straightforward if you follow the right steps. This tutorial guides beginners through the complete setup process, from installation to running your first query.

Prerequisites

  • Basic knowledge of command-line interface (CLI)
  • Docker installed on your machine
  • Internet connection to download necessary images
  • Optional: a code editor like Visual Studio Code

Step 1: Install Docker

Ensure Docker is installed and running on your system. You can download Docker from the official website (Docker Desktop) and follow the installation instructions for your operating system.

Step 2: Pull the Weaviate Docker Image

Open your terminal or command prompt and execute the following command to download the latest Weaviate image:

docker pull semitechnologies/weaviate:latest

Step 3: Run the Weaviate Container

Start a new Weaviate container with the following command:

docker run -d -p 8080:8080 --name weaviate semitechnologies/weaviate:latest

This command runs Weaviate in detached mode, mapping port 8080 on your machine to the container.

Step 4: Verify the Setup

Check if Weaviate is running by opening your browser and navigating to:

http://localhost:8080

You should see a JSON response indicating that the server is active.

Step 5: Install the Weaviate Client

To interact with Weaviate programmatically, install the client library suitable for your programming language. For Python, run:

pip install weaviate-client

Step 6: Connect to Weaviate and Create a Schema

Use the client to connect and define your schema. Here's an example in Python:

Note: Replace your_host with localhost if running locally.

import weaviate

client = weaviate.Client("http://localhost:8080")

Define a simple schema:

schema = {
"classes": [{
"class": "Article",
"properties": [{
"name": "title",
"dataType": ["text"]
}, {
"name": "content",
"dataType": ["text"]
}]
}]
}

client.schema.create(schema)

Step 7: Add Data to Your Schema

Insert a new article:

data_object = {
"title": "The Renaissance",
"content": "The Renaissance was a fervent period of European cultural, artistic, political and economic “rebirth” following the Middle Ages."
}

client.data_object.create(data_object, "Article")

Step 8: Perform a Search Query

Query the data you added:

result = client.query.get("Article", ["title", "content"]).with_where({
"path": ["title"],
"operator": "Equal",
"valueText": "The Renaissance"
}).do()

Review the results returned from Weaviate in your console or application.

Conclusion

Setting up Weaviate involves installing Docker, running the container, and optionally integrating it with your code. Once operational, you can leverage its powerful vector search capabilities for various applications such as semantic search, recommendation systems, and more.