'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.
Code
This example finds entries in "Movie" whose vector best matches the query vector (for "dystopian future"). 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 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", {
singlePrompt: "Translate this into French: {title}" },
{ limit: 5 }
)
// Inspect the response
for (let item of response.objects) {
console.log(`${item.properties.title} - ${item.generated}`)
}
Explain the code
You must pass on one or more properties to the singlePrompt
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
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 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.