Quickstart: With Cloud resources
Weaviate is an open-source vector database built to power AI applications. This quickstart guide will show you how to:
- Set up a collection - Create a collection and import data into it.
- Search - Perform a similarity (vector) search on your data.
- RAG - Perform Retrieval Augmented Generation (RAG) with a generative model.
- Query Agent - Get answers from you data by using a natural language prompt/question.
Cloud only
If you encounter any issues along the way or have additional questions, use the feature.
Prerequisites
A Weaviate Cloud Sandbox instance - you will need an admin API key and a REST endpoint URL to connect to your instance. See the instructions below for more info. If you don't want to use Weaviate Cloud, check out the Local Quickstart with Docker.
How to set up a Weaviate Cloud Sandbox instance
Go to the Weaviate Cloud console and create a free Sandbox instance as shown in the interactive example below.
- Cluster provisioning typically takes 1-3 minutes.
- When the cluster is ready, Weaviate Cloud displays a checkmark (
✔️) next to the cluster name. - Note that Weaviate Cloud adds a random suffix to sandbox cluster names to ensure uniqueness.
How to retrieve Weaviate Cloud credentials (WEAVIATE_API_KEY and WEAVIATE_URL)
After you create a Weaviate Cloud instance, you will need the:
- REST Endpoint URL and the
- Administrator API Key.
You can retrieve them both from the WCD console as shown in the interactive example below.
Weaviate supports both REST and gRPC protocols. For Weaviate Cloud deployments, you only need to provide the REST endpoint URL - the client will automatically configure gRPC.
Once you have the REST Endpoint URL and the admin API key, you can connect to the Sandbox instance, and work with Weaviate.
Install a client library
Follow the instructions below to install one of the official client libraries, available in Python, JavaScript/TypeScript, Go, and Java.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
pip install -U weaviate-client[agents]
Step 1: Create a collection & import data
There are two paths you can choose from when importing data:
(recommended)
Import objects and vectorize them with the Weaviate Embeddings service.
Import pre-computed vector embeddings along with your data.
The following example creates a collection called Movie. The data will be vectorized with the Weaviate EmbeddingsWeaviate Embeddings is a managed embedding inference service for Weaviate Cloud users (embedding model provider). It generates vector embeddings for your data and queries directly from a Weaviate Cloud database instance. model provider. You are also free to use any other available embedding model provider.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import weaviate
from weaviate.classes.config import Configure
import os
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
# Step 1.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
) as client:
# Step 1.2: Create a collection
movies = client.collections.create(
name="Movie",
vector_config=Configure.Vectors.text2vec_weaviate(), # Configure the Weaviate Embeddings vectorizer
)
# Step 1.3: Import three objects
data_objects = [
{"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"},
{"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"},
{"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"},
]
movies = client.collections.use("Movie")
with movies.batch.fixed_size(batch_size=200) as batch:
for obj in data_objects:
batch.add_object(properties=obj)
print(f"Imported & vectorized {len(movies)} objects into the Movie collection")
The following example creates a collection called Movie. The data should already contain the pre-computed vector embeddingsVector embeddings generated by an embedding model (from a provider like OpenAI, Anthropic, etc.).. This option is useful for when you are migrating data from a different vector database.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import weaviate
from weaviate.classes.config import Configure
import os
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
# Step 1.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
) as client:
# Step 1.2: Create a collection
movies = client.collections.create(
name="Movie",
vector_config=Configure.Vectors.self_provided(), # No automatic vectorization since we're providing vectors
)
# Step 1.3: Import three objects
data_objects = [
{"properties": {"title": "The Matrix", "description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers.", "genre": "Science Fiction"},
"vector": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]},
{"properties": {"title": "Spirited Away", "description": "A young girl becomes trapped in a mysterious world of spirits and must find a way to save her parents and return home.", "genre": "Animation"},
"vector": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]},
{"properties": {"title": "The Lord of the Rings: The Fellowship of the Ring", "description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth.", "genre": "Fantasy"},
"vector": [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]}
]
# Insert the objects with vectors
movies = client.collections.get("Movie")
with movies.batch.fixed_size(batch_size=200) as batch:
for obj in data_objects:
batch.add_object(properties=obj["properties"], vector=obj["vector"])
print(
f"Imported {len(data_objects)} objects with vectors into the Movie collection"
)
Step 2: Semantic (vector) search
Semantic search finds results based on meaning. This is called nearText in Weaviate. The following example searches for 2 objects (limit) whose meaning is most similar to that of sci-fi.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import weaviate
import os, json
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
# Step 2.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
) as client:
# Step 2.2: Use this collection
movies = client.collections.use("Movie")
# Step 2.3: Perform a semantic search with NearText
response = movies.query.near_text(
query="sci-fi",
limit=2
)
for obj in response.objects:
print(json.dumps(obj.properties, indent=2)) # Inspect the results
Semantic search finds results based on meaning. This is called nearVector in Weaviate. The following example searches for 2 objects (limit) whose vector is most similar to the query vector.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import weaviate
import os, json
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
# Step 2.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
) as client:
# Step 2.2: Use this collection
movies = client.collections.use("Movie")
# Step 2.3: Perform a vector search with NearVector
response = movies.query.near_vector(
near_vector=[0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81],
limit=2
)
for obj in response.objects:
print(json.dumps(obj.properties, indent=2)) # Inspect the results
Example response
{
"genre": "Science Fiction",
"title": "The Matrix",
"description": "A computer hacker learns about the true nature of reality and his role in the war against its controllers."
}
{
"genre": "Fantasy",
"title": "The Lord of the Rings: The Fellowship of the Ring",
"description": "A meek Hobbit and his companions set out on a perilous journey to destroy a powerful ring and save Middle-earth."
}
Step 3: Retrieval augmented generation (RAG)
For Retrieval Augmented Generation (RAG) in this step, you will need a Claude API key. You can also use another generative model provider instead.
Retrieval augmented generation (RAG), also called generative search, works by prompting a large language model (LLM) with a combination of a user query and data retrieved from a database.
The following example combines the semantic search for the query sci-fi with a prompt to generate a tweet using the Anthropic generative model (generative-anthropic).
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import os
import weaviate
from weaviate.classes.generate import GenerativeConfig
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
anthropic_api_key = os.environ["ANTHROPIC_API_KEY"]
# Step 2.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
headers={"X-Anthropic-Api-Key": anthropic_api_key},
) as client:
# Step 2.2: Use this collection
movies = client.collections.use("Movie")
# Step 2.3: Perform RAG with on NearText results
response = movies.generate.near_text(
query="sci-fi",
limit=1,
grouped_task="Write a tweet with emojis about this movie.",
generative_provider=GenerativeConfig.anthropic(
model="claude-3-5-haiku-latest"
), # Configure the Anthropic generative integration for RAG
)
print(response.generative.text) # Inspect the results
Retrieval augmented generation (RAG), also called generative search, works by prompting a large language model (LLM) with a combination of a user query and data retrieved from a database.
The following example combines the vector similarity search with a prompt to generate a tweet using the Anthropic generative model (generative-anthropic).
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import os
import weaviate
from weaviate.classes.generate import GenerativeConfig
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
anthropic_api_key = os.environ["ANTHROPIC_API_KEY"]
# Step 2.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
headers={"X-Anthropic-Api-Key": anthropic_api_key},
) as client:
# Step 2.2: Use this collection
movies = client.collections.use("Movie")
# Step 2.3: Perform RAG with on NearVector results
response = movies.generate.near_vector(
near_vector=[0.11, 0.21, 0.31, 0.41, 0.51, 0.61, 0.71, 0.81],
limit=1,
grouped_task="Write a tweet with emojis about this movie.",
generative_provider=GenerativeConfig.anthropic(
model="claude-3-5-haiku-latest"
), # Configure the Anthropic generative integration for RAG
)
print(response.generative.text) # Inspect the results
Example response
🕶️ Unplug from the system & join Neo's journey 💊🐰
"The Matrix" will blow your mind 🤯 as reality unravels 🌀
Kung-fu, slow-mo & mind-bending sci-fi 🥋🕴️
Are you ready to see how deep the rabbit hole goes? 🔴🔵 #TheMatrix #WakeUp
Step 4: Query Agent
The Weaviate Query Agent is a pre-built agentic service designed to answer natural language queries based on the data stored in Weaviate Cloud. The user simply provides a prompt/question in natural language, and the Query Agent takes care of all intervening steps to provide an answer.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import os
import weaviate
from weaviate.agents.query import QueryAgent
# Best practice: store your credentials in environment variables
weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
# Step 2.1: Connect to your Weaviate Cloud instance
with weaviate.connect_to_weaviate_cloud(
cluster_url=weaviate_url,
auth_credentials=weaviate_api_key,
) as client:
# Step 2.2: Instantiate a new agent object
qa = QueryAgent(client=client, collections=["Movie"])
# Step 2.3: Perform a query using Search Mode
response = qa.search("Find a cool sci-fi movie.", limit=1)
# Print the response
for obj in response.search_results.objects:
print(f"Movie: {obj.properties['title']} - {obj.properties['description']}")
Here is the printed response:
Movie: The Matrix - A computer hacker learns about the true nature of reality and his role in the war against its controllers.
Next steps
We recommend you check out the following resources to continue learning about Weaviate.
Continue with the Quick tour tutorial – an end-to-end guide that covers important topics like configuring collections, searches, etc.
Check out Weaviate Academy – a learning platform centered around AI-native development.
Quick examples of how to configure, manage and query Weaviate using client libraries.
Guides and tips for new users learning how to use Weaviate.
Questions and feedback
If you have any questions or feedback, let us know in the user forum.
