Skip to main content
Weaviate Docs (migrated from docs.weaviate.io) Docs

Search documentation

Type to search this documentation.

On this pageOverview

Retrieval Augmented Generation (RAG)

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.

To use RAG with a generative model integration:

Python
from weaviate.classes.generate import GenerativeConfigfrom weaviate.classes.query import MetadataQueryreviews = 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}")
JavaScript/TypeScript
import { generativeParameters } from 'weaviate-client';
Go
// Go support coming soon
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());
C#
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()}");
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.

Any vector-based search on collections with 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.

Python
from weaviate.classes.query import MetadataQueryreviews = 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}")
JavaScript/TypeScript
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 resultfor (let object of result.objects) {  console.log(JSON.stringify(object.properties, null, 2));  console.log(object.generative?.text); // print singlePrompt result}
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)        // .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());
C#
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
{  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        }      }    }  }}
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 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.

Python
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 responsesfor o in response.objects:    print(f"Properties: {o.properties}")    print(f"Single prompt result: {o.generative.text}")
JavaScript/TypeScript
let response;
const jeopardy = client.collections.use('JeopardyQuestion');
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
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 responsesfor (var o : response.objects()) {  System.out.printf("Properties: %s\n", o.properties());  System.out.printf("Single prompt result: %s\n", o.generative().text());}
C#
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 responsesforeach (var o in response.Objects){    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");    Console.WriteLine($"Single prompt result: {o.Generative?.Values.First()}");}
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
        }
      }
    }
  }
}
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

You can use generative parameters to specify additional options when performing a single prompt search:

Python
from weaviate.classes.generate import GenerativeConfig, GenerativeParametersprompt = 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 responsesfor 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}")
JavaScript/TypeScript
import { generativeParameters } from 'weaviate-client';
Go
// Go support coming soon
Java
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 responsesfor (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());}
C#
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 responsesforeach (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)}");}
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 returns one response that includes all of the query results. By default grouped task search uses all object properties in the prompt.

Python
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 responseprint(f"Grouped task result: {response.generative.text}")
JavaScript/TypeScript
let response;
const jeopardy = client.collections.use('JeopardyQuestion');
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
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 responseSystem.out.printf("Grouped task result: %s\n",    response.generative().text());
C#
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 responseConsole.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
GraphQL
{  Get {    JeopardyQuestion (      nearText: {        concepts: ["Cute animals"]      }      limit: 3    ) {      points      _additional {        generate(          groupedResult: {            task: """              What do these animals have in common, if anything?            """          }        ) {          groupedResult          error        }      }    }  }}
Example response
Grouped task result: All of these animals are mammals.

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

Python
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 responsefor o in response.objects:    print(f"Properties: {o.properties}")print(f"Grouped task result: {response.generative.text}")
JavaScript/TypeScript
let response;
const jeopardy = client.collections.use('JeopardyQuestion');
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
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 responsefor (var o : response.objects()) {  System.out.printf("Properties: %s\n", o.properties());}System.out.printf("Grouped task result: %s\n",    response.generative().text());
C#
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 responseforeach (var o in response.Objects){    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");}Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
GraphQL
{  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        }      }    }  }}
Example response
Grouped task result: The commonality among these animals is that they are all native to Australia.

You can use generative parameters to specify additional options when performing grouped tasks:

Python
from weaviate.classes.generate import GenerativeConfig, GenerativeParametersgrouped_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 responseprint(f"Grouped task result: {response.generative.text}")print(f"Metadata: {o.generative.metadata}")
JavaScript/TypeScript
import { generativeParameters } from 'weaviate-client';
Go
// Go support coming soon
Java
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 responseSystem.out.printf("Grouped task result: %s\n",    response.generative().text());System.out.printf("Metadata: %s\n", response.generative().metadata());
C#
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 responseConsole.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");// Console.WriteLine($"Metadata: {JsonSerializer.Serialize(response.Generative?.Metadata)}");
Example response
Grouped task result: They are all animals.
Metadata: usage {
  prompt_tokens: 42
  completion_tokens: 36
  total_tokens: 78
}

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.
Python
import base64import requestsfrom weaviate.classes.generate import GenerativeConfig, GenerativeParameterssrc_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 responsefor o in response.objects:    print(f"Properties: {o.properties}")print(f"Grouped task result: {response.generative.text}")
JavaScript/TypeScript
import { generativeParameters } from 'weaviate-client';
Go
// Go support coming soon
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());
C#
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 responseforeach (var o in response.Objects){    Console.WriteLine($"Properties: {JsonSerializer.Serialize(o.Properties)}");}Console.WriteLine($"Grouped task result: {response.Generative?.Values.First()}");
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?

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

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu