nemoguardrails.embeddings.cache
Module Contents
Classes
Functions
Data
API
Abstract class for cache stores.
Clear the cache.
Get a value from the cache.
Set a value in the cache.
Bases: CacheStore
Filesystem cache store.
This cache store persists the cache between runs by storing it in the filesystem as JSON files.
Parameters:
The directory where the cache files will be stored. Defaults to ”./cache”.
Bases: CacheStore
In-memory cache store.
This cache store keeps the cache in memory. It does not persist the cache between runs.
Abstract class for key generators.
Bases: CacheStore
Redis cache store.
This cache store keeps the cache in a Redis database. It can be used to share the cache between multiple machines.
Parameters:
The Redis client to use. If not provided, a new client will be created.
Decorator to cache the embeddings.
This decorator caches the embeddings in the cache store.
It uses the cache_config attribute of the class to configure the cache.
If the class does not have a cache_config attribute, it will use the EmbeddingsCacheConfig by default.
This decorator can be applied to the _get_embeddings method of a subclass of EmbeddingsIndex that accepts a list of strings and returns a list of lists of floats.
Parameters:
The method to decorate. The first argument should be self.
Returns:
Callable[[Any, List[str]], Awaitable[List[List[float]]]]: The decorated method.