Weaviate Query Agent
To be notified when this agent is released, sign up here for updates.
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.
Architecture
The Query Agent is provided as a service on Weaviate Cloud.
When a user provides a prompt/query, the query agent analyses it and any other known context to autonomously carry out the searches itself.
The Query agent analyses collection and property descriptions to better understand how to construct relevant queries.
The context may also include previous conversation history, and any other relevant information.
Query Agent: visualized workflow
The Query Agent follows these high-level steps:
- Use appropriate foundation models (e.g. large language models) to analyze the task & the required queries. Determine the exact queries to perform. (Steps 1 & 2)
- Send queries to Weaviate. Weaviate vectorizes the queries as needed using the specified vectorizer integration. (Steps 3-5)
- Receive the results from Weaviate, and use appropriate foundation models to generate the final respond to the user prompt/query. (Step 6)
Then, the Query Agent returns the answer to the user, as well as intermediate outputs, such as the underlying search results from Weaviate.
Note that the term Query Agent
refers to the entire system. The Query Agent may comprise multiple subsystems, such as microservices and/or agents under the hood, each responsible for a specific task.
Usage
To be notified when this agent is released, sign up here for updates.
Prerequisites
The Query Agent is tightly integrated with Weaviate Cloud. As a result, the Query Agent is available exclusively for use with a Weaviate Cloud instance, and a supported version of the client library.
Connect to Query Agent
Provide the following to the Query Agent:
- Your Weaviate Cloud instance details (e.g. the
WeaviateClient
object in Python) to the Query Agent. - A list of the collections that the Query Agent may use to answer queries.
- Python[agents]
# [🚧 UNDER CONSTRUCTION 🚧] This Weaviate Agent is not available just yet.
# These snippets are indicative. The syntax may change when this Agent is released.
import os
import weaviate
from weaviate.classes.init import Auth
from weaviate.agents.query import QueryAgent
headers = {
# Provide your required API key(s), e.g. Cohere, OpenAI, etc. for the configured vectorizer(s)
"X-INFERENCE-PROVIDER-API-KEY": os.environ.get("YOUR_INFERENCE_PROVIDER_KEY", ""),
}
client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.environ.get("WCD_URL"),
auth_credentials=Auth.api_key(os.environ.get("WCD_API_KEY")),
headers=headers,
)
# Instantiate a new agent object, and specify the collections to query
qa = QueryAgent(
client=client, collections=["ecommerce", "financial_contracts", "weather"]
)
Queries
Provide a natural language query to the Query Agent. The Query Agent will process the query, perform the necessary searches in Weaviate, and return the answer.
This is a synchronous operation. The Query Agent will return the answer to the user as soon as it is available.
The Query Agent will formulate its strategy based on your query. So, aim to be unambiguous, complete, yet concise in your query as much as possible.
- Python[agents]
# [🚧 UNDER CONSTRUCTION 🚧] This Weaviate Agent is not available just yet.
# These snippets are indicative. The syntax may change when this Agent is released.
# Perform a query
response = qa.run(
"I like vintage clothes and and nice shoes. Recommend some of each below $60."
)
# Print the response
print(f"{response.final_answer}\n")
The Query Agent can even handle follow-up queries, using the previous response as additional context.
- Python[agents]
# [🚧 UNDER CONSTRUCTION 🚧] This Weaviate Agent is not available just yet.
# These snippets are indicative. The syntax may change when this Agent is released.
# Perform a follow-up query
following_response = qa.run(
"I like the vintage clothes options, can you do the same again but above $200?",
context=response,
)
# Print the response
print(f"{following_response.final_answer}\n")
Inspect responses
The above examples display the final answers only. The response from the Query Agent will contain additional information, such as the various search results and aggregations.
You can inspect these to verify the answer, or as the basis for further analysis. The examples below show multiple ways to inspect the response.
Summarized elements
This format may be useful for a quick overview of the response.
- Python[agents]
# [🚧 UNDER CONSTRUCTION 🚧] This Weaviate Agent is not available just yet.
# These snippets are indicative. The syntax may change when this Agent is released.
from weaviate.agents.query import QueryAgentResponse
print("\n=== Query Agent Response ===")
print(f"Original Query: {response.original_query}\n")
print("🔍 Final Answer Found:")
print(f"{response.final_answer}\n")
print("🔍 Searches Executed:")
for collection_searches in response.searches:
for result in collection_searches:
print(f"- {result}\n")
print("📊 Aggregation Results:")
for collection_aggs in response.aggregations:
for agg in collection_aggs:
print(f"- {agg}\n")
Detailed response
This example explores the response object in further detail. It includes the answer, as well as the Query Agent's feedback on whether some desired information was found or not.
- Python[agents]
# [🚧 UNDER CONSTRUCTION 🚧] This Weaviate Agent is not available just yet.
# These snippets are indicative. The syntax may change when this Agent is released.
from weaviate.agents.query import QueryAgentResponse
print("\n=== Query Agent Response ===")
print(f"Original Query: {response.original_query}\n")
if response.has_search_answer:
print("🔍 Search Answer Found:")
print(f"{response.search_answer}\n")
print("Searches Executed:")
for collection_searches in response.searches:
for result in collection_searches:
print(f"- {result}\n")
else:
print("🔍 No Searches Run \n")
if response.has_aggregation_answer:
print("📊 Aggregation Answer Found:")
print(f"{response.aggregation_answer}\n")
print("Aggregations Run:")
for collection_aggs in response.aggregations:
for agg in collection_aggs:
print(f"- {agg}\n")
else:
print("📊 No Aggregations Run")
if response.missing_information:
if response.is_partial_answer:
print("⚠️ Answer is Partial - Missing Information:")
else:
print("⚠️ Missing Information:")
for missing in response.missing_information:
print(f"- {missing}")
print("Searches Executed:")
for collection_searches in response.searches:
for result in collection_searches:
print(f"- {result}\n")
print("Aggregation Results:")
for collection_aggs in response.aggregations:
for agg in collection_aggs:
print(f"- {agg}\n")
Questions and feedback
If you have any questions or feedback, let us know in the user forum.