'Single prompt' generation
A 'single prompt' generation performs RAG queries on each retrieved object. This is useful when you want to transform each object separately, with the same prompt.
Code
Run this to find entries in "Movies" most similar to "dystopian future", translate the title of each movie into French, and print out the results.
import os
import weaviate
# Instantiate your client (not shown). e.g.:
# client = weaviate.connect_to_weaviate_cloud(...) or
# client = weaviate.connect_to_local(...)
# Configure collection object
movies = client.collections.use("Movies")
# Perform query
response = movies.generate.near_text(
query="dystopian future",
limit=5,
single_prompt="Translate this into French: {title}"
)
# Inspect the response
for o in response.objects:
print(o.properties["title"]) # Print the title
print(o.generated) # Print the generated text (the title, in French)
client.close()
Explain the code
RAG queries are accessed in Weaviate through the generate submodule of the collection object. Each generative query performs RAG in addition to the regular search query.
You must pass on one or more properties to the single_prompt parameter through braces, as we've done here with "... {title} ...". This instructs Weaviate to pass on the title property from each retrieved object to the generative AI model.
Example results
In Time
À temps
Looper
Boucleur
I, Robot
Je, Robot
The Matrix
La Matrice
Children of Men
Les enfants des hommes
Response object
Each response object is similar to that from a regular search query, with an additional generative.text attribute, which contains the generated output for each object.
'Single prompt' generation transforms each object separately with the same task. Next, you will learn how to use 'grouped task' generation to transform multiple objects together with a single task.