From 14966581dfd3df163212a5912b3ce90b19778a31 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Thu, 4 Jan 2024 13:45:20 -0800 Subject: [PATCH] add ragatouille (#15561) --- .../integrations/retrievers/ragatouille.ipynb | 525 ++++++++++++++++++ .../model_io/chat/chat_model_caching.ipynb | 1 + .../modules/model_io/llms/llm_caching.ipynb | 1 + 3 files changed, 527 insertions(+) create mode 100644 docs/docs/integrations/retrievers/ragatouille.ipynb diff --git a/docs/docs/integrations/retrievers/ragatouille.ipynb b/docs/docs/integrations/retrievers/ragatouille.ipynb new file mode 100644 index 00000000000..9b4240b63ae --- /dev/null +++ b/docs/docs/integrations/retrievers/ragatouille.ipynb @@ -0,0 +1,525 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d19521dc", + "metadata": {}, + "source": [ + "# RAGatouille\n", + "\n", + "\n", + "This page covers how to use [RAGatouille](https://github.com/bclavie/RAGatouille) as a retriever in a LangChain chain. RAGatouille makes it as simple as can be to use ColBERT! [ColBERT](https://github.com/stanford-futuredata/ColBERT) is a fast and accurate retrieval model, enabling scalable BERT-based search over large text collections in tens of milliseconds. Since the Ragatouille wrapper is so ergonomic we will only write a simple wrapper class so it conforms to the LangChain api." + ] + }, + { + "cell_type": "markdown", + "id": "0b16a1cf", + "metadata": {}, + "source": [ + "## Load RAGatouille\n", + "\n", + "This example is taken from their documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "00de63d0", + "metadata": {}, + "outputs": [], + "source": [ + "from ragatouille import RAGPretrainedModel\n", + "\n", + "RAG = RAGPretrainedModel.from_pretrained(\"colbert-ir/colbertv2.0\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "9653b742", + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "\n", + "\n", + "def get_wikipedia_page(title: str):\n", + " \"\"\"\n", + " Retrieve the full text content of a Wikipedia page.\n", + "\n", + " :param title: str - Title of the Wikipedia page.\n", + " :return: str - Full text content of the page as raw string.\n", + " \"\"\"\n", + " # Wikipedia API endpoint\n", + " URL = \"https://en.wikipedia.org/w/api.php\"\n", + "\n", + " # Parameters for the API request\n", + " params = {\n", + " \"action\": \"query\",\n", + " \"format\": \"json\",\n", + " \"titles\": title,\n", + " \"prop\": \"extracts\",\n", + " \"explaintext\": True,\n", + " }\n", + "\n", + " # Custom User-Agent header to comply with Wikipedia's best practices\n", + " headers = {\"User-Agent\": \"RAGatouille_tutorial/0.0.1 (ben@clavie.eu)\"}\n", + "\n", + " response = requests.get(URL, params=params, headers=headers)\n", + " data = response.json()\n", + "\n", + " # Extracting page content\n", + " page = next(iter(data[\"query\"][\"pages\"].values()))\n", + " return page[\"extract\"] if \"extract\" in page else None" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "da2a13e2", + "metadata": {}, + "outputs": [], + "source": [ + "full_document = get_wikipedia_page(\"Hayao_Miyazaki\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "6a582959", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "[Jan 04, 13:19:13] #> Creating directory .ragatouille/colbert/indexes/Miyazaki \n", + "\n", + "\n", + "#> Starting...\n", + "[Jan 04, 13:19:17] Loading segmented_maxsim_cpp extension (set COLBERT_LOAD_TORCH_EXTENSION_VERBOSE=True for more info)...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/cuda/amp/grad_scaler.py:125: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available. Disabling.\n", + " warnings.warn(\n", + "\r", + " 0%| | 0/2 [00:00 Encoding 81 passages..\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + " 50%|█████ | 1/2 [00:03<00:03, 3.00s/it]/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/amp/autocast_mode.py:250: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling\n", + " warnings.warn(\n", + "100%|██████████| 2/2 [00:03<00:00, 1.82s/it]\n", + "WARNING clustering 10000 points to 1024 centroids: please provide at least 39936 training points\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Jan 04, 13:19:21] [0] \t\t avg_doclen_est = 129.95062255859375 \t len(local_sample) = 81\n", + "[Jan 04, 13:19:21] [0] \t\t Creating 1,024 partitions.\n", + "[Jan 04, 13:19:21] [0] \t\t *Estimated* 10,526 embeddings.\n", + "[Jan 04, 13:19:21] [0] \t\t #> Saving the indexing plan to .ragatouille/colbert/indexes/Miyazaki/plan.json ..\n", + "Clustering 10000 points in 128D to 1024 clusters, redo 1 times, 20 iterations\n", + " Preprocessing in 0.00 s\n", + " Iteration 0 (0.02 s, search 0.02 s): objective=3678.67 imbalance=1.583 nsplit=0 \r", + " Iteration 1 (0.02 s, search 0.02 s): objective=2381.02 imbalance=1.462 nsplit=0 \r", + " Iteration 2 (0.03 s, search 0.03 s): objective=2240.91 imbalance=1.453 nsplit=0 \r", + " Iteration 3 (0.04 s, search 0.04 s): objective=2177.91 imbalance=1.459 nsplit=0 \r", + " Iteration 4 (0.05 s, search 0.05 s): objective=2145.76 imbalance=1.465 nsplit=0 \r", + " Iteration 5 (0.06 s, search 0.05 s): objective=2127.39 imbalance=1.465 nsplit=0 \r", + " Iteration 6 (0.06 s, search 0.06 s): objective=2115.28 imbalance=1.467 nsplit=0 \r", + " Iteration 7 (0.07 s, search 0.07 s): objective=2107.16 imbalance=1.469 nsplit=0 \r", + " Iteration 8 (0.08 s, search 0.08 s): objective=2102.22 imbalance=1.468 nsplit=0 \r", + " Iteration 9 (0.09 s, search 0.08 s): objective=2099.1 imbalance=1.467 nsplit=0 \r", + " Iteration 10 (0.09 s, search 0.09 s): objective=2097.68 imbalance=1.466 nsplit=0 \r", + " Iteration 11 (0.10 s, search 0.10 s): objective=2096.89 imbalance=1.465 nsplit=0 \r", + " Iteration 12 (0.11 s, search 0.11 s): objective=2096.21 imbalance=1.464 nsplit=0 \r", + " Iteration 13 (0.12 s, search 0.11 s): objective=2095.73 imbalance=1.464 nsplit=0 \r", + " Iteration 14 (0.13 s, search 0.12 s): objective=2095.42 imbalance=1.465 nsplit=0 \r", + " Iteration 15 (0.13 s, search 0.13 s): objective=2095.38 imbalance=1.465 nsplit=0 \r", + " Iteration 16 (0.14 s, search 0.14 s): objective=2095.36 imbalance=1.465 nsplit=0 \r", + " Iteration 17 (0.15 s, search 0.15 s): objective=2095.36 imbalance=1.465 nsplit=0 \r", + " Iteration 18 (0.16 s, search 0.15 s): objective=2095.36 imbalance=1.465 nsplit=0 \r", + " Iteration 19 (0.17 s, search 0.16 s): objective=2095.36 imbalance=1.465 nsplit=0 \r", + "[0.037, 0.038, 0.039, 0.033, 0.033, 0.04, 0.033, 0.034, 0.032, 0.033, 0.033, 0.036, 0.033, 0.038, 0.037, 0.038, 0.035, 0.033, 0.034, 0.036, 0.037, 0.035, 0.032, 0.036, 0.037, 0.032, 0.037, 0.034, 0.036, 0.036, 0.034, 0.035, 0.039, 0.032, 0.035, 0.033, 0.035, 0.034, 0.034, 0.04, 0.034, 0.037, 0.033, 0.032, 0.035, 0.032, 0.036, 0.036, 0.036, 0.034, 0.034, 0.034, 0.033, 0.037, 0.035, 0.036, 0.039, 0.038, 0.043, 0.032, 0.033, 0.035, 0.035, 0.034, 0.038, 0.037, 0.034, 0.037, 0.033, 0.033, 0.034, 0.034, 0.034, 0.034, 0.036, 0.035, 0.033, 0.037, 0.036, 0.035, 0.035, 0.039, 0.033, 0.039, 0.033, 0.035, 0.037, 0.036, 0.033, 0.042, 0.036, 0.039, 0.037, 0.038, 0.036, 0.035, 0.04, 0.033, 0.036, 0.036, 0.037, 0.04, 0.035, 0.036, 0.036, 0.034, 0.035, 0.033, 0.036, 0.033, 0.035, 0.036, 0.037, 0.028, 0.034, 0.035, 0.036, 0.034, 0.037, 0.038, 0.033, 0.034, 0.033, 0.036, 0.034, 0.036, 0.035, 0.035]\n", + "[Jan 04, 13:19:22] [0] \t\t #> Encoding 81 passages..\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "0it [00:00, ?it/s]\n", + " 0%| | 0/2 [00:00 Optimizing IVF to store map from centroids to list of pids..\n", + "[Jan 04, 13:19:25] #> Building the emb2pid mapping..\n", + "[Jan 04, 13:19:25] len(emb2pid) = 10526\n", + "[Jan 04, 13:19:25] #> Saved optimized IVF to .ragatouille/colbert/indexes/Miyazaki/ivf.pid.pt\n", + "\n", + "#> Joined...\n", + "Done indexing!\n" + ] + } + ], + "source": [ + "RAG.index(\n", + " collection=[full_document],\n", + " index_name=\"Miyazaki\",\n", + " max_document_length=180,\n", + " split_documents=True,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fba3b082", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loading searcher for index Miyazaki for the first time... This may take a few seconds\n", + "[Jan 04, 13:19:48] Loading segmented_maxsim_cpp extension (set COLBERT_LOAD_TORCH_EXTENSION_VERBOSE=True for more info)...\n", + "[Jan 04, 13:19:49] #> Loading codec...\n", + "[Jan 04, 13:19:49] #> Loading IVF...\n", + "[Jan 04, 13:19:49] Loading segmented_lookup_cpp extension (set COLBERT_LOAD_TORCH_EXTENSION_VERBOSE=True for more info)...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/cuda/amp/grad_scaler.py:125: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available. Disabling.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Jan 04, 13:19:55] #> Loading doclens...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 376.07it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Jan 04, 13:19:55] #> Loading codes and residuals...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n", + "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 152.81it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Jan 04, 13:19:55] Loading filter_pids_cpp extension (set COLBERT_LOAD_TORCH_EXTENSION_VERBOSE=True for more info)...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Jan 04, 13:20:00] Loading decompress_residuals_cpp extension (set COLBERT_LOAD_TORCH_EXTENSION_VERBOSE=True for more info)...\n", + "Searcher loaded!\n", + "\n", + "#> QueryTokenizer.tensorize(batch_text[0], batch_background[0], bsize) ==\n", + "#> Input: . What animation studio did Miyazaki found?, \t\t True, \t\t None\n", + "#> Output IDs: torch.Size([32]), tensor([ 101, 1, 2054, 7284, 2996, 2106, 2771, 3148, 18637, 2179,\n", + " 1029, 102, 103, 103, 103, 103, 103, 103, 103, 103,\n", + " 103, 103, 103, 103, 103, 103, 103, 103, 103, 103,\n", + " 103, 103])\n", + "#> Output Mask: torch.Size([32]), tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", + " 0, 0, 0, 0, 0, 0, 0, 0])\n", + "\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/amp/autocast_mode.py:250: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "results = RAG.search(query=\"What animation studio did Miyazaki found?\", k=3)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "145b7edf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'content': 'In April 1984, Miyazaki opened his own office in Suginami Ward, naming it Nibariki.\\n\\n\\n=== Studio Ghibli ===\\n\\n\\n==== Early films (1985–1996) ====\\nIn June 1985, Miyazaki, Takahata, Tokuma and Suzuki founded the animation production company Studio Ghibli, with funding from Tokuma Shoten. Studio Ghibli\\'s first film, Laputa: Castle in the Sky (1986), employed the same production crew of Nausicaä. Miyazaki\\'s designs for the film\\'s setting were inspired by Greek architecture and \"European urbanistic templates\".',\n", + " 'score': 25.906391143798828,\n", + " 'rank': 1},\n", + " {'content': 'Hayao Miyazaki (宮崎 駿 or 宮﨑 駿, Miyazaki Hayao, [mijaꜜzaki hajao]; born January 5, 1941) is a Japanese animator, filmmaker, and manga artist. A co-founder of Studio Ghibli, he has attained international acclaim as a masterful storyteller and creator of Japanese animated feature films, and is widely regarded as one of the most accomplished filmmakers in the history of animation.\\nBorn in Tokyo City in the Empire of Japan, Miyazaki expressed interest in manga and animation from an early age, and he joined Toei Animation in 1963. During his early years at Toei Animation he worked as an in-between artist and later collaborated with director Isao Takahata.',\n", + " 'score': 25.472686767578125,\n", + " 'rank': 2},\n", + " {'content': 'Glen Keane said Miyazaki is a \"huge influence\" on Walt Disney Animation Studios and has been \"part of our heritage\" ever since The Rescuers Down Under (1990). The Disney Renaissance era was also prompted by competition with the development of Miyazaki\\'s films. Artists from Pixar and Aardman Studios signed a tribute stating, \"You\\'re our inspiration, Miyazaki-san!\"',\n", + " 'score': 24.847288131713867,\n", + " 'rank': 3}]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results" + ] + }, + { + "cell_type": "markdown", + "id": "2f5c7235", + "metadata": {}, + "source": [ + "## Use in LangChain\n", + "\n", + "In order to use as a retriever in LangChain, we need to make a really simple wrapper." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a88d9112", + "metadata": {}, + "outputs": [], + "source": [ + "from typing import List\n", + "\n", + "from langchain_core.callbacks import CallbackManagerForRetrieverRun\n", + "from langchain_core.documents import Document\n", + "from langchain_core.retrievers import BaseRetriever\n", + "\n", + "\n", + "class CustomRetriever(BaseRetriever):\n", + " rag: RAGPretrainedModel\n", + " k: int = 3\n", + "\n", + " def _get_relevant_documents(\n", + " self, query: str, *, run_manager: CallbackManagerForRetrieverRun\n", + " ) -> List[Document]:\n", + " results = self.rag.search(query=query, k=self.k)\n", + " return [Document(page_content=doc[\"content\"]) for doc in results]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "63da0b8e", + "metadata": {}, + "outputs": [], + "source": [ + "retriever = CustomRetriever(rag=RAG)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "65954ee4", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/amp/autocast_mode.py:250: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "text/plain": [ + "[Document(page_content='In April 1984, Miyazaki opened his own office in Suginami Ward, naming it Nibariki.\\n\\n\\n=== Studio Ghibli ===\\n\\n\\n==== Early films (1985–1996) ====\\nIn June 1985, Miyazaki, Takahata, Tokuma and Suzuki founded the animation production company Studio Ghibli, with funding from Tokuma Shoten. Studio Ghibli\\'s first film, Laputa: Castle in the Sky (1986), employed the same production crew of Nausicaä. Miyazaki\\'s designs for the film\\'s setting were inspired by Greek architecture and \"European urbanistic templates\".'),\n", + " Document(page_content='Hayao Miyazaki (宮崎 駿 or 宮﨑 駿, Miyazaki Hayao, [mijaꜜzaki hajao]; born January 5, 1941) is a Japanese animator, filmmaker, and manga artist. A co-founder of Studio Ghibli, he has attained international acclaim as a masterful storyteller and creator of Japanese animated feature films, and is widely regarded as one of the most accomplished filmmakers in the history of animation.\\nBorn in Tokyo City in the Empire of Japan, Miyazaki expressed interest in manga and animation from an early age, and he joined Toei Animation in 1963. During his early years at Toei Animation he worked as an in-between artist and later collaborated with director Isao Takahata.'),\n", + " Document(page_content='Glen Keane said Miyazaki is a \"huge influence\" on Walt Disney Animation Studios and has been \"part of our heritage\" ever since The Rescuers Down Under (1990). The Disney Renaissance era was also prompted by competition with the development of Miyazaki\\'s films. Artists from Pixar and Aardman Studios signed a tribute stating, \"You\\'re our inspiration, Miyazaki-san!\"')]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retriever.get_relevant_documents(\"What animation studio did Miyazaki found?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "550e73e2", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.chains import create_retrieval_chain\n", + "from langchain.chains.combine_documents import create_stuff_documents_chain\n", + "from langchain_community.chat_models import ChatOpenAI\n", + "from langchain_core.prompts import ChatPromptTemplate\n", + "\n", + "prompt = ChatPromptTemplate.from_template(\n", + " \"\"\"Answer the following question based only on the provided context:\n", + "\n", + "\n", + "{context}\n", + "\n", + "\n", + "Question: {input}\"\"\"\n", + ")\n", + "\n", + "llm = ChatOpenAI()\n", + "\n", + "document_chain = create_stuff_documents_chain(llm, prompt)\n", + "retrieval_chain = create_retrieval_chain(retriever, document_chain)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "0e58ee1d", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/amp/autocast_mode.py:250: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling\n", + " warnings.warn(\n" + ] + }, + { + "data": { + "text/plain": [ + "{'input': 'What animation studio did Miyazaki found?',\n", + " 'context': [Document(page_content='In April 1984, Miyazaki opened his own office in Suginami Ward, naming it Nibariki.\\n\\n\\n=== Studio Ghibli ===\\n\\n\\n==== Early films (1985–1996) ====\\nIn June 1985, Miyazaki, Takahata, Tokuma and Suzuki founded the animation production company Studio Ghibli, with funding from Tokuma Shoten. Studio Ghibli\\'s first film, Laputa: Castle in the Sky (1986), employed the same production crew of Nausicaä. Miyazaki\\'s designs for the film\\'s setting were inspired by Greek architecture and \"European urbanistic templates\".'),\n", + " Document(page_content='Hayao Miyazaki (宮崎 駿 or 宮﨑 駿, Miyazaki Hayao, [mijaꜜzaki hajao]; born January 5, 1941) is a Japanese animator, filmmaker, and manga artist. A co-founder of Studio Ghibli, he has attained international acclaim as a masterful storyteller and creator of Japanese animated feature films, and is widely regarded as one of the most accomplished filmmakers in the history of animation.\\nBorn in Tokyo City in the Empire of Japan, Miyazaki expressed interest in manga and animation from an early age, and he joined Toei Animation in 1963. During his early years at Toei Animation he worked as an in-between artist and later collaborated with director Isao Takahata.'),\n", + " Document(page_content='Glen Keane said Miyazaki is a \"huge influence\" on Walt Disney Animation Studios and has been \"part of our heritage\" ever since The Rescuers Down Under (1990). The Disney Renaissance era was also prompted by competition with the development of Miyazaki\\'s films. Artists from Pixar and Aardman Studios signed a tribute stating, \"You\\'re our inspiration, Miyazaki-san!\"')],\n", + " 'answer': 'Miyazaki founded Studio Ghibli.'}" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "retrieval_chain.invoke({\"input\": \"What animation studio did Miyazaki found?\"})" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "d0134f73", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/harrisonchase/.pyenv/versions/3.10.1/envs/langchain/lib/python3.10/site-packages/torch/amp/autocast_mode.py:250: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Miyazaki founded Studio Ghibli." + ] + } + ], + "source": [ + "for s in retrieval_chain.stream({\"input\": \"What animation studio did Miyazaki found?\"}):\n", + " print(s.get(\"answer\", \"\"), end=\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35aaceee", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/docs/modules/model_io/chat/chat_model_caching.ipynb b/docs/docs/modules/model_io/chat/chat_model_caching.ipynb index 7c0b6d0202e..69aae9aabf0 100644 --- a/docs/docs/modules/model_io/chat/chat_model_caching.ipynb +++ b/docs/docs/modules/model_io/chat/chat_model_caching.ipynb @@ -61,6 +61,7 @@ "source": [ "%%time\n", "from langchain.cache import InMemoryCache\n", + "\n", "set_llm_cache(InMemoryCache())\n", "\n", "# The first time, it is not yet in cache, so it should take longer\n", diff --git a/docs/docs/modules/model_io/llms/llm_caching.ipynb b/docs/docs/modules/model_io/llms/llm_caching.ipynb index eaac29f51fa..f75fe566259 100644 --- a/docs/docs/modules/model_io/llms/llm_caching.ipynb +++ b/docs/docs/modules/model_io/llms/llm_caching.ipynb @@ -54,6 +54,7 @@ "source": [ "%%time\n", "from langchain.cache import InMemoryCache\n", + "\n", "set_llm_cache(InMemoryCache())\n", "\n", "# The first time, it is not yet in cache, so it should take longer\n",