Class instantiation
Instantiate the Query Agent against an authenticated Weaviate Cloud client. Configuration can be set at construction time (collections, system prompt, and — in Python — a request timeout) and most options can also be overridden per call to ask() or search().
Basic instantiation
Section titled “Basic instantiation”The Query Agent requires only a target Weaviate Cloud instance to be initialised. First, set up a Weaviate client:
import os
import weaviate
from weaviate.agents.query import QueryAgent
from weaviate.classes.init import Auth
headers = {import weaviate from 'weaviate-client';
import { QueryAgent } from 'weaviate-agents';
const headers = {Then pass that client to the Query Agent, and all Weaviate calls via agents will be routed through it.
qa = QueryAgent(client=client)const qa = new QueryAgent(client);Additional configuration
Section titled “Additional configuration”Parameters
Section titled “Parameters”The QueryAgent constructor accepts the following arguments:
| Parameter | Type | Description |
|---|---|---|
client | WeaviateClient | Required. The Weaviate client connected to a Weaviate Cloud cluster. |
collections | list[str | QueryAgentCollectionConfig] | Optional. The collections to query. Can be overridden per call to ask() or search(). |
system_prompt | str | Optional. Prompt to provide extra instructions to the agents, as well as define the tone, format, and style of the agent's final response. See the page on the system prompt for more detail. |
timeout | int | None | Optional. The maximum time to wait for a response, in seconds. Defaults to 60 seconds. |
The first argument is the Weaviate client. All other options are passed in a QueryAgentOptions object as the second argument.
| Parameter | Type | Description |
|---|---|---|
client | WeaviateClient | Required. The Weaviate client connected to a Weaviate Cloud cluster. |
collections | (string | QueryAgentCollectionConfig)[] | Optional. The collections to query. Can be overridden per call to ask() or search(). |
systemPrompt | string | Optional. Prompt to provide extra instructions to the agents, as well as define the tone, format, and style of the agent's final response. See the page on the system prompt for more detail. |
The TypeScript client does not currently expose a timeout option.
Collections
Section titled “Collections”You can define which collections are available either
- at the instantiation of the Query Agent base class,
qa = QueryAgent(
client=client,
collections=["FinancialContracts", "Weather"]
)const qaWithCollections = new QueryAgent(client, {
collections: ['FinancialContracts', 'Weather'],
});- or at runtime of the Query Agent's methods, either Ask Mode or Search Mode.
qa = QueryAgent(client=client)
qa.ask(
"What type of contracts have been signed and who were the authors?",
collections=["FinancialContracts", "Weather"]
)const qaWithoutCollections = new QueryAgent(client);
await qaWithoutCollections.ask(
"What type of contracts have been signed and who were the authors?", {
collections: ['FinancialContracts', 'Weather'],
});If you provide both, then the collections specified at runtime will override those specified in the base class. See the page on collection configuration for more detail.
Questions and feedback
Section titled “Questions and feedback”Have a question or feedback? Here's how to reach us.