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.

Code

This example finds entries in "Movie" based on their similarity to the input vector. Then, instructs the large language model to find commonalities between them.

The generated text, and 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-Cohere-Api-Key": os.getenv("COHERE_APIKEY")} # Replace with your Cohere API key
# client = weaviate.connect_to_weaviate_cloud(..., headers=headers) or
# client = weaviate.connect_to_local(..., headers=headers)

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

# Perform query
response = movies.generate.near_vector(
near_vector=query_vector,
limit=5,
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(o.properties["title"]) # Print the title
print(response.generated) # Print the generated text (the commonalities between them)

client.close()

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
Gattaca
I, Robot
Mad Max: Fury Road
The Maze Runner
These movies all take place in a futuristic or dystopian society where the characters must navigate complex systems and face challenges related to technology, society, and survival. They all explore themes of control, power, and the consequences of scientific advancements on 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, let us know in the user forum.