始める無料で始める

検索プロンプトの作成

RAG実装において重要な要素のひとつが検索プロンプトです。この演習では、検索チェーン用のチャットプロンプトテンプレートを作成し、LLMが提供されたコンテキストのみを使って応答できるかを確認します。

すでに使用可能なllmが定義されています。

この演習はコースの一部です

LangChainで学ぶ検索拡張生成(RAG)

コースを見る

演習の手順

  • 文字列promptを再利用可能なチャットプロンプトテンプレートに変換してください。
  • プロンプトテンプレートと、llmを連携するLCELチェーンを作成してください。
  • 与えられた入力に対してchainを実行し、モデルが提供されたコンテキストのみを使って応答できるかを確認してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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?"}))
コードを編集して実行