开始使用免费开始使用

创建 Cypher few-shot 提示词

您将使用的最后一种技术,是提供一个 few-shot 提示词,以提升生成的 Cypher 的可靠性。Few-shot 提示词可以在无需用大量示例微调模型的情况下,有效引导模型朝着期望的输出前进。

有一组针对本用例定制的示例,可通过 examples 获取;您可以在 shell 中打印它以查看内容。您将使用这些示例来为 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=["____"]
)
编辑并运行代码