mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-07-23 12:55:46 -04:00
74 lines
1.8 KiB
Plaintext
74 lines
1.8 KiB
Plaintext
---
|
|
dimensions:
|
|
type:
|
|
primary: reference
|
|
detail: core
|
|
level: beginner
|
|
standard_title: Persistent Storage KV
|
|
language: zh
|
|
title: 持久化存储
|
|
description: 本文档介绍了Dify插件中的持久化存储功能,详细说明了如何在插件中使用KV数据库来储存、获取和删除数据。这一功能使插件能够在相同Workspace内持久化存储数据,满足跨会话数据保存的需求。
|
|
---
|
|
|
|
如果单独审视插件中的 Tool 及 Endpoint,不难发现大多数情况下其只能完成单轮交互,请求后返回数据,任务结束。
|
|
|
|
如果有需要长期储存的数据,如实现持久化的记忆,需要插件具备持久化存储能力。**持久化存储机制能够让插件具备在相同 Workspace 持久存储数据的能力**,目前通过提供 KV 数据库满足存储需求,未来可能会根据实际的使用情况推出更灵活更强大的储存接口。
|
|
|
|
### 储存 Key
|
|
|
|
#### **入口**
|
|
|
|
```python
|
|
self.session.storage
|
|
```
|
|
|
|
#### **接口**
|
|
|
|
```python
|
|
def set(self, key: str, val: bytes) -> None:
|
|
pass
|
|
```
|
|
|
|
可以注意到传入的是一个 bytes,因此实际上你可以在其中储存文件。
|
|
|
|
### 获取 Key
|
|
|
|
#### **入口**
|
|
|
|
```python
|
|
self.session.storage
|
|
```
|
|
|
|
#### **接口**
|
|
|
|
```python
|
|
def get(self, key: str) -> bytes:
|
|
pass
|
|
```
|
|
|
|
### 删除 Key
|
|
|
|
#### **入口**
|
|
|
|
```python
|
|
self.session.storage
|
|
```
|
|
|
|
#### **接口**
|
|
|
|
```python
|
|
def delete(self, key: str) -> None:
|
|
pass
|
|
```
|
|
|
|
{/*
|
|
Contributing Section
|
|
DO NOT edit this section!
|
|
It will be automatically generated by the script.
|
|
*/}
|
|
|
|
---
|
|
|
|
[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/plugin-dev-zh/0411-persistent-storage-kv.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)
|
|
|