Skip to main content

'Grouped task' generation

A 'grouped task' generation wil perform RAG queries on the set of retrieved objects. This is useful when you want to transform the set of objects as a whole, with one prompt.


This example finds entries in "Movie" whose vector best matches the query vector (for "dystopian future"). Then, instructs the large language model to find commonalities between them.

Each of the results are then printed out to the console.

import os
import weaviate
import os

# Instantiate your client (not shown). e.g.:
# headers = {"X-OpenAI-Api-Key": os.getenv("OPENAI_APIKEY")} # Replace with your OpenAI API key
# client = weaviate.connect_to_wcs(..., headers=headers) or
# client = weaviate.connect_to_local(..., headers=headers)

# Get the collection
movies = client.collections.get("Movie")

# Perform query
response = movies.generate.near_text(
query="dystopian future",
grouped_task="What do these movies have in common?",
# grouped_properties=["title", "overview"] # Optional parameter; for reducing prompt length

# Inspect the response
for o in response.objects:
print(["title"]) # Print the title
print(response.generated) # Print the generated text (the commonalities between them)


Explain the code

For grouped_task queries, you simply pass on the prompt to the grouped_task parameter. This will instruct Weaviate to pass on the:

  • text properties from all retrieved objects, and
  • the prompt

to the large language model.

Example results
In Time
I, Robot
The Matrix
Children of Men
These movies all involve futuristic settings and explore themes related to the manipulation of time, technology, and the potential consequences of advancements in society. They also touch on issues such as inequality, control, and the impact of human actions on the future of humanity.

Optional parameters

You can also pass on a list of properties to be used, as the grouped_properties parameter. This can be useful to reduce the amount of data passed on to the large language model and omit irrelevant properties.

Response object

A RAG query with the grouped_task parameter will return a response with an additional generated attribute. This attribute will contain the generated output for the set of objects.

Questions and feedback

If you have any questions or feedback, please let us know on our forum. For example, you can: