LoslegenKostenlos loslegen

Creating the retrieval prompt

A key piece of any RAG implementation is the retrieval prompt. In this exercise, you'll create a chat prompt template for your retrieval chain and test that the LLM is able to respond using only the context provided.

An llm has already been defined for you to use.

Diese Übung ist Teil des Kurses

Retrieval Augmented Generation (RAG) with LangChain

Kurs anzeigen

Anleitung zur Übung

  • Convert the string prompt into a reusable chat prompt template.
  • Create an LCEL chain to integrate the prompt template with the llm provided.
  • Invoke the chain on the inputs provided to see if you model can respond using only the context provided.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

prompt = """
Use the only the context provided to answer the following question. If you don't know the answer, reply that you are unsure.
Context: {context}
Question: {question}
"""

# Convert the string into a chat prompt template
prompt_template = ____

# Create an LCEL chain to test the prompt
chain = ____ | ____

# Invoke the chain on the inputs provided
print(chain.____({"context": "DataCamp's RAG course was created by Meri Nova and James Chapman!", "question": "Who created DataCamp's RAG course?"}))
Code bearbeiten und ausführen