Skip to main content

'Single prompt' generation

A 'single prompt' generation wil perform RAG queries on each retrieved object. This is useful when you want to transform each object separately, with the same prompt.


This example finds entries in "Movie" based on their similarity to the input vector. Then, instructs the large language model to translate the title of each movie into French.

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_wcs(..., 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(
single_prompt="Translate this into French: {title}"

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


Explain the code

You must pass on one or more properties to the single_prompt parameter through braces, as we've done here with "... {title} ...". This will instruct Weaviate to pass on the title property from each retrieved object to the large language model.

Example results
In Time
À temps
I, Robot
Je, Robot
Mad Max: Fury Road
Mad Max: Fury Road
The Maze Runner
Le Labyrinthe

Response object

Each response object is similar to that from a regular search query, with an additional generated attribute. This attribute will contain the generated output for each object.

Questions and feedback

If you have any questions or feedback, let us know in the user forum.