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.
One significant advantage of Upstash is that their databases support HTTP and all of their SDKs use HTTP. This means that you can run this in serverless platforms, edge or any platform that does not support TCP connections.
Currently, there are two Upstash integrations available for LangChain: Upstash Vector as a vector embedding database and Upstash Redis as a cache and memory store.
Upstash Vector
Upstash Vector is a serverless vector database that can be used to store and query vectors.
Installation
Create a new serverless vector database at the Upstash Console. Select your preferred distance metric and dimension count according to your model.
Install the Upstash Vector Python SDK with pip install upstash-vector
.
The Upstash Vector integration in langchain is a wrapper for the Upstash Vector Python SDK. That's why the upstash-vector
package is required.
Integrations
Create a UpstashVectorStore
object using credentials from the Upstash Console.
You also need to pass in an Embeddings
object which can turn text into vector embeddings.
from langchain_community.vectorstores.upstash import UpstashVectorStore
import os
os.environ["UPSTASH_VECTOR_REST_URL"] = "<UPSTASH_VECTOR_REST_URL>"
os.environ["UPSTASH_VECTOR_REST_TOKEN"] = "<UPSTASH_VECTOR_REST_TOKEN>"
store = UpstashVectorStore(
embedding=embeddings
)
An alternative way of UpstashVectorStore
is to pass embedding=True
. This is a unique
feature of the UpstashVectorStore
thanks to the ability of the Upstash Vector indexes
to have an associated embedding model. In this configuration, documents we want to insert or
queries we want to search for are simply sent to Upstash Vector as text. In the background,
Upstash Vector embeds these text and executes the request with these embeddings. To use this
feature, create an Upstash Vector index by selecting a model
and simply pass embedding=True
:
from langchain_community.vectorstores.upstash import UpstashVectorStore
import os
os.environ["UPSTASH_VECTOR_REST_URL"] = "<UPSTASH_VECTOR_REST_URL>"
os.environ["UPSTASH_VECTOR_REST_TOKEN"] = "<UPSTASH_VECTOR_REST_TOKEN>"
store = UpstashVectorStore(
embedding=True
)
See Upstash Vector documentation for more detail on embedding models.