Open jayanthma opened 2 months ago
To connect to the Neptune database through llama_index
on your local machine, you can use the provided NeptuneDatabaseGraphStore
class. Here is an example of how you can instantiate and use this class:
from llama_index.graph_stores.neptune.database import NeptuneDatabaseGraphStore
# Define your Neptune database connection parameters
host = 'your-neptune-endpoint'
port = 8182
use_https = True
credentials_profile_name = 'your-aws-profile'
region_name = 'your-region'
sign = True
# Create an instance of the NeptuneDatabaseGraphStore
neptune_store = NeptuneDatabaseGraphStore(
host=host,
port=port,
use_https=use_https,
credentials_profile_name=credentials_profile_name,
region_name=region_name,
sign=sign
)
# Example query
query = "MATCH (n) RETURN n LIMIT 10"
results = neptune_store.query(query)
print(results)
Make sure to replace 'your-neptune-endpoint'
, 'your-aws-profile'
, and 'your-region'
with your actual Neptune database endpoint, AWS credentials profile name, and AWS region, respectively. This code will create a connection to your Neptune database and execute a sample query [1].
Additionally, ensure that your connection parameters such as host
, port
, and network configurations are correctly set. Here are some steps to help you troubleshoot and resolve the connectivity timeout issue:
host
and port
values are correctly specified and reachable.credentials_profile_name
and region_name
.Here is a snippet of the relevant code from the NeptuneDatabasePropertyGraphStore
class:
class NeptuneDatabasePropertyGraphStore(NeptuneBasePropertyGraph):
supports_vector_queries: bool = False
def __init__(
self,
host: str,
port: int = 8182,
client: Any = None,
credentials_profile_name: Optional[str] = None,
region_name: Optional[str] = None,
sign: bool = True,
use_https: bool = True,
**kwargs: Any,
) -> None:
self._client = create_neptune_database_client(
host, port, client, credentials_profile_name, region_name, sign, use_https
)
Ensure that the host
and port
values are correctly set to match your Neptune instance's configuration [2].
To continue talking to Dosu, mention @dosu.
Neptune Database runs within a private VPC in AWS. You will need to ensure that your local machine has access to that private VPC via either a jump box, VPN, PrivateLink, etc.
Question Validation
Question
How to connect to the Neptune database through llama_index in my local machine?
Below is my code:
from llama_index.llms.bedrock import Bedrock from llama_index.embeddings.bedrock import BedrockEmbedding from llama_index.core import ( StorageContext, SimpleDirectoryReader, PropertyGraphIndex, Settings, ) from llama_index.graph_stores.neptune import ( NeptuneAnalyticsPropertyGraphStore, NeptuneDatabasePropertyGraphStore, NeptuneDatabaseGraphStore ) from IPython.display import Markdown, display
llm = Bedrock(model="mistral.mistral-7b-instruct-v0:2", region_name="ap-south-1") embed_model = BedrockEmbedding(region_name="ap-south-1", model_name="cohere.embed-multilingual-v3")
Settings.llm = llm Settings.embed_model = embed_model Settings.chunk_size = 512
documents = SimpleDirectoryReader( "./english" ).load_data()
print(documents)
graph_store = NeptuneDatabasePropertyGraphStore( host="demo-neptune-cluster.cluster-abcdewxyzp12345.ap-south-1.neptune.amazonaws.com", port=8182 )
storage_context = StorageContext.from_defaults(graph_store=graph_store)
index = PropertyGraphIndex.from_documents( documents, property_graph_store = graph_store, storage_context=storage_context )
The error is CONNECTIVITY_TIMEOUT