Retrieval Augmented Generation (RAG) combines information retrieval with generative AI models.

In Weaviate, a RAG query consists of two parts: _a search query_, and a _prompt for the model_. Weaviate first performs the search, then passes both the search results and your prompt to a generative AI model before returning the generated response.

:::callout{intent="tip" title="Prefer natural language queries?"}
The [Query Agent](query-agent.md) translates plain English questions into optimized Weaviate queries automatically - no manual query construction needed.
Cloud only
:::

## Configure a generative model provider

:::callout{intent="info" title="Added in `v1.30`"}
:::

To use RAG with a [generative model integration](../model-provider-integrations/index.md):

- [set a default configuration for the collection](../how-to-manage-collections/generative-reranker-models.md#specify-a-generative-model-integration) and/or
- provide the settings as a part of the query:

:::code-group{sync="languages"}
```python title="Python" {11}
from weaviate.classes.generate import GenerativeConfig
from weaviate.classes.query import MetadataQuery

reviews = client.collections.use("WineReviewNV")
response = reviews.generate.near_text(
    query="a sweet German white wine",
    limit=2,
    target_vector="title_country",
    single_prompt="Translate this into German: {review_body}",
    grouped_task="Summarize these review",
    generative_provider=GenerativeConfig.openai(),
)

for o in response.objects:
    print(f"Properties: {o.properties}")
    print(f"Single prompt result: {o.generative.text}")
print(f"Grouped task result: {response.generative.text}")
```

```typescript title="JavaScript/TypeScript"
import { generativeParameters } from 'weaviate-client';
```

```go title="Go"
// Go support coming soon
```

```java title="Java"
CollectionHandle<Map<String, Object>> reviews =
    client.collections.use("WineReviewNV");
var response = reviews.generate.nearText(
    Target.text("title_country", "a sweet German white wine"),
    q -> q.limit(2),
    g -> g.singlePrompt("Translate this into German: {review_body}")
        .groupedTask("Summarize these reviews", c -> c.generativeProvider(
            GenerativeProvider.openai(o -> o.temperature(1f))))
// highlight-start
// highlight-end
);

for (var o : response.objects()) {
  System.out.printf("Properties: %s\n", o.properties());
  System.out.printf("Single prompt result: %s\n", o.generative().text());
}
System.out.printf("Grouped task result: %s\n",
    response.generative().text());
```

```csharp title="C#" {7}
var reviews = client.Collections.Use("WineReviewNV");
var response = await reviews.Generate.NearText(
    query => query("a sweet German white wine").TargetVectorsMinimum("title_country"),
    limit: 2,
    provider: new Providers.OpenAI { Model = "gpt-5-mini" },
    singlePrompt: new SinglePrompt("Translate this into German: {review_body}"),
    groupedTask: new GroupedTask("Summarize these reviews")
);

foreach (var o in response.Objects)
{
    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");
    Console.WriteLine($"Single prompt result: {o.Generative?.Values.First()}");
}
Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
```
:::

:::accordion{title="Example response"}
```
Properties: {'country': 'Austria', 'title': 'Gebeshuber 2013 Frizzante Rosé Pinot Noir (Österreichischer Perlwein)', 'review_body': "With notions of cherry and cinnamon on the nose and just slight fizz, this is a refreshing, fruit-driven sparkling rosé that's full of strawberry and cherry notes—it might just be the very definition of easy summer wine. It ends dry, yet refreshing.", 'points': 85, 'price': 21.0}

Single prompt result: Mit Noten von Kirsche und Zimt in der Nase und nur leicht prickelnd, ist dies ein erfrischender, fruchtiger sprudelnder Rosé, der voller Erdbeer- und Kirschnoten steckt - es könnte genau die Definition von leichtem Sommerwein sein. Er endet trocken, aber erfrischend.

Properties: {'price': 27.0, 'points': 89, 'review_body': 'Beautifully perfumed, with acidity, white fruits and a mineral context. The wine is layered with citrus and lime, hints of fresh pineapple acidity. Screw cap.', 'title': 'Stadt Krems 2009 Steinterrassen Riesling (Kremstal)', 'country': 'Austria'}

Single prompt result: Wunderschön parfümiert, mit Säure, weißen Früchten und einem mineralischen Kontext. Der Wein ist mit Zitrus- und Limettennoten durchzogen, mit Anklängen von frischer Ananas-Säure. Schraubverschluss.

Grouped task result: The first review is for the Gebeshuber 2013 Frizzante Rosé Pinot Noir from Austria, describing it as a refreshing and fruit-driven sparkling rosé with cherry and cinnamon notes. It is said to be the perfect easy summer wine, ending dry yet refreshing.

The second review is for the Stadt Krems 2009 Steinterrassen Riesling from Austria, noting its beautiful perfume, acidity, white fruits, and mineral context. The wine is described as layered with citrus and lime flavors, with hints of fresh pineapple acidity. It is sealed with a screw cap.
```
:::

:::callout{intent="tip"}
For more information on the available models and their additional options, see the [model providers section](../model-provider-integrations/index.md).
:::

## Named vectors

Any vector-based search on collections with [named vectors](../reference-configuration/collections.md#multiple-vector-embeddings-named-vectors) configured must include a `target` vector name in the query. This allows Weaviate to find the correct vector to compare with the query vector.

:::code-group{sync="languages"}
```python title="Python" {7-9}
from weaviate.classes.query import MetadataQuery

reviews = client.collections.use("WineReviewNV")
response = reviews.generate.near_text(
    query="a sweet German white wine",
    limit=2,
    target_vector="title_country",  # Specify the target vector for named vector collections
    single_prompt="Translate this into German: {review_body}",
    grouped_task="Summarize these review",
    return_metadata=MetadataQuery(distance=True),
)

for o in response.objects:
    print(f"Properties: {o.properties}")
    print(f"Single prompt result: {o.generative.text}")
print(f"Grouped task result: {response.generative.text}")
```

```typescript title="JavaScript/TypeScript" {8}
const myNVCollection = client.collections.use('WineReviewNV');

const result = await myNVCollection.generate.nearText('a sweet German white wine', {
  singlePrompt: 'Translate this into German: {review_body}',
  groupedTask: 'Summarize these review',
}, {
  limit: 2,
  targetVector: 'title_country',
}
);

console.log(result.generative?.text); // print groupedTask result

for (let object of result.objects) {
  console.log(JSON.stringify(object.properties, null, 2));
  console.log(object.generative?.text); // print singlePrompt result
}
```

```java title="Java" {6-9}
CollectionHandle<Map<String, Object>> reviews =
    client.collections.use("WineReviewNV");
var response = reviews.generate.nearText(
    Target.text("title_country", "a sweet German white wine"),
    q -> q.limit(2)
        // .targetVector("title_country") // Specify the target vector for named vector collections
        .returnMetadata(Metadata.DISTANCE),
    g -> g.singlePrompt("Translate this into German: {review_body}")
        .groupedTask("Summarize these reviews")
);

for (var o : response.objects()) {
  System.out.printf("Properties: %s\n", o.properties());
  System.out.printf("Single prompt result: %s\n", o.generative().text());
}
System.out.printf("Grouped task result: %s\n",
    response.generative().text());
```

```csharp title="C#" {5-7}
var reviews = client.Collections.Use("WineReviewNV");
var response = await reviews.Generate.NearText(
    query => query("a sweet German white wine").TargetVectorsMinimum("title_country"),
    limit: 2,
    returnMetadata: MetadataOptions.Distance,
    singlePrompt: new SinglePrompt("Translate this into German: {review_body}"),
    groupedTask: new GroupedTask("Summarize these reviews")
);

foreach (var o in response.Objects)
{
    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");
    Console.WriteLine($"Single prompt result: {o.Generative?.Values.First()}");
}
Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
```

```graphql title="GraphQL" {8-12}
{
  Get {
    JeopardyQuestion(
      limit: 2
      nearText: {
        concepts: ["animals in movies"]
      }
      where: {
        path: ["round"]
        operator: Equal
        valueText: "Double Jeopardy!"
      }
    ) {
      question
      answer
      _additional {
        generate(
          singleResult: {
            prompt: """
              Translate this into German: {review_body}
            """
          }
          groupedResult: {
            task: """
              Summarize these reviews
            """
          }
        ) {
          singleResult
          error
        }
      }
    }
  }
}
```
:::

:::accordion{title="Example response"}
```
Properties: {'country': 'Austria', 'title': 'Gebeshuber 2013 Frizzante Rosé Pinot Noir (Österreichischer Perlwein)', 'review_body': "With notions of cherry and cinnamon on the nose and just slight fizz, this is a refreshing, fruit-driven sparkling rosé that's full of strawberry and cherry notes—it might just be the very definition of easy summer wine. It ends dry, yet refreshing.", 'points': 85, 'price': 21.0}

Single prompt result: Mit Noten von Kirsche und Zimt in der Nase und nur leicht prickelnd, ist dies ein erfrischender, fruchtiger sprudelnder Rosé, der voller Erdbeer- und Kirschnoten steckt - es könnte genau die Definition von leichtem Sommerwein sein. Er endet trocken, aber erfrischend.

Properties: {'price': 27.0, 'points': 89, 'review_body': 'Beautifully perfumed, with acidity, white fruits and a mineral context. The wine is layered with citrus and lime, hints of fresh pineapple acidity. Screw cap.', 'title': 'Stadt Krems 2009 Steinterrassen Riesling (Kremstal)', 'country': 'Austria'}

Single prompt result: Wunderschön parfümiert, mit Säure, weißen Früchten und einem mineralischen Kontext. Der Wein ist mit Zitrus- und Limettennoten durchzogen, mit Anklängen von frischer Ananas-Säure. Schraubverschluss.

Grouped task result: The first review is for the Gebeshuber 2013 Frizzante Rosé Pinot Noir from Austria, describing it as a refreshing and fruit-driven sparkling rosé with cherry and cinnamon notes. It is said to be the perfect easy summer wine, ending dry yet refreshing.

The second review is for the Stadt Krems 2009 Steinterrassen Riesling from Austria, noting its beautiful perfume, acidity, white fruits, and mineral context. The wine is described as layered with citrus and lime flavors, with hints of fresh pineapple acidity. It is sealed with a screw cap.
```
:::

## Single prompt search

Single prompt search returns a generated response for each object in the query results.

Define object `properties` with the `{prop-name}` syntax to interpolate retrieved content in the prompt.

The properties you use in the prompt do not have to be among the properties you retrieve in the query.

:::code-group{sync="languages"}
```python title="Python" {1-3}
prompt = (
    "Convert this quiz question: {question} and answer: {answer} into a trivia tweet."
)

jeopardy = client.collections.use("JeopardyQuestion")
response = jeopardy.generate.near_text(
    query="World history", limit=2, single_prompt=prompt
)

# print source properties and generated responses
for o in response.objects:
    print(f"Properties: {o.properties}")
    print(f"Single prompt result: {o.generative.text}")
```

```typescript title="JavaScript/TypeScript"
let response;
const jeopardy = client.collections.use('JeopardyQuestion');
```

```go title="Go"
generatePrompt := "Convert this quiz question: {question} and answer: {answer} into a trivia tweet."

gs := graphql.NewGenerativeSearch().SingleResult(generatePrompt)

response, err := client.GraphQL().Get().
  WithClassName("JeopardyQuestion").
  WithFields(
    graphql.Field{Name: "question"},
    graphql.Field{Name: "answer"},
  ).
  WithGenerativeSearch(gs).
  WithNearText((&graphql.NearTextArgumentBuilder{}).
    WithConcepts([]string{"World history"})).
  WithLimit(2).
  Do(ctx)
```

```java title="Java" {1-2}
String prompt =
    "Convert this quiz question: {question} and answer: {answer} into a trivia tweet.";

CollectionHandle<Map<String, Object>> jeopardy =
    client.collections.use("JeopardyQuestion");
var response = jeopardy.generate.nearText("World history", q -> q.limit(2),
    g -> g.singlePrompt(prompt));

// print source properties and generated responses
for (var o : response.objects()) {
  System.out.printf("Properties: %s\n", o.properties());
  System.out.printf("Single prompt result: %s\n", o.generative().text());
}
```

```csharp title="C#" {1-2}
var prompt =
    "Convert this quiz question: {question} and answer: {answer} into a trivia tweet.";

var jeopardy = client.Collections.Use("JeopardyQuestion");
var response = await jeopardy.Generate.NearText(
    "World history",
    limit: 2,
    singlePrompt: new SinglePrompt(prompt)
);

// print source properties and generated responses
foreach (var o in response.Objects)
{
    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");
    Console.WriteLine($"Single prompt result: {o.Generative?.Values.First()}");
}
```

```graphql title="GraphQL"
{
  Get {
    JeopardyQuestion (
      nearText: {
        concepts: ["World history"]
      }
      limit: 2
    ) {
      _additional {
        generate(
          singleResult: {
            prompt: """
              Convert this quiz question: {question} and answer: {answer} into a trivia tweet.
            """
          }
        ) {
          singleResult
          error
        }
      }
    }
  }
}
```
:::

:::accordion{title="Example response"}
```
Property 'question': Including, in 19th century, one quarter of world's land & people, the sun never set on it
Single prompt result: Did you know that in the 19th century, one quarter of the world's land and people were part of an empire where the sun never set? ☀️🌍 #historybuffs #funfact

Property 'question': From Menes to the Ptolemys, this country had more kings than any other in ancient history
Single prompt result: Which country in ancient history had more kings than any other, from Menes to the Ptolemys? 👑🏛️ #historybuffs #ancientkings
```
:::

### Additional parameters

:::callout{intent="info" title="Added in `v1.30`"}
:::

You can use _generative parameters_ to specify additional options when performing a single prompt search:

:::code-group{sync="languages"}
```python title="Python" {1-7,13}
from weaviate.classes.generate import GenerativeConfig, GenerativeParameters

prompt = GenerativeParameters.single_prompt(
    prompt="Convert this quiz question: {question} and answer: {answer} into a trivia tweet.",
    metadata=True,
    debug=True,
)

jeopardy = client.collections.use("JeopardyQuestion")
response = jeopardy.generate.near_text(
    query="World history",
    limit=2,
    single_prompt=prompt,
    generative_provider=GenerativeConfig.openai()
)

# print source properties and generated responses
for o in response.objects:
    print(f"Properties: {o.properties}")
    print(f"Single prompt result: {o.generative.text}")
    print(f"Debug: {o.generative.debug}")
    print(f"Metadata: {o.generative.metadata}")
```

```typescript title="JavaScript/TypeScript"
import { generativeParameters } from 'weaviate-client';
```

```go title="Go"
// Go support coming soon
```

```java title="Java" {4-10}
CollectionHandle<Map<String, Object>> jeopardy =
    client.collections.use("JeopardyQuestion");
var response = jeopardy.generate.nearText("World history", q -> q.limit(2),
    g -> g.singlePrompt(
        "Convert this quiz question: {question} and answer: {answer} into a trivia tweet.",
        c -> c
            .generativeProvider(
                GenerativeProvider.openai(d -> d.baseUrl(null)))
            .debug(true)
            .metadata(true)
    ));

// print source properties and generated responses
for (var o : response.objects()) {
  System.out.printf("Properties: %s\n", o.properties());
  System.out.printf("Single prompt result: %s\n", o.generative().text());
  System.out.printf("Debug: %s\n", o.generative().debug());
  System.out.printf("Metadata: %s\n", o.generative().metadata());
}
```

```csharp title="C#" {1-7,13}
var singlePrompt = new SinglePrompt(
    "Convert this quiz question: {question} and answer: {answer} into a trivia tweet."
)
{
    // Metadata = true,
    Debug = true,
};

var jeopardy = client.Collections.Use("JeopardyQuestion");
var response = await jeopardy.Generate.NearText(
    "World history",
    limit: 2,
    singlePrompt: singlePrompt
// provider: new GenerativeProvider.OpenAI()
);

// print source properties and generated responses
foreach (var o in response.Objects)
{
    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");
    Console.WriteLine($"Single prompt result: {o.Generative?.Values.First()}");
    //Console.WriteLine($"Debug: {o.Generative?}");
    //Console.WriteLine($"Metadata: {JsonSerializer.Serialize(o.Generative?.Metadata)}");
}
```
:::

:::accordion{title="Example response"}
```
Properties: {'points': 400, 'answer': 'the British Empire', 'air_date': datetime.datetime(1984, 12, 10, 0, 0, tzinfo=datetime.timezone.utc), 'question': "Including, in 19th century, one quarter of world's land & people, the sun never set on it", 'round': 'Double Jeopardy!'}

Single prompt result: Did you know that in the 19th century, the sun never set on the British Empire, which included one quarter of the world's land and people? #triviatuesday #britishempire

Debug: full_prompt: "Convert this quiz question: Including, in 19th century, one quarter of world\'s land & people, the sun never set on it and answer: the British Empire into a trivia tweet."

Metadata: usage {
  prompt_tokens: 46
  completion_tokens: 43
  total_tokens: 89
}

Properties: {'points': 400, 'answer': 'Egypt', 'air_date': datetime.datetime(1989, 9, 5, 0, 0, tzinfo=datetime.timezone.utc), 'question': 'From Menes to the Ptolemys, this country had more kings than any other in ancient history', 'round': 'Double Jeopardy!'}

Single prompt result: Did you know that Egypt had more kings than any other country in ancient history, from Menes to the Ptolemys? #triviathursday #ancienthistory

Debug: full_prompt: "Convert this quiz question: From Menes to the Ptolemys, this country had more kings than any other in ancient history and answer: Egypt into a trivia tweet."

Metadata: usage {
  prompt_tokens: 42
  completion_tokens: 36
  total_tokens: 78
}
```
:::

## Grouped task search

Grouped task search returns one response that includes all of the query results. By default grouped task search uses all object `properties` in the prompt.

:::code-group{sync="languages"}
```python title="Python" {1,7}
task = "What do these animals have in common, if anything?"

jeopardy = client.collections.use("JeopardyQuestion")
response = jeopardy.generate.near_text(
    query="Cute animals",
    limit=3,
    grouped_task=task,
)

# print the generated response
print(f"Grouped task result: {response.generative.text}")
```

```typescript title="JavaScript/TypeScript"
let response;
const jeopardy = client.collections.use('JeopardyQuestion');
```

```go title="Go"
generatePrompt := "What do these animals have in common, if anything?"

gs := graphql.NewGenerativeSearch().GroupedResult(generatePrompt)

response, err := client.GraphQL().Get().
  WithClassName("JeopardyQuestion").
  WithFields(
    graphql.Field{Name: "points"},
  ).
  WithGenerativeSearch(gs).
  WithNearText((&graphql.NearTextArgumentBuilder{}).
    WithConcepts([]string{"Cute animals"})).
  WithLimit(3).
  Do(ctx)
```

```java title="Java" {1,6}
String task = "What do these animals have in common, if anything?";

CollectionHandle<Map<String, Object>> jeopardy =
    client.collections.use("JeopardyQuestion");
var response = jeopardy.generate.nearText("Cute animals", q -> q.limit(3),
    g -> g.groupedTask(task)
);

// print the generated response
System.out.printf("Grouped task result: %s\n",
    response.generative().text());
```

```csharp title="C#" {1,7-8}
var task = "What do these animals have in common, if anything?";

var jeopardy = client.Collections.Use("JeopardyQuestion");
var response = await jeopardy.Generate.NearText(
    "Cute animals",
    limit: 3,
    groupedTask: new GroupedTask(task)
);

// print the generated response
Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
```

```graphql title="GraphQL" {11-20}
{
  Get {
    JeopardyQuestion (
      nearText: {
        concepts: ["Cute animals"]
      }
      limit: 3
    ) {
      points
      _additional {
        generate(
          groupedResult: {
            task: """
              What do these animals have in common, if anything?
            """
          }
        ) {
          groupedResult
          error
        }
      }
    }
  }
}
```
:::

:::accordion{title="Example response"}
```
Grouped task result: All of these animals are mammals.
```
:::

### Set grouped task prompt properties

Define object `properties` to use in the prompt. This limits the information in the prompt and reduces prompt length.

:::code-group{sync="languages"}
```python title="Python" {8,12-14}
task = "What do these animals have in common, if anything?"

jeopardy = client.collections.use("JeopardyQuestion")
response = jeopardy.generate.near_text(
    query="Australian animals",
    limit=3,
    grouped_task=task,
    grouped_properties=["answer", "question"],
)

# print the generated response
for o in response.objects:
    print(f"Properties: {o.properties}")
print(f"Grouped task result: {response.generative.text}")
```

```typescript title="JavaScript/TypeScript"
let response;
const jeopardy = client.collections.use('JeopardyQuestion');
```

```go title="Go"
generatePrompt := "What do these animals have in common, if anything?"

gs := graphql.NewGenerativeSearch().GroupedResult(generatePrompt, "answer", "question")

response, err := client.GraphQL().Get().
  WithClassName("JeopardyQuestion").
  WithFields(
    graphql.Field{Name: "question"},
    graphql.Field{Name: "points"},
  ).
  WithGenerativeSearch(gs).
  WithNearText((&graphql.NearTextArgumentBuilder{}).
    WithConcepts([]string{"Australian animals"})).
  WithLimit(3).
  Do(ctx)
```

```java title="Java" {8-12}
CollectionHandle<Map<String, Object>> jeopardy =
    client.collections.use("JeopardyQuestion");
var response = jeopardy.generate.nearText("Cute animals", q -> q.limit(3),
    g -> g.groupedTask("What do these animals have in common, if anything?",
        c -> c.properties("answer", "question")));

// print the generated response
for (var o : response.objects()) {
  System.out.printf("Properties: %s\n", o.properties());
}
System.out.printf("Grouped task result: %s\n",
    response.generative().text());
```

```csharp title="C#" {9,14-18}
var task = "What do these animals have in common, if anything?";

var jeopardy = client.Collections.Use("JeopardyQuestion");
var response = await jeopardy.Generate.NearText(
    "Australian animals",
    limit: 3,
    groupedTask: new GroupedTask(task)
    {
        Properties = ["answer", "question"],
    }
);

// print the generated response
foreach (var o in response.Objects)
{
    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");
}
Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
```

```graphql title="GraphQL" {17}
{
  Get {
    JeopardyQuestion (
      nearText: {
        concepts: ["Australian animals"]
      }
      limit: 3
    ) {
      question
      points
      _additional {
        generate(
          groupedResult: {
            task: """
              What do these animals have in common, if anything?
            """
            properties: ["answer", "question"]
          }
        ) {
          groupedResult
          error
        }
      }
    }
  }
}
```
:::

:::accordion{title="Example response"}
```
Grouped task result: The commonality among these animals is that they are all native to Australia.
```
:::

### Additional parameters

:::callout{intent="info" title="Added in `v1.30`"}
:::

You can use _generative parameters_ to specify additional options when performing grouped tasks:

:::code-group{sync="languages"}
```python title="Python" {3-6,12}
from weaviate.classes.generate import GenerativeConfig, GenerativeParameters

grouped_task = GenerativeParameters.grouped_task(
    prompt="What do these animals have in common, if anything?",
    metadata=True,
)

jeopardy = client.collections.use("JeopardyQuestion")
response = jeopardy.generate.near_text(
    query="Cute animals",
    limit=3,
    grouped_task=grouped_task,
    generative_provider=GenerativeConfig.openai()
)

# print the generated response
print(f"Grouped task result: {response.generative.text}")
print(f"Metadata: {o.generative.metadata}")
```

```typescript title="JavaScript/TypeScript"
import { generativeParameters } from 'weaviate-client';
```

```go title="Go"
// Go support coming soon
```

```java title="Java" {4-8}
CollectionHandle<Map<String, Object>> jeopardy =
    client.collections.use("JeopardyQuestion");
var response = jeopardy.generate.nearText("Cute animals", q -> q.limit(3),
    g -> g.groupedTask("What do these animals have in common, if anything?",
        c -> c
            .generativeProvider(
                GenerativeProvider.openai(d -> d.baseUrl(null)))
            .debug(true))
);

// print the generated response
System.out.printf("Grouped task result: %s\n",
    response.generative().text());
System.out.printf("Metadata: %s\n", response.generative().metadata());
```

```csharp title="C#" {5-9}
var jeopardy = client.Collections.Use("JeopardyQuestion");
var response = await jeopardy.Generate.NearText(
    "Cute animals",
    limit: 3,
    groupedTask: new GroupedTask("What do these animals have in common, if anything?")
    {
        Debug = true,
    },
    provider: new Providers.OpenAI { ReturnMetadata = true, Model = "gpt-5-mini" }
);

// print the generated response
Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
// Console.WriteLine($"Metadata: {JsonSerializer.Serialize(response.Generative?.Metadata)}");
```
:::

:::accordion{title="Example response"}
```
Grouped task result: They are all animals.
Metadata: usage {
  prompt_tokens: 42
  completion_tokens: 36
  total_tokens: 78
}
```
:::

## Working with images

You can also supply images as a part of the input when performing retrieval augmented generation in both single prompts and grouped tasks.
The following fields are available for generative search with images:

- `images`: A base64 encoded string of the image bytes.
- `image_properties`: Names of the properties in Weaviate that store images for additional context.

:::code-group{sync="languages"}
```python title="Python" {9-11,18}
import base64
import requests
from weaviate.classes.generate import GenerativeConfig, GenerativeParameters

src_img_path = "https://images.unsplash.com/photo-1459262838948-3e2de6c1ec80?w=500&h=500&fit=crop"
base64_image = base64.b64encode(requests.get(src_img_path).content).decode('utf-8')

prompt = GenerativeParameters.grouped_task(
    prompt="Formulate a Jeopardy!-style question about this image",
    images=[base64_image],      # A list of base64 encoded strings of the image bytes
    # image_properties=["img"], # Properties containing images in Weaviate
)

jeopardy = client.collections.use("JeopardyQuestion")
response = jeopardy.generate.near_text(
    query="Australian animals",
    limit=3,
    grouped_task=prompt,
    grouped_properties=["answer", "question"],
    generative_provider=GenerativeConfig.anthropic(
        max_tokens=1000
    ),
)

# Print the source property and the generated response
for o in response.objects:
    print(f"Properties: {o.properties}")
print(f"Grouped task result: {response.generative.text}")
```

```typescript title="JavaScript/TypeScript"
import { generativeParameters } from 'weaviate-client';
```

```go title="Go"
// Go support coming soon
```

```java title="Java"
//   String srcImgPath =
//       "https://images.unsplash.com/photo-1459262838948-3e2de6c1ec80?w=500&h=500&fit=crop";
//   HttpClient httpClient = HttpClient.newHttpClient();
//   HttpRequest request =
//       HttpRequest.newBuilder().uri(URI.create(srcImgPath)).build();
//   HttpResponse<byte[]> imageResponse =
//       httpClient.send(request, HttpResponse.BodyHandlers.ofByteArray());
//   String base64Image =
//       Base64.getEncoder().encodeToString(imageResponse.body());

//   CollectionHandle<Map<String, Object>> jeopardy =
//       client.collections.use("JeopardyQuestion");
//   var response =
//       jeopardy.generate.nearText("Australian animals", q -> q.limit(3),
//           // highlight-start
//           g -> g.groupedTask(
//               "Formulate a Jeopardy!-style question about this image",
//               c -> c
//                   .dynamicProvider(
//                       DynamicProvider.anthropic(p -> p.maxTokens(1000)))
//                   .images(List.of(base64Image))
//                   .properties("answer", "question"))
//       // highlight-end
//       );

//   // Print the source property and the generated response
//   for (var o : response.objects()) {
//     System.out.printf("Properties: %s\n", o.properties());
//   }
//   System.out.printf("Grouped task result: %s\n", response.generative().text());
```

```csharp title="C#" {8-13}
var srcImgPath =
    "https://images.unsplash.com/photo-1459262838948-3e2de6c1ec80?w=500&h=500&fit=crop";
using var httpClient = new HttpClient();
var imageBytes = await httpClient.GetByteArrayAsync(srcImgPath);
var base64Image = Convert.ToBase64String(imageBytes);

var groupedTask = new GroupedTask("Formulate a Jeopardy!-style question about this image");
var provider = new Providers.Anthropic
{
    MaxTokens = 1000,
    Images = [base64Image], // A list of base64 encoded strings of the image bytes
    ImageProperties = ["img"], // Properties containing images in Weaviate }
};

var jeopardy = client.Collections.Use("JeopardyQuestion");
var response = await jeopardy.Generate.NearText(
    "Australian animals",
    limit: 3,
    groupedTask: groupedTask,
    provider: provider
);

// Print the source property and the generated response
foreach (var o in response.Objects)
{
    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");
}
Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
```
:::

:::accordion{title="Example response"}
```
Properties: {'points': 800, 'answer': 'sheep', 'air_date': datetime.datetime(2007, 12, 13, 0, 0, tzinfo=datetime.timezone.utc), 'question': 'Australians call this animal a jumbuck or a monkey', 'round': 'Jeopardy!'}
Properties: {'points': 100, 'answer': 'Australia', 'air_date': datetime.datetime(2000, 3, 10, 0, 0, tzinfo=datetime.timezone.utc), 'question': 'An island named for the animal seen <a href="http://www.j-archive.com/media/2000-03-10_J_01.jpg" target="_blank">here</a> belongs to this country [kangaroo]', 'round': 'Jeopardy!'}
Properties: {'points': 300, 'air_date': datetime.datetime(1996, 7, 18, 0, 0, tzinfo=datetime.timezone.utc), 'answer': 'Kangaroo', 'question': 'Found chiefly in Australia, the wallaby is a smaller type of this marsupial', 'round': 'Jeopardy!'}

Grouped task result: I'll formulate a Jeopardy!-style question based on the image of the koala:

Answer: This Australian marsupial, often mistakenly called a bear, spends most of its time in eucalyptus trees.

Question: What is a koala?
```
:::

## Related pages

- [Connect to Weaviate](../connect-to-weaviate/index.md)
- [Model provider integrations](../model-provider-integrations/index.md).
- [API References: GraphQL: Get](../apis/graphql-get.md)

## Questions and feedback

Have a question or feedback? Here's how to reach us.

::::card-grid
:::card{title="Community Forum" href="https://forum.weaviate.io/c/support" icon="messages-square"}
Ask questions and connect with other developers on our **Community forum**.
:::

:::card{title="Support" href="/guides/support-overview" icon="life-buoy"}
Weaviate Cloud user or customer? Find the right channel on the **Support page**.
:::
::::

## Related pages

- [Agents](./agents-index.md)
- [AI-assisted Weaviate code generation](./ai-assisted-vibe-coding-index.md)
- [APIs](./apis-index.md)
- [Authorization and authentication](./authorization-and-authentication-index.md)
- [Benchmarks](./benchmarks-index.md)
- [Best practices](./best-practices-index.md)
- [Client libraries](./clients-index.md)
- [Client Libraries / SDKs](./client-libraries-index.md)
- [Cloud](./cloud-index.md)
- [Cloud account management](./cloud-account-management-index.md)

# Agent Instructions

This portal answers questions programmatically. To receive a synthesized,
source-cited answer instead of crawling page by page, append the `?ask=`
query parameter to any page URL on this site:

    /guides/quickstart?ask=how+do+I+authenticate

Optional parameters:

- `&goal=<what-you-are-trying-to-do>` steers the answer toward your
  objective (e.g. `&goal=write+a+python+client`).
- `&version=<label>` scopes the answer to a mounted version when the
  portal publishes more than one.

The response is `text/markdown`: the answer followed by a `# Sources` list
of the portal pages it was grounded in. Status codes are the contract:

- `200` — the answer; `402` — the portal owner’s plan or answer credits are
  exhausted (surface this to your operator; do NOT retry); `429` — you are
  rate-limited; back off for the `Retry-After` seconds; `503` — the answer
  lane is temporarily unavailable; fall back to crawling the `.md` pages.

For the full corpus map read `llms.txt` at the site root; for the tool
surface (search + page fetch as MCP tools) see `/mcp`.
