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" 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 weaviate, { WeaviateClient } from "weaviate-client"

let client: WeaviateClient
let response

// Instantiate your client (not shown). e.g.:
// const requestHeaders = {'X-OpenAI-Api-Key': process.env.OPENAI_APIKEY as string,}
// client = weaviate.connectToWeaviateCloud(..., headers: requestHeaders) or
// client = weaviate.connectToLocal(..., headers: requestHeaders)

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

// Perform query
response = await movies.generate.nearText("dystopian future", {
groupedTask: "What do these movies have in common?",
groupedProperties: ['title', 'overview']},
{ limit: 5 }
)

// Inspect the response
for (let item of response.objects) {
console.log('Title: ', item.properties.title) // Print the title
}

console.log(response.generated) // Print the generated text (the commonalities between them)

client.close()

Explain the code

For groupedTask queries, you simply pass on the prompt to the groupedTask 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
Looper
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 groupedProperties 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 groupedTask 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.