> ## Documentation Index
> Fetch the complete documentation index at: https://alterxyz-a56768d7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Persistent Storage

> This document introduces the persistent storage functionality in Dify plugins, detailing how to use the KV database in plugins to store, retrieve, and delete data. This feature enables plugins to persistently store data within the same Workspace, meeting the needs for data preservation across sessions.

When examining Tools and Endpoints in plugins individually, it's not difficult to see that in most cases, they can only complete single-round interactions: request, return data, and the task ends.

If there is data that needs to be stored long-term, such as implementing persistent memory, the plugin needs to have persistent storage capabilities. **The persistent storage mechanism allows plugins to have the ability to persistently store data within the same Workspace**. Currently, a KV database is provided to meet storage needs, and more flexible and powerful storage interfaces may be introduced in the future based on actual usage.

### Storing Keys

#### **Entry Point**

```python
    self.session.storage
```

#### **Interface**

```python
    def set(self, key: str, val: bytes) -> None:
        pass
```

Note that what is passed in is bytes, so you can actually store files in it.

### Getting Keys

#### **Entry Point**

```python
    self.session.storage
```

#### **Interface**

```python
    def get(self, key: str) -> bytes:
        pass
```

### Deleting Keys

#### **Entry Point**

```python
    self.session.storage
```

#### **Interface**

```python
    def delete(self, key: str) -> None:
        pass
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.