Skip to main content

Upstash Redis

Upstash offers developers serverless databases and messaging platforms to build powerful applications without having to worry about the operational complexity of running databases at scale.

This page covers how to use Upstash Redis with LangChain.

Installation and Setup​

  • Upstash Redis Python SDK can be installed with pip install upstash-redis
  • A globally distributed, low-latency and highly available database can be created at the Upstash Console

Integrations​

All of Upstash-LangChain integrations are based on upstash-redis Python SDK being utilized as wrappers for LangChain. This SDK utilizes Upstash Redis DB by giving UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN parameters from the console. One significant advantage of this is that, this SDK uses a REST API. This means, you can run this in serverless platforms, edge or any platform that does not support TCP connections.

Cache​

Upstash Redis can be used as a cache for LLM prompts and responses.

To import this cache:

from langchain.cache import UpstashRedisCache

To use with your LLMs:

import langchain
from upstash_redis import Redis

URL = "<UPSTASH_REDIS_REST_URL>"
TOKEN = "<UPSTASH_REDIS_REST_TOKEN>"

langchain.llm_cache = UpstashRedisCache(redis_=Redis(url=URL, token=TOKEN))

Memory​

Upstash Redis can be used to persist LLM conversations.

Chat Message History Memory​

An example of Upstash Redis for caching conversation message history can be seen in this notebook.