Skip to main content
Weaviate Docs (migrated from docs.weaviate.io) Docs

Search documentation

Type to search this documentation.

On this pageOverview

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().

The Query Agent requires only a target Weaviate Cloud instance to be initialised. First, set up a Weaviate client:

Python
import os
import weaviate
from weaviate.agents.query import QueryAgent
from weaviate.classes.init import Auth
headers = {
JavaScript/TypeScript
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.

Python
qa = QueryAgent(client=client)
JavaScript/TypeScript
const qa = new QueryAgent(client);

The QueryAgent constructor accepts the following arguments:

ParameterTypeDescription
clientWeaviateClientRequired. The Weaviate client connected to a Weaviate Cloud cluster.
collectionslist[str | QueryAgentCollectionConfig]Optional. The collections to query. Can be overridden per call to ask() or search().
system_promptstrOptional. 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.
timeoutint | NoneOptional. 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.

ParameterTypeDescription
clientWeaviateClientRequired. 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().
systemPromptstringOptional. 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.

You can define which collections are available either

  • at the instantiation of the Query Agent base class,
Python
qa = QueryAgent(
    client=client,
    collections=["FinancialContracts", "Weather"]
)
JavaScript/TypeScript
const qaWithCollections = new QueryAgent(client, {
    collections: ['FinancialContracts', 'Weather'],
});
  • or at runtime of the Query Agent's methods, either Ask Mode or Search Mode.
Python
qa = QueryAgent(client=client)

qa.ask(
    "What type of contracts have been signed and who were the authors?", 
    collections=["FinancialContracts", "Weather"]
)
JavaScript/TypeScript
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.

Have a question or feedback? Here's how to reach us.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu