Limit the number of results#
You can limit the number of results from the Cypher QA Chain using the top_k parameter.
The default is 10.
chain = GraphCypherQAChain.from_llm(
    ChatOpenAI(temperature=0), graph=graph, verbose=True, top_k=2
)
chain.run("Who played in Top Gun?")
> Entering new GraphCypherQAChain chain...
Generated Cypher:
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie {name: 'Top Gun'})
RETURN a.name
Full Context:
[{'a.name': 'Val Kilmer'}, {'a.name': 'Anthony Edwards'}]
> Finished chain.
'Val Kilmer and Anthony Edwards played in Top Gun.'
Return intermediate results#
You can return intermediate steps from the Cypher QA Chain using the return_intermediate_steps parameter
chain = GraphCypherQAChain.from_llm(
    ChatOpenAI(temperature=0), graph=graph, verbose=True, return_intermediate_steps=True
)
result = chain("Who played in Top Gun?")
print(f"Intermediate steps: {result['intermediate_steps']}")
print(f"Final answer: {result['result']}")
> Entering new GraphCypherQAChain chain...
Generated Cypher:
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie {name: 'Top Gun'})
RETURN a.name
Full Context:
[{'a.name': 'Val Kilmer'}, {'a.name': 'Anthony Edwards'}, {'a.name': 'Meg Ryan'}, {'a.name': 'Tom Cruise'}]
> Finished chain.
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/graph_cypher_qa.html