With the results from the search at hand, it is now possible to generate a prompt to send to the LLM. The prompt must include the original question sent by the user, the relevant passages that were obtained in the retrieval phase, and instructions to the LLM stating that the answer should come from the included passages.

To render the prompt, the application uses Flask's render_template() function:

The template file that is referenced in this call is in api/templates/rag_prompt.txt.

You can make changes to this template if you'd like to see their effect in the quality of the chatbot responses. But always make sure to preserve the for-loop that renders the retrieved passages.

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. Elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as your are. Let’s connect and work together to build the magical search experience that will get you the results you want.

Try it yourself