Skip to main content
Open In ColabOpen on GitHub

Amazon Neptune with Cypher

Amazon Neptune is a high-performance graph analytics and serverless database for superior scalability and availability.

This example shows the QA chain that queries the Neptune graph database using openCypher and returns a human-readable response.

Cypher is a declarative graph query language that allows for expressive and efficient data querying in a property graph.

openCypher is an open-source implementation of Cypher.# Neptune Open Cypher QA Chain This QA chain queries Amazon Neptune using openCypher and returns human readable response

LangChain supports both Neptune Database and Neptune Analytics with create_neptune_opencypher_qa_chain.

Neptune Database is a serverless graph database designed for optimal scalability and availability. It provides a solution for graph database workloads that need to scale to 100,000 queries per second, Multi-AZ high availability, and multi-Region deployments. You can use Neptune Database for social networking, fraud alerting, and Customer 360 applications.

Neptune Analytics is an analytics database engine that can quickly analyze large amounts of graph data in memory to get insights and find trends. Neptune Analytics is a solution for quickly analyzing existing graph databases or graph datasets stored in a data lake. It uses popular graph analytic algorithms and low-latency analytic queries.

Using Neptune Database

from langchain_aws.graphs import NeptuneGraph

host = "<neptune-host>"
port = 8182
use_https = True

graph = NeptuneGraph(
host=host,
port=port,
use_https=use_https
)
API Reference:NeptuneGraph

Using Neptune Analytics

from langchain_aws.graphs import NeptuneAnalyticsGraph

graph = NeptuneAnalyticsGraph(graph_identifier="<neptune-analytics-graph-id>")
API Reference:NeptuneAnalyticsGraph

Using the Neptune openCypher QA Chain

This QA chain queries the Neptune graph database using openCypher and returns a human-readable response.

from langchain_aws import ChatBedrockConverse
from langchain_aws.chains import create_neptune_opencypher_qa_chain

MODEL_ID = "anthropic.claude-3-5-sonnet-20241022-v2:0"
llm = ChatBedrockConverse(
model=MODEL_ID,
temperature=0,
)

chain = create_neptune_opencypher_qa_chain(
llm=llm,
graph=graph,
)

result = chain.invoke({"query": "How many outgoing routes does the Austin airport have?"})
print(result['result'].content)
API Reference:ChatBedrockConverse

Was this page helpful?