langchain.js
    Preparing search index...

    A cache that uses Momento as the backing store. See https://gomomento.com.

    const cache = new MomentoCache({
    client: new CacheClient({
    configuration: Configurations.Laptop.v1(),
    credentialProvider: CredentialProvider.fromEnvironmentVariable({
    environmentVariableName: "MOMENTO_API_KEY",
    }),
    defaultTtlSeconds: 60 * 60 * 24, // Cache TTL set to 24 hours.
    }),
    cacheName: "langchain",
    });
    // Initialize the OpenAI model with Momento cache for caching responses
    const model = new ChatOpenAI({
    model: "gpt-4o-mini",
    cache,
    });
    await model.invoke("How are you today?");
    const cachedValues = await cache.lookup("How are you today?", "llmKey");

    Hierarchy (View Summary)

    Index

    Methods

    • Lookup LLM generations in cache by prompt and associated LLM key.

      Parameters

      • prompt: string

        The prompt to lookup.

      • llmKey: string

        The LLM key to lookup.

      Returns Promise<null | Generation[]>

      The generations associated with the prompt and LLM key, or null if not found.

    • Update the cache with the given generations.

      Note this overwrites any existing generations for the given prompt and LLM key.

      Parameters

      • prompt: string

        The prompt to update.

      • llmKey: string

        The LLM key to update.

      • value: Generation[]

        The generations to store.

      Returns Promise<void>

    • Create a new standard cache backed by Momento.

      Parameters

      • props: MomentoCacheProps

        The settings to instantiate the cache.

        The settings to instantiate the Momento standard cache.

        • cacheName: string

          The name of the cache to use to store the data.

        • client: ICacheClient

          The Momento cache client.

        • OptionalensureCacheExists?: true

          If true, ensure that the cache exists before returning. If false, the cache is not checked for existence. Defaults to true.

        • OptionalttlSeconds?: number

          The time to live for the cache items. If not specified, the cache client default is used.

      Returns Promise<MomentoCache>

      The Momento-backed cache.

      InvalidArgumentError if props.ttlSeconds is not strictly positive.