langchain4j [特性]支持将少量样本传递给Neo4jContentRetriever

7uhlpewt  于 2个月前  发布在  其他
关注(0)|答案(3)|浏览(49)

Andreas Kollegger的课程“RAG中的知识图谱”涵盖了创建一个Neo4j知识图谱,在他的示例中,他通过没有问题和Cypher示例来说明Neo4jContentRetriever获取错误的Cypher。这也在下面的博客的“最后一部分”中得到了涵盖,实际上与Andreas的Kollegger课程相同
https://medium.com/@rubenszimbres/building-knowledge-graphs-from-scratch-using-neo4j-and-vertex-ai-8311eb69a472
我希望Neo4jContentRetriever构建器支持传递如下的"examples"字符串

Neo4jContentRetriever retriever = Neo4jContentRetriever.builder()
                .graph(graph)
                .chatLanguageModel(chatLanguageModel)
                .examples(examples)
                .build();

并将默认提示模板设置为

private static final PromptTemplate DEFAULT_PROMPT_TEMPLATE = PromptTemplate.from("""

Task:Generate Cypher statement to query a graph database.
Instructions
Use only the provided relationship types and properties in the schema.
Do not use any other relationship types or properties that are not provided.
Schema:
{{schema}}

Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.

{{examples}}

Question: {{question}}

""");

如果用户没有设置"examples"变量,则将其作为""传递。对于格式化表示歉意,无法使其正确显示。

lkaoscv7

lkaoscv71#

@sjivan,这可以通过在Neo4jContentRetriever的构建器中提供一个PromptTemplate来实现:

Neo4jContentRetriever.builder()
                .graph(graph)
                .chatLanguageModel(chatLanguageModel)
                .promptTemplate(PromptTemplate.from(...))
                .build();
yzxexxkh

yzxexxkh2#

@sjivan,这可以通过在Neo4jContentRetriever的构建器中提供一个PromptTemplate来实现:

Neo4jContentRetriever.builder()
                .graph(graph)
                .chatLanguageModel(chatLanguageModel)
                .promptTemplate(PromptTemplate.from(...))
                .build();

@langchain4j 同意,但基本模板是一个很好的模板,我只需要添加一些示例。如果我传递一个promptTemplate,它基本上是默认模板加上示例。在学习了Andreas Kollegger的课程之后,很明显,几乎总是需要为Neo4jContentRetriever传递Cypher查询的示例,以便返回有效的Cypher,所以感觉最好支持将“示例”作为一级构造传递。

7rfyedvj

7rfyedvj3#

好的,这很有道理。但是请不要强制要求使用例子。

相关问题