diff --git a/docs/query-agent/_includes/code/suggest_queries.mts b/docs/query-agent/_includes/code/suggest_queries.mts index eaec99af..29dfadd7 100644 --- a/docs/query-agent/_includes/code/suggest_queries.mts +++ b/docs/query-agent/_includes/code/suggest_queries.mts @@ -41,4 +41,30 @@ for (const suggestedQuery of response.queries) { } // END AccessResponse +// START SuggestQueriesWithConversation +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); +} +// END SuggestQueriesWithConversation + await client.close(); diff --git a/docs/query-agent/_includes/code/suggest_queries.py b/docs/query-agent/_includes/code/suggest_queries.py index 518a3303..f9dfa4f2 100644 --- a/docs/query-agent/_includes/code/suggest_queries.py +++ b/docs/query-agent/_includes/code/suggest_queries.py @@ -29,6 +29,28 @@ print(suggested_query.query) # END AccessResponse +# START SuggestQueriesWithConversation +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) +# END SuggestQueriesWithConversation + """ # START AsyncInstantiation import os diff --git a/docs/query-agent/guides/suggest_queries.md b/docs/query-agent/guides/suggest_queries.md index 72d26e66..ecdba6a3 100644 --- a/docs/query-agent/guides/suggest_queries.md +++ b/docs/query-agent/guides/suggest_queries.md @@ -70,6 +70,7 @@ Suggest Queries can be called with the following arguments: | `collections` | `list[str \| QueryAgentCollectionConfig] \| None` | Override the collections configured at instantiation. [See the page on collection configuration for more detail](../reference/advanced_collections.md). | | `num_queries` | `int` | The number of queries to suggest (default: `3`). | | `instructions` | `str \| None` | Guide the style or focus of the suggested queries. This is provided in addition to any system instructions. Useful for e.g. specifying language. | +| `conversation` | `list[ChatMessage] \| None` | A conversation history used to generate follow-up query suggestions. | @@ -78,6 +79,32 @@ Suggest Queries can be called with the following arguments: | `collections` | `(string \| QueryAgentCollectionConfig)[]` | Override the collections configured at instantiation. [See the page on collection configuration for more detail](../reference/advanced_collections.md). | | `numQueries` | `number` | The number of queries to suggest (default: `3`). | | `instructions` | `string` | Guide the style or focus of the suggested queries. This is provided in addition to any system instructions. Useful for e.g. specifying language. | +| `conversation` | `ChatMessage[]` | A conversation history used to generate follow-up query suggestions. | + + + +### Follow-up queries + +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](../reference/multi_turn_conversations.md). + + + + + + +