Google Memorystore for Redis is a fully-managed service that is powered by the Redis in-memory data store to build application caches that provide sub-millisecond data access. Extend your database application to build AI-powered experiences leveraging Memorystore for Redisβs Langchain integrations.This notebook goes over how to use Memorystore for Redis to save, load and delete langchain documents with
MemorystoreDocumentLoader
and MemorystoreDocumentSaver
.
Learn more about the package on GitHub.
langchain-google-memorystore-redis
package, so we need to install it.
gcloud config list
.gcloud projects list
.MemorystoreDocumentSaver.add_documents(<documents>)
. To initialize MemorystoreDocumentSaver
class you need to provide 2 things:
client
- A redis.Redis
client object.key_prefix
- A prefix for the keys to store Documents in Redis.key_prefix
. Alternatively, you can designate the suffixes of the keys by specifying ids
in the add_documents
method.
MemorystoreDocumentLoader.load()
or MemorystoreDocumentLoader.lazy_load()
. lazy_load
returns a generator that only queries database during the iteration. To initialize MemorystoreDocumentLoader
class you need to provide:
client
- A redis.Redis
client object.key_prefix
- A prefix for the keys to store Documents in Redis.MemorystoreDocumentSaver.delete()
. You can also specify the suffixes of the keys if you know.
page_content
of the loaded Documents will contain a JSON-encoded string with top level fields equal to the specified fields in content_fields
.
If the metadata_fields
are specified, the metadata
field of the loaded Documents will only have the top level fields equal to the specified metadata_fields
. If any of the values of the metadata fields is stored as a JSON-encoded string, it will be decoded prior to being loaded to the metadata fields.