# Setting Connection & Initializing

### **1. Setting Up the Datalake Connection**

Before using Promptlake, a **MongoDB connection** must be established within **Datalake**.

```python
from config import Config
from dotenv import load_dotenv
from groclake.datalake import Datalake

load_dotenv()

class DatalakeConnection(Datalake):
    def __init__(self):
        super().__init__()
        MONGODB_CONFIG = Config.MONGODB_CONFIG
        MONGODB_CONFIG['connection_type'] = 'mongo'

        self.test_pipeline = self.create_pipeline(name="test_pipeline")
        self.test_pipeline.add_connection(name="mongodb_connection", config=MONGODB_CONFIG)
        self.execute_all()

        self.connections = {
            "mongodb_connection": self.get_connection("mongodb_connection")
        }

    def get_connection(self, connection_name):
        return self.test_pipeline.get_connection_by_name(connection_name)

# Initialize the connection
datalake_connection = DatalakeConnection()
mongodb_connection = datalake_connection.connections["mongodb_connection"]
```

#### **What This Does**

* Initializes a **Datalake** instance.
* Sets up **MongoDB** as a connection inside a data pipeline.
* Executes all configured connections and stores them in a dictionary for easy access.

***

### **2. Initializing Promptlake**

After setting up the Datalake connection, **Promptlake** can be initialized.

```python
class Promptlake:
    def __init__(self):
        self.mongodb_connection = mongodb_connection
```

* This class provides structured methods for storing and retrieving prompts.
* It **directly interacts with the MongoDB connection** from Datalake.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.groclake.ai/lakes/agent-management-and-deployment/promptlake/setting-connection-and-initializing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
