run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.85k stars 5.28k forks source link

[Question]: Neptune cluster connectivity through llama_index #16061

Open jayanthma opened 2 months ago

jayanthma commented 2 months ago

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

dosubot[bot] commented 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:

  1. VPC Configuration: Ensure that your application is running within the same VPC as your Neptune DB.
  2. Security Group Settings: Verify that the security group associated with your Neptune DB allows inbound traffic on port 8182.
  3. Network ACLs: Check the Network ACLs for your VPC to ensure they are not blocking traffic on port 8182.
  4. Endpoint and Port: Double-check that the host and port values are correctly specified and reachable.
  5. SSL/TLS Configuration: If using HTTPS, ensure that the SSL/TLS settings are correctly configured.
  6. AWS Credentials and Region: Ensure that the AWS credentials and region are correctly set if using 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.

bechbd commented 2 months ago

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.