mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 06:14:37 +00:00
docs: Update MongoDB information in llm_caching (#22708)
**Description:**: Update MongoDB information in llm_caching
This commit is contained in:
parent
c1fced9269
commit
3f76c9e908
@ -724,6 +724,83 @@
|
||||
"llm(\"Tell me joke\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9b2b2777",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## `MongoDB Atlas` Cache\n",
|
||||
"\n",
|
||||
"[MongoDB Atlas](https://www.mongodb.com/docs/atlas/) is a fully-managed cloud database available in AWS, Azure, and GCP. It has native support for \n",
|
||||
"Vector Search on the MongoDB document data.\n",
|
||||
"Use [MongoDB Atlas Vector Search](/docs/integrations/providers/mongodb_atlas) to semantically cache prompts and responses."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ecdc2a0a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### `MongoDBCache`\n",
|
||||
"An abstraction to store a simple cache in MongoDB. This does not use Semantic Caching, nor does it require an index to be made on the collection before generation.\n",
|
||||
"\n",
|
||||
"To import this cache:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"from langchain_mongodb.cache import MongoDBCache\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"To use this cache with your LLMs:\n",
|
||||
"```python\n",
|
||||
"from langchain_core.globals import set_llm_cache\n",
|
||||
"\n",
|
||||
"# use any embedding provider...\n",
|
||||
"from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings\n",
|
||||
"\n",
|
||||
"mongodb_atlas_uri = \"<YOUR_CONNECTION_STRING>\"\n",
|
||||
"COLLECTION_NAME=\"<YOUR_CACHE_COLLECTION_NAME>\"\n",
|
||||
"DATABASE_NAME=\"<YOUR_DATABASE_NAME>\"\n",
|
||||
"\n",
|
||||
"set_llm_cache(MongoDBCache(\n",
|
||||
" connection_string=mongodb_atlas_uri,\n",
|
||||
" collection_name=COLLECTION_NAME,\n",
|
||||
" database_name=DATABASE_NAME,\n",
|
||||
"))\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### `MongoDBAtlasSemanticCache`\n",
|
||||
"Semantic caching allows users to retrieve cached prompts based on semantic similarity between the user input and previously cached results. Under the hood it blends MongoDBAtlas as both a cache and a vectorstore.\n",
|
||||
"The MongoDBAtlasSemanticCache inherits from `MongoDBAtlasVectorSearch` and needs an Atlas Vector Search Index defined to work. Please look at the [usage example](/docs/integrations/vectorstores/mongodb_atlas) on how to set up the index.\n",
|
||||
"\n",
|
||||
"To import this cache:\n",
|
||||
"```python\n",
|
||||
"from langchain_mongodb.cache import MongoDBAtlasSemanticCache\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"To use this cache with your LLMs:\n",
|
||||
"```python\n",
|
||||
"from langchain_core.globals import set_llm_cache\n",
|
||||
"\n",
|
||||
"# use any embedding provider...\n",
|
||||
"from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings\n",
|
||||
"\n",
|
||||
"mongodb_atlas_uri = \"<YOUR_CONNECTION_STRING>\"\n",
|
||||
"COLLECTION_NAME=\"<YOUR_CACHE_COLLECTION_NAME>\"\n",
|
||||
"DATABASE_NAME=\"<YOUR_DATABASE_NAME>\"\n",
|
||||
"\n",
|
||||
"set_llm_cache(MongoDBAtlasSemanticCache(\n",
|
||||
" embedding=FakeEmbeddings(),\n",
|
||||
" connection_string=mongodb_atlas_uri,\n",
|
||||
" collection_name=COLLECTION_NAME,\n",
|
||||
" database_name=DATABASE_NAME,\n",
|
||||
"))\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"To find more resources about using MongoDBSemanticCache visit [here](https://www.mongodb.com/blog/post/introducing-semantic-caching-dedicated-mongodb-lang-chain-package-gen-ai-apps)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "726fe754",
|
||||
@ -993,7 +1070,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"CASSANDRA_KEYSPACE = demo_keyspace\n"
|
||||
@ -1029,7 +1106,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ASTRA_DB_ID = 01234567-89ab-cdef-0123-456789abcdef\n",
|
||||
|
Loading…
Reference in New Issue
Block a user