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

Search documentation

Type to search this documentation.

On this pageOverview

Suggest Queries Mode

Weaviate Cloud only

The Query Agent can suggest queries based on the data in your collections. This is useful for helping users discover what kinds of questions they can ask, or for generating example queries for a new dataset.

The method can be called with a set of instructions and/or specifications:

Python
from weaviate.agents.query import QueryAgent
qa = QueryAgent(client=client)

response = qa.suggest_queries(
    collections=["FinancialContracts"],
    num_queries=3,
    instructions="High-level themes and open-ended exploration",
)
JavaScript/TypeScript
import weaviate from 'weaviate-client';
import { QueryAgent } from 'weaviate-agents';

Or can be called without any additional arguments, to use the defaults.

Python
qa = QueryAgent(client=client, collections=["FinancialContracts"])

qa.suggest_queries()
JavaScript/TypeScript
qa = new QueryAgent(client, {
    collections: ['FinancialContracts'],
});

await qa.suggestQueries();

Suggest Queries can be called with the following arguments:

ParameterTypeDescription
collectionslist[str | QueryAgentCollectionConfig] | NoneOverride the collections configured at instantiation. See the page on collection configuration for more detail.
num_queriesintThe number of queries to suggest (default: 3).
instructionsstr | NoneGuide the style or focus of the suggested queries. This is provided in addition to any system instructions. Useful for e.g. specifying language.
conversationlist[ChatMessage] | NoneA conversation history used to generate follow-up query suggestions.
ParameterTypeDescription
collections(string | QueryAgentCollectionConfig)[]Override the collections configured at instantiation. See the page on collection configuration for more detail.
numQueriesnumberThe number of queries to suggest (default: 3).
instructionsstringGuide the style or focus of the suggested queries. This is provided in addition to any system instructions. Useful for e.g. specifying language.
conversationChatMessage[]A conversation history used to generate follow-up query suggestions.

You can pass a conversation to Suggest Queries to generate follow-up query suggestions based on the conversation history. This is useful for guiding users toward relevant next questions after an initial exchange.

The conversation parameter accepts a list of ChatMessage objects, using the same format as multi-turn conversations.

Python
from weaviate.agents.classes import ChatMessage

# Build a conversation history
conversation = [
    ChatMessage(role="user", content="What are some popular machine learning frameworks?"),
    ChatMessage(
        role="assistant",
        content="Some popular ML frameworks include TensorFlow, PyTorch, and JAX.",
    ),
]

# Suggest follow-up queries based on the conversation context
response = qa.suggest_queries(
    conversation=conversation,
    num_queries=3,
)

for suggested_query in response.queries:
    print(suggested_query.query)
JavaScript/TypeScript
import { ChatMessage } from 'weaviate-agents';

// Build a conversation history
const suggestConversation: ChatMessage[] = [
    {
        role: 'user',
        content: 'What are some popular machine learning frameworks?',
    },
    {
        role: 'assistant',
        content: 'Some popular ML frameworks include TensorFlow, PyTorch, and JAX.',
    },
];

// Suggest follow-up queries based on the conversation context
const suggestWithConvoResponse = await qa.suggestQueries({
    conversation: suggestConversation,
    numQueries: 3,
});

for (const suggestedQuery of suggestWithConvoResponse.queries) {
    console.log(suggestedQuery.query);
}

The SuggestQueryResponse class has the following properties:

FieldTypeDescription
querieslist[SuggestedQuery]A list of SuggestedQuery objects, each with a single property query, a suggested query that the user could run against their data.
collection_countintThe number of collections that were considered when generating the suggested queries.
usageModelUnitUsageA ModelUnitUsage instance providing detail on the model units used during the run. The model_units are effectively token usage measurements normalized by cost.
total_timefloatTotal time taken (seconds).

See the client documentation for more detail.

FieldTypeDescription
queriesSuggestedQuery[]A list of SuggestedQuery objects, each with a single property query, a suggested query that the user could run against their data.
collectionCountnumberThe number of collections that were considered when generating the suggested queries.
usageModelUnitUsageA ModelUnitUsage object providing detail on the model units used during the run. The modelUnits are effectively token usage measurements normalized by cost.
totalTimenumberTotal time taken (seconds).

See the client documentation for more detail.

In Python, the above examples use the synchronous client, but Suggest Queries can also be called asynchronously. This requires the AsyncQueryAgent class (instantiated the same way as its sync counterpart) together with an async Weaviate client.

Python
import os
import weaviate
from weaviate.classes.init import Auth
from weaviate.agents.query import AsyncQueryAgent

async_client = weaviate.use_async_with_weaviate_cloud(
    cluster_url=os.environ.get("WEAVIATE_URL"),
    auth_credentials=Auth.api_key(os.environ.get("WEAVIATE_API_KEY")),
)
await async_client.connect()

async_qa = AsyncQueryAgent(client=async_client)

The .suggest_queries() method must be awaited:

Python
await async_qa.suggest_queries(
    collections=["FinancialContracts"],
    num_queries=3,
    instructions="High-level themes and open-ended exploration",
)

In JavaScript/TypeScript, the QueryAgent is asynchronous by default — the examples in the previous sections already are asynchronous, and no separate async setup is needed.

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