langchain_mongodb.cache.MongoDBCache

class langchain_mongodb.cache.MongoDBCache(connection_string: str, collection_name: str = 'default', database_name: str = 'default', **kwargs: Dict[str, Any])[source]

MongoDB Atlas cache

A cache that uses MongoDB Atlas as a backend

Initialize Atlas Cache. Creates collection on instantiation

Parameters
  • collection_name (str) – Name of collection for cache to live. Defaults to “default”.

  • connection_string (str) – Connection URI to MongoDB Atlas. Defaults to “default”.

  • database_name (str) – Name of database for cache to live. Defaults to “default”.

  • kwargs (Dict[str, Any]) –

Attributes

LLM

PROMPT

RETURN_VAL

collection

Returns the collection used to store cache values.

database

Returns the database used to store cache values.

Methods

__init__(connection_string[, ...])

Initialize Atlas Cache.

aclear(**kwargs)

Clear cache that can take additional keyword arguments.

alookup(prompt, llm_string)

Async version of lookup.

aupdate(prompt, llm_string, return_val)

Async version of aupdate.

clear(**kwargs)

Clear cache that can take additional keyword arguments.

lookup(prompt, llm_string)

Look up based on prompt and llm_string.

update(prompt, llm_string, return_val)

Update cache based on prompt and llm_string.

__init__(connection_string: str, collection_name: str = 'default', database_name: str = 'default', **kwargs: Dict[str, Any]) None[source]

Initialize Atlas Cache. Creates collection on instantiation

Parameters
  • collection_name (str) – Name of collection for cache to live. Defaults to “default”.

  • connection_string (str) – Connection URI to MongoDB Atlas. Defaults to “default”.

  • database_name (str) – Name of database for cache to live. Defaults to “default”.

  • kwargs (Dict[str, Any]) –

Return type

None

async aclear(**kwargs: Any) None

Clear cache that can take additional keyword arguments.

Parameters

kwargs (Any) –

Return type

None

async alookup(prompt: str, llm_string: str) Optional[Sequence[Generation]]

Async version of lookup.

Parameters
  • prompt (str) –

  • llm_string (str) –

Return type

Optional[Sequence[Generation]]

async aupdate(prompt: str, llm_string: str, return_val: Sequence[Generation]) None

Async version of aupdate.

Parameters
  • prompt (str) –

  • llm_string (str) –

  • return_val (Sequence[Generation]) –

Return type

None

clear(**kwargs: Any) None[source]

Clear cache that can take additional keyword arguments. Any additional arguments will propagate as filtration criteria for what gets deleted.

E.g.

# Delete only entries that have llm_string as “fake-model” self.clear(llm_string=”fake-model”)

Parameters

kwargs (Any) –

Return type

None

lookup(prompt: str, llm_string: str) Optional[Sequence[Generation]][source]

Look up based on prompt and llm_string.

Parameters
  • prompt (str) –

  • llm_string (str) –

Return type

Optional[Sequence[Generation]]

update(prompt: str, llm_string: str, return_val: Sequence[Generation]) None[source]

Update cache based on prompt and llm_string.

Parameters
  • prompt (str) –

  • llm_string (str) –

  • return_val (Sequence[Generation]) –

Return type

None