From 8ea364880ccfef5a503d81f029e8d1f27f63a97d Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Wed, 6 Dec 2023 09:39:07 -0800 Subject: [PATCH] upstash redis --- .../integrations/stores/upstash_redis.ipynb | 90 +++++++++++++++++++ libs/langchain/langchain/storage/__init__.py | 3 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 docs/docs/integrations/stores/upstash_redis.ipynb diff --git a/docs/docs/integrations/stores/upstash_redis.ipynb b/docs/docs/integrations/stores/upstash_redis.ipynb new file mode 100644 index 0000000000000..b070728907f4b --- /dev/null +++ b/docs/docs/integrations/stores/upstash_redis.ipynb @@ -0,0 +1,90 @@ +{ + "cells": [ + { + "cell_type": "raw", + "metadata": {}, + "source": [ + "---\n", + "sidebar_label: Upstash Redis\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# UpstashRedisByteStore\n", + "\n", + "The `UpstashRedisStore` is an implementation of `ByteStore` that stores everything in your Upstash-hosted Redis instance.\n", + "\n", + "To use the base `RedisStore` instead, see [this guide](./redis)\n", + "\n", + "To configure Upstash Redis, follow our [Upstash guide](/docs/integrations/providers/upstash)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install upstash-redis" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[b'v1', b'v2']\n" + ] + } + ], + "source": [ + "from langchain.storage import UpstashRedisByteStore\n", + "from upstash_redis import Redis\n", + "\n", + "URL = \"\"\n", + "TOKEN = \"\"\n", + "\n", + "redis_client = Redis(url=URL, token=TOKEN)\n", + "store = UpstashRedisByteStore(client=redis_client, ttl=None, namespace=\"test-ns\")\n", + "\n", + "store.mset([(\"k1\", b\"v1\"), (\"k2\", b\"v2\")])\n", + "print(store.mget([\"k1\", \"k2\"]))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/libs/langchain/langchain/storage/__init__.py b/libs/langchain/langchain/storage/__init__.py index 18c9bea79c6cc..5722213f93db9 100644 --- a/libs/langchain/langchain/storage/__init__.py +++ b/libs/langchain/langchain/storage/__init__.py @@ -11,7 +11,7 @@ from langchain.storage.file_system import LocalFileStore from langchain.storage.in_memory import InMemoryByteStore, InMemoryStore from langchain.storage.redis import RedisStore -from langchain.storage.upstash_redis import UpstashRedisStore +from langchain.storage.upstash_redis import UpstashRedisByteStore, UpstashRedisStore __all__ = [ "EncoderBackedStore", @@ -21,5 +21,6 @@ "RedisStore", "create_lc_store", "create_kv_docstore", + "UpstashRedisByteStore", "UpstashRedisStore", ]