始める無料で始める

Cypher の few-shot プロンプトを作成する

生成される Cypher の信頼性を高めるために、最後に使うテクニックは「few-shot プロンプト」を提供することです。few-shot プロンプトは、大量の例でのファインチューニングを行わなくても、モデルを望ましい出力に誘導できる優れた方法です。

このユースケースに合わせて用意された一連の例は examples として提供されています。シェルで内容を表示して確認してみてください。これらの例を使って、Cypher 生成用の few-shot プロンプトを作成します。先ほど作成したグラフは graph として引き続き利用できます。

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

LangChain で学ぶ Retrieval Augmented Generation (RAG)

コースを見る

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

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

# Create an example prompt template
example_prompt = ____(
    "User input: {question}\nCypher query: {query}"
)

# Create the few-shot prompt template
cypher_prompt = ____(
    examples=____,
    example_prompt=____,
    prefix="You are a Neo4j expert. Given an input question, create a syntactically correct Cypher query to run.\n\nHere is the schema information\n{schema}.\n\nBelow are a number of examples of questions and their corresponding Cypher queries.",
    suffix="User input: {question}\nCypher query: ",
    input_variables=["____"]
)
コードを編集して実行