diff --git a/docs/docs/integrations/callbacks/comet_tracing.ipynb b/docs/docs/integrations/callbacks/comet_tracing.ipynb index 088786ed91e..f2cfcb5c6e4 100644 --- a/docs/docs/integrations/callbacks/comet_tracing.ipynb +++ b/docs/docs/integrations/callbacks/comet_tracing.ipynb @@ -29,6 +29,7 @@ "import os\n", "\n", "import comet_llm\n", + "from langchain_openai import OpenAI\n", "\n", "os.environ[\"LANGCHAIN_COMET_TRACING\"] = \"true\"\n", "\n", @@ -40,8 +41,7 @@ "# here we are configuring the comet project\n", "os.environ[\"COMET_PROJECT_NAME\"] = \"comet-example-langchain-tracing\"\n", "\n", - "from langchain.agents import AgentType, initialize_agent, load_tools\n", - "from langchain.llms import OpenAI" + "from langchain.agents import AgentType, initialize_agent, load_tools" ] }, { diff --git a/docs/docs/integrations/callbacks/context.ipynb b/docs/docs/integrations/callbacks/context.ipynb index 3f5bae3c773..8b3330265be 100644 --- a/docs/docs/integrations/callbacks/context.ipynb +++ b/docs/docs/integrations/callbacks/context.ipynb @@ -114,10 +114,7 @@ "source": [ "import os\n", "\n", - "from langchain.schema import (\n", - " HumanMessage,\n", - " SystemMessage,\n", - ")\n", + "from langchain_core.messages import HumanMessage, SystemMessage\n", "from langchain_openai import ChatOpenAI\n", "\n", "token = os.environ[\"CONTEXT_API_TOKEN\"]\n", diff --git a/docs/docs/integrations/callbacks/promptlayer.ipynb b/docs/docs/integrations/callbacks/promptlayer.ipynb index acbe00324ae..dd749afcf01 100644 --- a/docs/docs/integrations/callbacks/promptlayer.ipynb +++ b/docs/docs/integrations/callbacks/promptlayer.ipynb @@ -94,9 +94,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema import (\n", - " HumanMessage,\n", - ")\n", + "from langchain_core.messages import HumanMessage\n", "from langchain_openai import ChatOpenAI\n", "\n", "chat_llm = ChatOpenAI(\n", diff --git a/docs/docs/integrations/chat/azure_chat_openai.ipynb b/docs/docs/integrations/chat/azure_chat_openai.ipynb index 1b7cb31ee35..5e3f60ef6e8 100644 --- a/docs/docs/integrations/chat/azure_chat_openai.ipynb +++ b/docs/docs/integrations/chat/azure_chat_openai.ipynb @@ -127,7 +127,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks import get_openai_callback" + "from langchain_community.callbacks import get_openai_callback" ] }, { diff --git a/docs/docs/integrations/chat/baichuan.ipynb b/docs/docs/integrations/chat/baichuan.ipynb index 8b46b88b2b0..0f942c5da06 100644 --- a/docs/docs/integrations/chat/baichuan.ipynb +++ b/docs/docs/integrations/chat/baichuan.ipynb @@ -161,8 +161,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/chat/coze.ipynb b/docs/docs/integrations/chat/coze.ipynb index 269ce6c62ce..3888623ed39 100644 --- a/docs/docs/integrations/chat/coze.ipynb +++ b/docs/docs/integrations/chat/coze.ipynb @@ -86,7 +86,13 @@ { "data": { "text/plain": [ - "AIMessage(content='为你找到关于coze的信息如下:\n\nCoze是一个由字节跳动推出的AI聊天机器人和应用程序编辑开发平台。\n\n用户无论是否有编程经验,都可以通过该平台快速创建各种类型的聊天机器人、智能体、AI应用和插件,并将其部署在社交平台和即时聊天应用程序中。\n\n国际版使用的模型比国内版更强大。')" + "AIMessage(content='为你找到关于coze的信息如下:\n", + "\n", + "Coze是一个由字节跳动推出的AI聊天机器人和应用程序编辑开发平台。\n", + "\n", + "用户无论是否有编程经验,都可以通过该平台快速创建各种类型的聊天机器人、智能体、AI应用和插件,并将其部署在社交平台和即时聊天应用程序中。\n", + "\n", + "国际版使用的模型比国内版更强大。')" ] }, "execution_count": 3, @@ -173,8 +179,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/chat/deepinfra.ipynb b/docs/docs/integrations/chat/deepinfra.ipynb index f2810bdb7a5..f3f3704ccf4 100644 --- a/docs/docs/integrations/chat/deepinfra.ipynb +++ b/docs/docs/integrations/chat/deepinfra.ipynb @@ -67,7 +67,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler" + "from langchain_core.callbacks import StreamingStdOutCallbackHandler" ] }, { diff --git a/docs/docs/integrations/chat/ernie.ipynb b/docs/docs/integrations/chat/ernie.ipynb index f5d2fa0e30c..b109c65be3e 100644 --- a/docs/docs/integrations/chat/ernie.ipynb +++ b/docs/docs/integrations/chat/ernie.ipynb @@ -133,8 +133,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/chat/everlyai.ipynb b/docs/docs/integrations/chat/everlyai.ipynb index 3c08355cf70..511b81dd634 100644 --- a/docs/docs/integrations/chat/everlyai.ipynb +++ b/docs/docs/integrations/chat/everlyai.ipynb @@ -126,8 +126,8 @@ } ], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain_community.chat_models import ChatEverlyAI\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "from langchain_core.messages import HumanMessage, SystemMessage\n", "\n", "messages = [\n", @@ -184,8 +184,8 @@ } ], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain_community.chat_models import ChatEverlyAI\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "from langchain_core.messages import HumanMessage, SystemMessage\n", "\n", "messages = [\n", diff --git a/docs/docs/integrations/chat/gpt_router.ipynb b/docs/docs/integrations/chat/gpt_router.ipynb index 967bf5bbddb..866a696e63e 100644 --- a/docs/docs/integrations/chat/gpt_router.ipynb +++ b/docs/docs/integrations/chat/gpt_router.ipynb @@ -143,8 +143,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.manager import CallbackManager\n", - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler" + "from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler" ] }, { diff --git a/docs/docs/integrations/chat/litellm.ipynb b/docs/docs/integrations/chat/litellm.ipynb index 6ab12ff186d..61e067513e7 100644 --- a/docs/docs/integrations/chat/litellm.ipynb +++ b/docs/docs/integrations/chat/litellm.ipynb @@ -94,8 +94,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.manager import CallbackManager\n", - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler" + "from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler" ] }, { diff --git a/docs/docs/integrations/chat/litellm_router.ipynb b/docs/docs/integrations/chat/litellm_router.ipynb index 4f31928526b..7a7d0fd1218 100644 --- a/docs/docs/integrations/chat/litellm_router.ipynb +++ b/docs/docs/integrations/chat/litellm_router.ipynb @@ -122,8 +122,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.manager import CallbackManager\n", - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler" + "from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler" ] }, { diff --git a/docs/docs/integrations/chat/maritalk.ipynb b/docs/docs/integrations/chat/maritalk.ipynb index 87c9402a980..ca93de3e327 100644 --- a/docs/docs/integrations/chat/maritalk.ipynb +++ b/docs/docs/integrations/chat/maritalk.ipynb @@ -173,8 +173,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders import OnlinePDFLoader\n", - "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", + "from langchain_community.document_loaders import OnlinePDFLoader\n", + "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", "\n", "# Loading the COMVEST 2024 notice\n", "loader = OnlinePDFLoader(\n", @@ -202,7 +202,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.retrievers import BM25Retriever\n", + "from langchain_community.retrievers import BM25Retriever\n", "\n", "retriever = BM25Retriever.from_documents(texts)" ] diff --git a/docs/docs/integrations/chat/minimax.ipynb b/docs/docs/integrations/chat/minimax.ipynb index 3411b0beb06..6c96d15db10 100644 --- a/docs/docs/integrations/chat/minimax.ipynb +++ b/docs/docs/integrations/chat/minimax.ipynb @@ -71,8 +71,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/chat/mlx.ipynb b/docs/docs/integrations/chat/mlx.ipynb index 07a4cc638fc..9f35033cb60 100644 --- a/docs/docs/integrations/chat/mlx.ipynb +++ b/docs/docs/integrations/chat/mlx.ipynb @@ -66,10 +66,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema import (\n", - " HumanMessage,\n", - ")\n", "from langchain_community.chat_models.mlx import ChatMLX\n", + "from langchain_core.messages import HumanMessage\n", "\n", "messages = [\n", " HumanMessage(\n", diff --git a/docs/docs/integrations/chat/moonshot.ipynb b/docs/docs/integrations/chat/moonshot.ipynb index c8bac9d0531..87c409c8ffc 100644 --- a/docs/docs/integrations/chat/moonshot.ipynb +++ b/docs/docs/integrations/chat/moonshot.ipynb @@ -78,8 +78,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/chat/sparkllm.ipynb b/docs/docs/integrations/chat/sparkllm.ipynb index 14c92d00084..096ebec8c8b 100644 --- a/docs/docs/integrations/chat/sparkllm.ipynb +++ b/docs/docs/integrations/chat/sparkllm.ipynb @@ -34,7 +34,9 @@ "outputs": [ { "data": { - "text/plain": "AIMessage(content='Hello! How can I help you today?')" + "text/plain": [ + "AIMessage(content='Hello! How can I help you today?')" + ] }, "execution_count": 10, "metadata": {}, diff --git a/docs/docs/integrations/chat/yuan2.ipynb b/docs/docs/integrations/chat/yuan2.ipynb index 0e37110aebf..4ce737712ad 100644 --- a/docs/docs/integrations/chat/yuan2.ipynb +++ b/docs/docs/integrations/chat/yuan2.ipynb @@ -2,17 +2,17 @@ "cells": [ { "cell_type": "raw", - "source": [ - "---\n", - "sidebar_label: Yuan2.0\n", - "---" - ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% raw\n" } - } + }, + "source": [ + "---\n", + "sidebar_label: Yuan2.0\n", + "---" + ] }, { "cell_type": "markdown", @@ -216,7 +216,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "\n", "chat = ChatYuan2(\n", " yuan2_api_base=\"http://127.0.0.1:8001/v1\",\n", @@ -460,4 +460,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/chat/zhipuai.ipynb b/docs/docs/integrations/chat/zhipuai.ipynb index 7dd4ae931cc..643f6e72d16 100644 --- a/docs/docs/integrations/chat/zhipuai.ipynb +++ b/docs/docs/integrations/chat/zhipuai.ipynb @@ -199,28 +199,32 @@ }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "### Using With Functions Call\n", "\n", "GLM-4 Model can be used with the function call as well,use the following code to run a simple LangChain json_chat_agent." - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "os.environ[\"TAVILY_API_KEY\"] = \"tavily_api_key\"" - ], + "execution_count": null, "metadata": { "collapsed": false }, - "execution_count": null + "outputs": [], + "source": [ + "os.environ[\"TAVILY_API_KEY\"] = \"tavily_api_key\"" + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, "outputs": [], "source": [ "from langchain import hub\n", @@ -235,22 +239,18 @@ "agent_executor = AgentExecutor(\n", " agent=agent, tools=tools, verbose=True, handle_parsing_errors=True\n", ")" - ], - "metadata": { - "collapsed": false - }, - "execution_count": null + ] }, { "cell_type": "code", - "outputs": [], - "source": [ - "agent_executor.invoke({\"input\": \"what is LangChain?\"})" - ], + "execution_count": null, "metadata": { "collapsed": false }, - "execution_count": null + "outputs": [], + "source": [ + "agent_executor.invoke({\"input\": \"what is LangChain?\"})" + ] } ], "metadata": { diff --git a/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb b/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb index b703be818c3..d5b1968d16d 100644 --- a/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb +++ b/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb @@ -135,8 +135,8 @@ "source": [ "from pprint import pprint\n", "\n", - "from langchain.utils.openai_functions import convert_pydantic_to_openai_function\n", "from langchain_core.pydantic_v1 import BaseModel\n", + "from langchain_core.utils.function_calling import convert_pydantic_to_openai_function\n", "\n", "openai_function_def = convert_pydantic_to_openai_function(Calculator)\n", "pprint(openai_function_def)" @@ -149,7 +149,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.output_parsers.openai_functions import PydanticOutputFunctionsParser\n", + "from langchain_core.output_parsers.openai_functions import PydanticOutputFunctionsParser\n", "from langchain_core.prompts import ChatPromptTemplate\n", "from langchain_openai import ChatOpenAI\n", "\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_cdk.ipynb b/docs/docs/integrations/document_loaders/airbyte_cdk.ipynb index b92098a0392..24705f3f940 100644 --- a/docs/docs/integrations/document_loaders/airbyte_cdk.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_cdk.ipynb @@ -166,7 +166,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_gong.ipynb b/docs/docs/integrations/document_loaders/airbyte_gong.ipynb index 2d479be51cd..5a50360add7 100644 --- a/docs/docs/integrations/document_loaders/airbyte_gong.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_gong.ipynb @@ -149,7 +149,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_hubspot.ipynb b/docs/docs/integrations/document_loaders/airbyte_hubspot.ipynb index 77b889f6db6..995e388b1da 100644 --- a/docs/docs/integrations/document_loaders/airbyte_hubspot.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_hubspot.ipynb @@ -151,7 +151,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_salesforce.ipynb b/docs/docs/integrations/document_loaders/airbyte_salesforce.ipynb index 588b0eaef6b..d3dbbd52642 100644 --- a/docs/docs/integrations/document_loaders/airbyte_salesforce.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_salesforce.ipynb @@ -156,7 +156,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_shopify.ipynb b/docs/docs/integrations/document_loaders/airbyte_shopify.ipynb index de8733fdc6e..2302ccec94e 100644 --- a/docs/docs/integrations/document_loaders/airbyte_shopify.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_shopify.ipynb @@ -152,7 +152,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_stripe.ipynb b/docs/docs/integrations/document_loaders/airbyte_stripe.ipynb index 2d097d6e303..d2fed86b010 100644 --- a/docs/docs/integrations/document_loaders/airbyte_stripe.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_stripe.ipynb @@ -149,7 +149,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_typeform.ipynb b/docs/docs/integrations/document_loaders/airbyte_typeform.ipynb index b8ebdb9b372..ae89b573a32 100644 --- a/docs/docs/integrations/document_loaders/airbyte_typeform.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_typeform.ipynb @@ -152,7 +152,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/airbyte_zendesk_support.ipynb b/docs/docs/integrations/document_loaders/airbyte_zendesk_support.ipynb index c5a5fd9c101..e27eeaf054c 100644 --- a/docs/docs/integrations/document_loaders/airbyte_zendesk_support.ipynb +++ b/docs/docs/integrations/document_loaders/airbyte_zendesk_support.ipynb @@ -153,7 +153,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "\n", "def handle_record(record, id):\n", diff --git a/docs/docs/integrations/document_loaders/apify_dataset.ipynb b/docs/docs/integrations/document_loaders/apify_dataset.ipynb index 1afa3a4d311..240fe420f96 100644 --- a/docs/docs/integrations/document_loaders/apify_dataset.ipynb +++ b/docs/docs/integrations/document_loaders/apify_dataset.ipynb @@ -101,8 +101,8 @@ "outputs": [], "source": [ "from langchain.indexes import VectorstoreIndexCreator\n", - "from langchain_community.docstore.document import Document\n", - "from langchain_community.document_loaders import ApifyDatasetLoader" + "from langchain_community.document_loaders import ApifyDatasetLoader\n", + "from langchain_core.documents import Document" ] }, { diff --git a/docs/docs/integrations/document_loaders/assemblyai.ipynb b/docs/docs/integrations/document_loaders/assemblyai.ipynb index 19055d40065..458b1c21007 100644 --- a/docs/docs/integrations/document_loaders/assemblyai.ipynb +++ b/docs/docs/integrations/document_loaders/assemblyai.ipynb @@ -208,8 +208,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/astradb.ipynb b/docs/docs/integrations/document_loaders/astradb.ipynb index da8c7c40437..292823802f7 100644 --- a/docs/docs/integrations/document_loaders/astradb.ipynb +++ b/docs/docs/integrations/document_loaders/astradb.ipynb @@ -80,21 +80,21 @@ }, { "cell_type": "code", + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2024-01-08T12:41:22.643335Z", + "start_time": "2024-01-08T12:40:57.759116Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "from getpass import getpass\n", "\n", "ASTRA_DB_API_ENDPOINT = input(\"ASTRA_DB_API_ENDPOINT = \")\n", "ASTRA_DB_APPLICATION_TOKEN = getpass(\"ASTRA_DB_APPLICATION_TOKEN = \")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-01-08T12:41:22.643335Z", - "start_time": "2024-01-08T12:40:57.759116Z" - } - }, - "execution_count": 4 + ] }, { "cell_type": "code", @@ -118,18 +118,18 @@ }, { "cell_type": "code", - "outputs": [], - "source": [ - "docs = loader.load()" - ], + "execution_count": 7, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-01-08T12:42:30.236489Z", "start_time": "2024-01-08T12:42:29.612133Z" - } + }, + "collapsed": false }, - "execution_count": 7 + "outputs": [], + "source": [ + "docs = loader.load()" + ] }, { "cell_type": "code", @@ -143,7 +143,9 @@ "outputs": [ { "data": { - "text/plain": "Document(page_content='{\"_id\": \"659bdffa16cbc4586b11a423\", \"title\": \"Dangerous Men\", \"reviewtext\": \"\\\\\"Dangerous Men,\\\\\" the picture\\'s production notes inform, took 26 years to reach the big screen. After having seen it, I wonder: What was the rush?\"}', metadata={'namespace': 'default_keyspace', 'api_endpoint': 'https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com', 'collection': 'movie_reviews'})" + "text/plain": [ + "Document(page_content='{\"_id\": \"659bdffa16cbc4586b11a423\", \"title\": \"Dangerous Men\", \"reviewtext\": \"\\\\\"Dangerous Men,\\\\\" the picture\\'s production notes inform, took 26 years to reach the big screen. After having seen it, I wonder: What was the rush?\"}', metadata={'namespace': 'default_keyspace', 'api_endpoint': 'https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com', 'collection': 'movie_reviews'})" + ] }, "execution_count": 8, "metadata": {}, diff --git a/docs/docs/integrations/document_loaders/aws_s3_directory.ipynb b/docs/docs/integrations/document_loaders/aws_s3_directory.ipynb index b35dd57a2c5..e69822a6aba 100644 --- a/docs/docs/integrations/document_loaders/aws_s3_directory.ipynb +++ b/docs/docs/integrations/document_loaders/aws_s3_directory.ipynb @@ -104,37 +104,37 @@ }, { "cell_type": "markdown", + "id": "91a7ac07", + "metadata": {}, "source": [ "## Configuring the AWS Boto3 client\n", "You can configure the AWS [Boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) client by passing\n", "named arguments when creating the S3DirectoryLoader.\n", "This is useful for instance when AWS credentials can't be set as environment variables.\n", "See the [list of parameters](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session) that can be configured." - ], - "metadata": {}, - "id": "91a7ac07" + ] }, { "cell_type": "code", "execution_count": null, + "id": "f485ec8c", + "metadata": {}, "outputs": [], "source": [ "loader = S3DirectoryLoader(\n", " \"testing-hwc\", aws_access_key_id=\"xxxx\", aws_secret_access_key=\"yyyy\"\n", ")" - ], - "metadata": {}, - "id": "f485ec8c" + ] }, { "cell_type": "code", "execution_count": null, + "id": "c0fa76ae", + "metadata": {}, "outputs": [], "source": [ "loader.load()" - ], - "metadata": {}, - "id": "c0fa76ae" + ] } ], "metadata": { @@ -158,4 +158,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/document_loaders/aws_s3_file.ipynb b/docs/docs/integrations/document_loaders/aws_s3_file.ipynb index 71a32fb87e2..164991824bf 100644 --- a/docs/docs/integrations/document_loaders/aws_s3_file.ipynb +++ b/docs/docs/integrations/document_loaders/aws_s3_file.ipynb @@ -80,24 +80,24 @@ { "cell_type": "code", "execution_count": null, + "id": "43106ee8", + "metadata": {}, "outputs": [], "source": [ "loader = S3FileLoader(\n", " \"testing-hwc\", \"fake.docx\", aws_access_key_id=\"xxxx\", aws_secret_access_key=\"yyyy\"\n", ")" - ], - "metadata": {}, - "id": "43106ee8" + ] }, { "cell_type": "code", "execution_count": null, + "id": "1764a727", + "metadata": {}, "outputs": [], "source": [ "loader.load()" - ], - "metadata": {}, - "id": "1764a727" + ] } ], "metadata": { @@ -121,4 +121,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/document_loaders/bilibili.ipynb b/docs/docs/integrations/document_loaders/bilibili.ipynb index ee8c7822c49..7d5fa6e2f2d 100644 --- a/docs/docs/integrations/document_loaders/bilibili.ipynb +++ b/docs/docs/integrations/document_loaders/bilibili.ipynb @@ -143,4 +143,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/document_loaders/browserless.ipynb b/docs/docs/integrations/document_loaders/browserless.ipynb index 18753fb5761..25fb42e7964 100644 --- a/docs/docs/integrations/document_loaders/browserless.ipynb +++ b/docs/docs/integrations/document_loaders/browserless.ipynb @@ -96,8 +96,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/copypaste.ipynb b/docs/docs/integrations/document_loaders/copypaste.ipynb index 0375a4813ed..fd7608578a6 100644 --- a/docs/docs/integrations/document_loaders/copypaste.ipynb +++ b/docs/docs/integrations/document_loaders/copypaste.ipynb @@ -17,7 +17,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document" + "from langchain_core.documents import Document" ] }, { diff --git a/docs/docs/integrations/document_loaders/cube_semantic.ipynb b/docs/docs/integrations/document_loaders/cube_semantic.ipynb index 9f8c8404478..07cd5a343ec 100644 --- a/docs/docs/integrations/document_loaders/cube_semantic.ipynb +++ b/docs/docs/integrations/document_loaders/cube_semantic.ipynb @@ -145,8 +145,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/fauna.ipynb b/docs/docs/integrations/document_loaders/fauna.ipynb index 1ecb610a1e6..23bf6b4954b 100644 --- a/docs/docs/integrations/document_loaders/fauna.ipynb +++ b/docs/docs/integrations/document_loaders/fauna.ipynb @@ -76,8 +76,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/google_cloud_sql_pg.ipynb b/docs/docs/integrations/document_loaders/google_cloud_sql_pg.ipynb index a40123fed1c..7f190adce26 100644 --- a/docs/docs/integrations/document_loaders/google_cloud_sql_pg.ipynb +++ b/docs/docs/integrations/document_loaders/google_cloud_sql_pg.ipynb @@ -1,362 +1,362 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "E_RJy7C1bpCT" - }, - "source": [ - "# Google Cloud SQL for PostgreSQL\n", - "\n", - "> [Cloud SQL for PostgreSQL](https://cloud.google.com/sql/docs/postgres) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud Platform. Extend your database application to build AI-powered experiences leveraging Cloud SQL for PostgreSQL's Langchain integrations.\n", - "\n", - "This notebook goes over how to use `Cloud SQL for PostgreSQL` to load Documents with the `PostgresLoader` class.\n", - "\n", - "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/).\n", - "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-pg-python/blob/main/docs/document_loader.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "xjcxaw6--Xyy" - }, - "source": [ - "## Before you begin\n", - "\n", - "To run this notebook, you will need to do the following:\n", - "\n", - " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", - " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/marketplace/product/google/sqladmin.googleapis.com)\n", - " * [Create a Cloud SQL for PostgreSQL instance.](https://cloud.google.com/sql/docs/postgres/create-instance)\n", - " * [Create a Cloud SQL for PostgreSQL database.](https://cloud.google.com/sql/docs/postgres/create-manage-databases)\n", - " * [Add a User to the database.](https://cloud.google.com/sql/docs/postgres/create-manage-users)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "IR54BmgvdHT_" - }, - "source": [ - "### 🦜🔗 Library Installation\n", - "Install the integration library, `langchain_google_cloud_sql_pg`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 1000 - }, - "id": "0ZITIDE160OD", - "outputId": "90e0636e-ff34-4e1e-ad37-d2a6db4a317e" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --quiet langchain_google_cloud_sql_pg" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "v40bB_GMcr9f" - }, - "source": [ - "**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "6o0iGVIdDD6K" - }, - "outputs": [], - "source": [ - "# # Automatically restart kernel after installs so that your environment can access the new packages\n", - "# import IPython\n", - "\n", - "# app = IPython.Application.instance()\n", - "# app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "cTXTbj4UltKf" - }, - "source": [ - "### 🔐 Authentication\n", - "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", - "\n", - "* If you are using Colab to run this notebook, use the cell below and continue.\n", - "* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from google.colab import auth\n", - "\n", - "auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Uj02bMRAc9_c" - }, - "source": [ - "### ☁ Set Your Google Cloud Project\n", - "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", - "\n", - "If you don't know your project ID, try the following:\n", - "\n", - "* Run `gcloud config list`.\n", - "* Run `gcloud projects list`.\n", - "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "wnp1R1PYc9_c", - "outputId": "6502c721-a2fd-451f-b946-9f7b850d5966" - }, - "outputs": [], - "source": [ - "# @title Project { display-mode: \"form\" }\n", - "PROJECT_ID = \"gcp_project_id\" # @param {type:\"string\"}\n", - "\n", - "# Set the project id\n", - "! gcloud config set project {PROJECT_ID}" - ] - }, - { - "cell_type": "markdown", - "id": "f8f2830ee9ca1e01", - "metadata": { - "id": "f8f2830ee9ca1e01" - }, - "source": [ - "## Basic Usage" - ] - }, - { - "cell_type": "markdown", - "id": "OMvzMWRrR6n7", - "metadata": { - "id": "OMvzMWRrR6n7" - }, - "source": [ - "### Set Cloud SQL database values\n", - "Find your database variables, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql/instances)." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "irl7eMFnSPZr", - "metadata": { - "id": "irl7eMFnSPZr" - }, - "outputs": [], - "source": [ - "# @title Set Your Values Here { display-mode: \"form\" }\n", - "REGION = \"us-central1\" # @param {type: \"string\"}\n", - "INSTANCE = \"my-primary\" # @param {type: \"string\"}\n", - "DATABASE = \"my-database\" # @param {type: \"string\"}\n", - "TABLE_NAME = \"vector_store\" # @param {type: \"string\"}" - ] - }, - { - "cell_type": "markdown", - "id": "QuQigs4UoFQ2", - "metadata": { - "id": "QuQigs4UoFQ2" - }, - "source": [ - "### Cloud SQL Engine\n", - "\n", - "One of the requirements and arguments to establish PostgreSQL as a document loader is a `PostgresEngine` object. The `PostgresEngine` configures a connection pool to your Cloud SQL for PostgreSQL database, enabling successful connections from your application and following industry best practices.\n", - "\n", - "To create a `PostgresEngine` using `PostgresEngine.from_instance()` you need to provide only 4 things:\n", - "\n", - "1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n", - "1. `region` : Region where the Cloud SQL instance is located.\n", - "1. `instance` : The name of the Cloud SQL instance.\n", - "1. `database` : The name of the database to connect to on the Cloud SQL instance.\n", - "\n", - "By default, [IAM database authentication](https://cloud.google.com/sql/docs/postgres/iam-authentication) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the environment.\n", - "\n", - "Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/postgres/users) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `PostgresEngine.from_instance()`:\n", - "\n", - "* `user` : Database user to use for built-in database authentication and login\n", - "* `password` : Database password to use for built-in database authentication and login.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Note**: This tutorial demonstrates the async interface. All async methods have corresponding sync methods." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import PostgresEngine\n", - "\n", - "engine = await PostgresEngine.afrom_instance(\n", - " project_id=PROJECT_ID,\n", - " region=REGION,\n", - " instance=INSTANCE,\n", - " database=DATABASE,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "e1tl0aNx7SWy" - }, - "source": [ - "### Create PostgresLoader" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "z-AZyzAQ7bsf" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import PostgresLoader\n", - "\n", - "# Creating a basic PostgreSQL object\n", - "loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "PeOMpftjc9_e" - }, - "source": [ - "### Load Documents via default table\n", - "The loader returns a list of Documents from the table using the first column as page_content and all other columns as metadata. The default table will have the first column as\n", - "page_content and the second column as metadata (JSON). Each row becomes a document. Please note that if you want your documents to have ids you will need to add them in." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "cwvi_O5Wc9_e" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import PostgresLoader\n", - "\n", - "# Creating a basic PostgresLoader object\n", - "loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)\n", - "\n", - "docs = await loader.aload()\n", - "print(docs)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "kSkL9l1Hc9_e" - }, - "source": [ - "### Load documents via custom table/metadata or custom page content columns" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "loader = await PostgresLoader.create(\n", - " engine,\n", - " table_name=TABLE_NAME,\n", - " content_columns=[\"product_name\"], # Optional\n", - " metadata_columns=[\"id\"], # Optional\n", - ")\n", - "docs = await loader.aload()\n", - "print(docs)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "5R6h0_Cvc9_f" - }, - "source": [ - "### Set page content format\n", - "The loader returns a list of Documents, with one document per row, with page content in specified string format, i.e. text (space separated concatenation), JSON, YAML, CSV, etc. JSON and YAML formats include headers, while text and CSV do not include field headers.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "NGNdS7cqc9_f" - }, - "outputs": [], - "source": [ - "loader = await PostgresLoader.create(\n", - " engine,\n", - " table_name=\"products\",\n", - " content_columns=[\"product_name\", \"description\"],\n", - " format=\"YAML\",\n", - ")\n", - "docs = await loader.aload()\n", - "print(docs)" - ] - } - ], - "metadata": { - "colab": { - "provenance": [], - "toc_visible": true - }, - "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.9.6" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "E_RJy7C1bpCT" + }, + "source": [ + "# Google Cloud SQL for PostgreSQL\n", + "\n", + "> [Cloud SQL for PostgreSQL](https://cloud.google.com/sql/docs/postgres) is a fully-managed database service that helps you set up, maintain, manage, and administer your PostgreSQL relational databases on Google Cloud Platform. Extend your database application to build AI-powered experiences leveraging Cloud SQL for PostgreSQL's Langchain integrations.\n", + "\n", + "This notebook goes over how to use `Cloud SQL for PostgreSQL` to load Documents with the `PostgresLoader` class.\n", + "\n", + "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/).\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-pg-python/blob/main/docs/document_loader.ipynb)" + ] }, - "nbformat": 4, - "nbformat_minor": 4 -} \ No newline at end of file + { + "cell_type": "markdown", + "metadata": { + "id": "xjcxaw6--Xyy" + }, + "source": [ + "## Before you begin\n", + "\n", + "To run this notebook, you will need to do the following:\n", + "\n", + " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", + " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/marketplace/product/google/sqladmin.googleapis.com)\n", + " * [Create a Cloud SQL for PostgreSQL instance.](https://cloud.google.com/sql/docs/postgres/create-instance)\n", + " * [Create a Cloud SQL for PostgreSQL database.](https://cloud.google.com/sql/docs/postgres/create-manage-databases)\n", + " * [Add a User to the database.](https://cloud.google.com/sql/docs/postgres/create-manage-users)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IR54BmgvdHT_" + }, + "source": [ + "### 🦜🔗 Library Installation\n", + "Install the integration library, `langchain_google_cloud_sql_pg`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "0ZITIDE160OD", + "outputId": "90e0636e-ff34-4e1e-ad37-d2a6db4a317e" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --quiet langchain_google_cloud_sql_pg" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v40bB_GMcr9f" + }, + "source": [ + "**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6o0iGVIdDD6K" + }, + "outputs": [], + "source": [ + "# # Automatically restart kernel after installs so that your environment can access the new packages\n", + "# import IPython\n", + "\n", + "# app = IPython.Application.instance()\n", + "# app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cTXTbj4UltKf" + }, + "source": [ + "### 🔐 Authentication\n", + "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", + "\n", + "* If you are using Colab to run this notebook, use the cell below and continue.\n", + "* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from google.colab import auth\n", + "\n", + "auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Uj02bMRAc9_c" + }, + "source": [ + "### ☁ Set Your Google Cloud Project\n", + "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", + "\n", + "If you don't know your project ID, try the following:\n", + "\n", + "* Run `gcloud config list`.\n", + "* Run `gcloud projects list`.\n", + "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "wnp1R1PYc9_c", + "outputId": "6502c721-a2fd-451f-b946-9f7b850d5966" + }, + "outputs": [], + "source": [ + "# @title Project { display-mode: \"form\" }\n", + "PROJECT_ID = \"gcp_project_id\" # @param {type:\"string\"}\n", + "\n", + "# Set the project id\n", + "! gcloud config set project {PROJECT_ID}" + ] + }, + { + "cell_type": "markdown", + "id": "f8f2830ee9ca1e01", + "metadata": { + "id": "f8f2830ee9ca1e01" + }, + "source": [ + "## Basic Usage" + ] + }, + { + "cell_type": "markdown", + "id": "OMvzMWRrR6n7", + "metadata": { + "id": "OMvzMWRrR6n7" + }, + "source": [ + "### Set Cloud SQL database values\n", + "Find your database variables, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql/instances)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "irl7eMFnSPZr", + "metadata": { + "id": "irl7eMFnSPZr" + }, + "outputs": [], + "source": [ + "# @title Set Your Values Here { display-mode: \"form\" }\n", + "REGION = \"us-central1\" # @param {type: \"string\"}\n", + "INSTANCE = \"my-primary\" # @param {type: \"string\"}\n", + "DATABASE = \"my-database\" # @param {type: \"string\"}\n", + "TABLE_NAME = \"vector_store\" # @param {type: \"string\"}" + ] + }, + { + "cell_type": "markdown", + "id": "QuQigs4UoFQ2", + "metadata": { + "id": "QuQigs4UoFQ2" + }, + "source": [ + "### Cloud SQL Engine\n", + "\n", + "One of the requirements and arguments to establish PostgreSQL as a document loader is a `PostgresEngine` object. The `PostgresEngine` configures a connection pool to your Cloud SQL for PostgreSQL database, enabling successful connections from your application and following industry best practices.\n", + "\n", + "To create a `PostgresEngine` using `PostgresEngine.from_instance()` you need to provide only 4 things:\n", + "\n", + "1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n", + "1. `region` : Region where the Cloud SQL instance is located.\n", + "1. `instance` : The name of the Cloud SQL instance.\n", + "1. `database` : The name of the database to connect to on the Cloud SQL instance.\n", + "\n", + "By default, [IAM database authentication](https://cloud.google.com/sql/docs/postgres/iam-authentication) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the environment.\n", + "\n", + "Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/postgres/users) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `PostgresEngine.from_instance()`:\n", + "\n", + "* `user` : Database user to use for built-in database authentication and login\n", + "* `password` : Database password to use for built-in database authentication and login.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note**: This tutorial demonstrates the async interface. All async methods have corresponding sync methods." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import PostgresEngine\n", + "\n", + "engine = await PostgresEngine.afrom_instance(\n", + " project_id=PROJECT_ID,\n", + " region=REGION,\n", + " instance=INSTANCE,\n", + " database=DATABASE,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e1tl0aNx7SWy" + }, + "source": [ + "### Create PostgresLoader" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "z-AZyzAQ7bsf" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import PostgresLoader\n", + "\n", + "# Creating a basic PostgreSQL object\n", + "loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PeOMpftjc9_e" + }, + "source": [ + "### Load Documents via default table\n", + "The loader returns a list of Documents from the table using the first column as page_content and all other columns as metadata. The default table will have the first column as\n", + "page_content and the second column as metadata (JSON). Each row becomes a document. Please note that if you want your documents to have ids you will need to add them in." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "cwvi_O5Wc9_e" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import PostgresLoader\n", + "\n", + "# Creating a basic PostgresLoader object\n", + "loader = await PostgresLoader.create(engine, table_name=TABLE_NAME)\n", + "\n", + "docs = await loader.aload()\n", + "print(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kSkL9l1Hc9_e" + }, + "source": [ + "### Load documents via custom table/metadata or custom page content columns" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "loader = await PostgresLoader.create(\n", + " engine,\n", + " table_name=TABLE_NAME,\n", + " content_columns=[\"product_name\"], # Optional\n", + " metadata_columns=[\"id\"], # Optional\n", + ")\n", + "docs = await loader.aload()\n", + "print(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5R6h0_Cvc9_f" + }, + "source": [ + "### Set page content format\n", + "The loader returns a list of Documents, with one document per row, with page content in specified string format, i.e. text (space separated concatenation), JSON, YAML, CSV, etc. JSON and YAML formats include headers, while text and CSV do not include field headers.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NGNdS7cqc9_f" + }, + "outputs": [], + "source": [ + "loader = await PostgresLoader.create(\n", + " engine,\n", + " table_name=\"products\",\n", + " content_columns=[\"product_name\", \"description\"],\n", + " format=\"YAML\",\n", + ")\n", + "docs = await loader.aload()\n", + "print(docs)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [], + "toc_visible": true + }, + "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.9.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/docs/docs/integrations/document_loaders/google_datastore.ipynb b/docs/docs/integrations/document_loaders/google_datastore.ipynb index 78414404640..055c83c1fbc 100644 --- a/docs/docs/integrations/document_loaders/google_datastore.ipynb +++ b/docs/docs/integrations/document_loaders/google_datastore.ipynb @@ -1,336 +1,336 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Google Firestore in Datastore Mode\n", - "\n", - "> [Firestore in Datastore Mode](https://cloud.google.com/datastore) is a NoSQL document database built for automatic scaling, high performance and ease of application development. Extend your database application to build AI-powered experiences leveraging Datastore's Langchain integrations.\n", - "\n", - "This notebook goes over how to use [Firestore in Datastore Mode](https://cloud.google.com/datastore) to [save, load and delete langchain documents](/docs/how_to#document-loaders) with `DatastoreLoader` and `DatastoreSaver`.\n", - "\n", - "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-datastore-python/).\n", - "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-datastore-python/blob/main/docs/document_loader.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Before You Begin\n", - "\n", - "To run this notebook, you will need to do the following:\n", - "\n", - "* [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", - "* [Enable the Datastore API](https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com)\n", - "* [Create a Firestore in Datastore Mode database](https://cloud.google.com/datastore/docs/manage-databases)\n", - "\n", - "After confirmed access to database in the runtime environment of this notebook, filling the following values and run the cell before running example scripts." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 🦜🔗 Library Installation\n", - "\n", - "The integration lives in its own `langchain-google-datastore` package, so we need to install it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "%pip install -upgrade --quiet langchain-google-datastore" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Colab only**: Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# # Automatically restart kernel after installs so that your environment can access the new packages\n", - "# import IPython\n", - "\n", - "# app = IPython.Application.instance()\n", - "# app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### ☁ Set Your Google Cloud Project\n", - "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", - "\n", - "If you don't know your project ID, try the following:\n", - "\n", - "* Run `gcloud config list`.\n", - "* Run `gcloud projects list`.\n", - "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n", - "\n", - "PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n", - "\n", - "# Set the project id\n", - "!gcloud config set project {PROJECT_ID}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 🔐 Authentication\n", - "\n", - "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", - "\n", - "- If you are using Colab to run this notebook, use the cell below and continue.\n", - "- If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from google.colab import auth\n", - "\n", - "auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Basic Usage" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Save documents\n", - "\n", - "Save langchain documents with `DatastoreSaver.upsert_documents()`. By default it will try to extract the entity key from the `key` in the Document metadata." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_core.documents import Document\n", - "from langchain_google_datastore import DatastoreSaver\n", - "\n", - "saver = DatastoreSaver()\n", - "\n", - "data = [Document(page_content=\"Hello, World!\")]\n", - "saver.upsert_documents(data)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Save documents without key\n", - "\n", - "If a `kind` is specified the documents will be stored with an auto generated id." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "saver = DatastoreSaver(\"MyKind\")\n", - "\n", - "saver.upsert_documents(data)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Load documents via Kind\n", - "\n", - "Load langchain documents with `DatastoreLoader.load()` or `DatastoreLoader.lazy_load()`. `lazy_load` returns a generator that only queries database during the iteration. To initialize `DatastoreLoader` class you need to provide:\n", - "1. `source` - The source to load the documents. It can be an instance of Query or the name of the Datastore kind to read from." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_google_datastore import DatastoreLoader\n", - "\n", - "loader = DatastoreLoader(\"MyKind\")\n", - "data = loader.load()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Load documents via query\n", - "\n", - "Other than loading documents from kind, we can also choose to load documents from query. For example:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from google.cloud import datastore\n", - "\n", - "client = datastore.Client(database=\"non-default-db\", namespace=\"custom_namespace\")\n", - "query_load = client.query(kind=\"MyKind\")\n", - "query_load.add_filter(\"region\", \"=\", \"west_coast\")\n", - "\n", - "loader_document = DatastoreLoader(query_load)\n", - "\n", - "data = loader_document.load()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Delete documents\n", - "\n", - "Delete a list of langchain documents from Datastore with `DatastoreSaver.delete_documents()`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "saver = DatastoreSaver()\n", - "\n", - "saver.delete_documents(data)\n", - "\n", - "keys_to_delete = [\n", - " [\"Kind1\", \"identifier\"],\n", - " [\"Kind2\", 123],\n", - " [\"Kind3\", \"identifier\", \"NestedKind\", 456],\n", - "]\n", - "# The Documents will be ignored and only the document ids will be used.\n", - "saver.delete_documents(data, keys_to_delete)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Advanced Usage" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Load documents with customized document page content & metadata\n", - "\n", - "The arguments of `page_content_properties` and `metadata_properties` will specify the Entity properties to be written into LangChain Document `page_content` and `metadata`." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "loader = DatastoreLoader(\n", - " source=\"MyKind\",\n", - " page_content_fields=[\"data_field\"],\n", - " metadata_fields=[\"metadata_field\"],\n", - ")\n", - "\n", - "data = loader.load()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Customize Page Content Format\n", - "\n", - "When the `page_content` contains only one field the information will be the field value only. Otherwise the `page_content` will be in JSON format." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Customize Connection & Authentication" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from google.auth import compute_engine\n", - "from google.cloud.firestore import Client\n", - "\n", - "client = Client(database=\"non-default-db\", creds=compute_engine.Credentials())\n", - "loader = DatastoreLoader(\n", - " source=\"foo\",\n", - " client=client,\n", - ")" - ] - } - ], - "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.6" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Google Firestore in Datastore Mode\n", + "\n", + "> [Firestore in Datastore Mode](https://cloud.google.com/datastore) is a NoSQL document database built for automatic scaling, high performance and ease of application development. Extend your database application to build AI-powered experiences leveraging Datastore's Langchain integrations.\n", + "\n", + "This notebook goes over how to use [Firestore in Datastore Mode](https://cloud.google.com/datastore) to [save, load and delete langchain documents](/docs/how_to#document-loaders) with `DatastoreLoader` and `DatastoreSaver`.\n", + "\n", + "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-datastore-python/).\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-datastore-python/blob/main/docs/document_loader.ipynb)" + ] }, - "nbformat": 4, - "nbformat_minor": 4 -} \ No newline at end of file + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Before You Begin\n", + "\n", + "To run this notebook, you will need to do the following:\n", + "\n", + "* [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", + "* [Enable the Datastore API](https://console.cloud.google.com/flows/enableapi?apiid=datastore.googleapis.com)\n", + "* [Create a Firestore in Datastore Mode database](https://cloud.google.com/datastore/docs/manage-databases)\n", + "\n", + "After confirmed access to database in the runtime environment of this notebook, filling the following values and run the cell before running example scripts." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 🦜🔗 Library Installation\n", + "\n", + "The integration lives in its own `langchain-google-datastore` package, so we need to install it." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "%pip install -upgrade --quiet langchain-google-datastore" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Colab only**: Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# # Automatically restart kernel after installs so that your environment can access the new packages\n", + "# import IPython\n", + "\n", + "# app = IPython.Application.instance()\n", + "# app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### ☁ Set Your Google Cloud Project\n", + "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", + "\n", + "If you don't know your project ID, try the following:\n", + "\n", + "* Run `gcloud config list`.\n", + "* Run `gcloud projects list`.\n", + "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n", + "\n", + "PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n", + "\n", + "# Set the project id\n", + "!gcloud config set project {PROJECT_ID}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 🔐 Authentication\n", + "\n", + "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", + "\n", + "- If you are using Colab to run this notebook, use the cell below and continue.\n", + "- If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from google.colab import auth\n", + "\n", + "auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Basic Usage" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Save documents\n", + "\n", + "Save langchain documents with `DatastoreSaver.upsert_documents()`. By default it will try to extract the entity key from the `key` in the Document metadata." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_core.documents import Document\n", + "from langchain_google_datastore import DatastoreSaver\n", + "\n", + "saver = DatastoreSaver()\n", + "\n", + "data = [Document(page_content=\"Hello, World!\")]\n", + "saver.upsert_documents(data)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Save documents without key\n", + "\n", + "If a `kind` is specified the documents will be stored with an auto generated id." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "saver = DatastoreSaver(\"MyKind\")\n", + "\n", + "saver.upsert_documents(data)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load documents via Kind\n", + "\n", + "Load langchain documents with `DatastoreLoader.load()` or `DatastoreLoader.lazy_load()`. `lazy_load` returns a generator that only queries database during the iteration. To initialize `DatastoreLoader` class you need to provide:\n", + "1. `source` - The source to load the documents. It can be an instance of Query or the name of the Datastore kind to read from." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_google_datastore import DatastoreLoader\n", + "\n", + "loader = DatastoreLoader(\"MyKind\")\n", + "data = loader.load()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load documents via query\n", + "\n", + "Other than loading documents from kind, we can also choose to load documents from query. For example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from google.cloud import datastore\n", + "\n", + "client = datastore.Client(database=\"non-default-db\", namespace=\"custom_namespace\")\n", + "query_load = client.query(kind=\"MyKind\")\n", + "query_load.add_filter(\"region\", \"=\", \"west_coast\")\n", + "\n", + "loader_document = DatastoreLoader(query_load)\n", + "\n", + "data = loader_document.load()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Delete documents\n", + "\n", + "Delete a list of langchain documents from Datastore with `DatastoreSaver.delete_documents()`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "saver = DatastoreSaver()\n", + "\n", + "saver.delete_documents(data)\n", + "\n", + "keys_to_delete = [\n", + " [\"Kind1\", \"identifier\"],\n", + " [\"Kind2\", 123],\n", + " [\"Kind3\", \"identifier\", \"NestedKind\", 456],\n", + "]\n", + "# The Documents will be ignored and only the document ids will be used.\n", + "saver.delete_documents(data, keys_to_delete)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Advanced Usage" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Load documents with customized document page content & metadata\n", + "\n", + "The arguments of `page_content_properties` and `metadata_properties` will specify the Entity properties to be written into LangChain Document `page_content` and `metadata`." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "loader = DatastoreLoader(\n", + " source=\"MyKind\",\n", + " page_content_fields=[\"data_field\"],\n", + " metadata_fields=[\"metadata_field\"],\n", + ")\n", + "\n", + "data = loader.load()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Customize Page Content Format\n", + "\n", + "When the `page_content` contains only one field the information will be the field value only. Otherwise the `page_content` will be in JSON format." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Customize Connection & Authentication" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from google.auth import compute_engine\n", + "from google.cloud.firestore import Client\n", + "\n", + "client = Client(database=\"non-default-db\", creds=compute_engine.Credentials())\n", + "loader = DatastoreLoader(\n", + " source=\"foo\",\n", + " client=client,\n", + ")" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/docs/docs/integrations/document_loaders/google_el_carro.ipynb b/docs/docs/integrations/document_loaders/google_el_carro.ipynb index ee201a065df..517c2cd1b20 100644 --- a/docs/docs/integrations/document_loaders/google_el_carro.ipynb +++ b/docs/docs/integrations/document_loaders/google_el_carro.ipynb @@ -1,637 +1,637 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "NKbPFu-GWFDV" - }, - "source": [ - "# Google El Carro for Oracle Workloads\n", - "\n", - "> Google [El Carro Oracle Operator](https://github.com/GoogleCloudPlatform/elcarro-oracle-operator)\n", - "offers a way to run Oracle databases in Kubernetes as a portable, open source,\n", - "community driven, no vendor lock-in container orchestration system. El Carro\n", - "provides a powerful declarative API for comprehensive and consistent\n", - "configuration and deployment as well as for real-time operations and\n", - "monitoring.\n", - "Extend your Oracle database's capabilities to build AI-powered experiences\n", - "by leveraging the El Carro Langchain integration.\n", - "\n", - "This guide goes over how to use El Carro Langchain integration to\n", - "[save, load and delete langchain documents](/docs/how_to#document-loaders)\n", - "with `ElCarroLoader` and `ElCarroDocumentSaver`. This integration works for any Oracle database, regardless of where it is running.\n", - "\n", - "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-el-carro-python/).\n", - "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-el-carro-python/blob/main/docs/document_loader.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ZqONzXRcWMJg" - }, - "source": [ - "## Before You Begin\n", - "\n", - "Please complete\n", - "the [Getting Started](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/README.md#getting-started)\n", - "section of\n", - "the README to set up your El Carro Oracle database." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "imbbHxKfWPso" - }, - "source": [ - "### 🦜🔗 Library Installation\n", - "\n", - "The integration lives in its own `langchain-google-el-carro` package, so\n", - "we need to install it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Su5BMP2zWRwM" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --quiet langchain-google-el-carro" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "azV0k45WWSVI" - }, - "source": [ - "## Basic Usage\n", - "\n", - "### Set Up Oracle Database Connection\n", - "Fill out the following variable with your Oracle database connections details." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# @title Set Your Values Here { display-mode: \"form\" }\n", - "HOST = \"127.0.0.1\" # @param {type: \"string\"}\n", - "PORT = 3307 # @param {type: \"integer\"}\n", - "DATABASE = \"my-database\" # @param {type: \"string\"}\n", - "TABLE_NAME = \"message_store\" # @param {type: \"string\"}\n", - "USER = \"my-user\" # @param {type: \"string\"}\n", - "PASSWORD = input(\"Please provide a password to be used for the database user: \")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": false - }, - "source": [ - "\n", - "If you are using El Carro, you can find the hostname and port values in the\n", - "status of the El Carro Kubernetes instance.\n", - "Use the user password you created for your PDB.\n", - "\n", - "Example Ouput:\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": false - }, - "source": [ - "```\n", - "kubectl get -w instances.oracle.db.anthosapis.com -n db\n", - "NAME DB ENGINE VERSION EDITION ENDPOINT URL DB NAMES BACKUP ID READYSTATUS READYREASON DBREADYSTATUS DBREADYREASON\n", - "\n", - "mydb Oracle 18c Express mydb-svc.db 34.71.69.25:6021 ['pdbname'] TRUE CreateComplete True CreateComplete\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": false - }, - "source": [ - "### ElCarroEngine Connection Pool\n", - "\n", - "`ElCarroEngine` configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "xG1mYFkEWbkp" - }, - "outputs": [], - "source": [ - "from langchain_google_el_carro import ElCarroEngine\n", - "\n", - "elcarro_engine = ElCarroEngine.from_instance(\n", - " db_host=HOST,\n", - " db_port=PORT,\n", - " db_name=DATABASE,\n", - " db_user=USER,\n", - " db_password=PASSWORD,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ICW3k_qUWgyv" - }, - "source": [ - "### Initialize a table\n", - "\n", - "Initialize a table of default schema\n", - "via `elcarro_engine.init_document_table()`. Table Columns:\n", - "\n", - "- page_content (type: text)\n", - "- langchain_metadata (type: JSON)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "JmlGLukoWdfS" - }, - "outputs": [], - "source": [ - "elcarro_engine.drop_document_table(TABLE_NAME)\n", - "elcarro_engine.init_document_table(\n", - " table_name=TABLE_NAME,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "kaI3avj5Wn5O" - }, - "source": [ - "### Save documents\n", - "\n", - "Save langchain documents with `ElCarroDocumentSaver.add_documents()`.\n", - "To initialize `ElCarroDocumentSaver` class you need to provide 2 things:\n", - "\n", - "1. `elcarro_engine` - An instance of a `ElCarroEngine` engine.\n", - "2. `table_name` - The name of the table within the Oracle database to store\n", - " langchain documents." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "skaXpthSWpeg" - }, - "outputs": [], - "source": [ - "from langchain_core.documents import Document\n", - "from langchain_google_el_carro import ElCarroDocumentSaver\n", - "\n", - "doc = Document(\n", - " page_content=\"Banana\",\n", - " metadata={\"type\": \"fruit\", \"weight\": 100, \"organic\": 1},\n", - ")\n", - "\n", - "saver = ElCarroDocumentSaver(\n", - " elcarro_engine=elcarro_engine,\n", - " table_name=TABLE_NAME,\n", - ")\n", - "saver.add_documents([doc])" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "owTYQdNyWs9s" - }, - "source": [ - "### Load documents\n", - "\n", - "Load langchain documents with `ElCarroLoader.load()`\n", - "or `ElCarroLoader.lazy_load()`.\n", - "`lazy_load` returns a generator that only queries database during the iteration.\n", - "To initialize `ElCarroLoader` class you need to provide:\n", - "\n", - "1. `elcarro_engine` - An instance of a `ElCarroEngine` engine.\n", - "2. `table_name` - The name of the table within the Oracle database to store\n", - " langchain documents.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "CM6p11amWvYp" - }, - "outputs": [], - "source": [ - "from langchain_google_el_carro import ElCarroLoader\n", - "\n", - "loader = ElCarroLoader(elcarro_engine=elcarro_engine, table_name=TABLE_NAME)\n", - "docs = loader.lazy_load()\n", - "for doc in docs:\n", - " print(\"Loaded documents:\", doc)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "OTIDGiZ8WyS3" - }, - "source": [ - "### Load documents via query\n", - "\n", - "Other than loading documents from a table, we can also choose to load documents\n", - "from a view generated from a SQL query. For example:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "p3OB9AwgWzrq" - }, - "outputs": [], - "source": [ - "from langchain_google_el_carro import ElCarroLoader\n", - "\n", - "loader = ElCarroLoader(\n", - " elcarro_engine=elcarro_engine,\n", - " query=f\"SELECT * FROM {TABLE_NAME} WHERE json_value(langchain_metadata, '$.organic') = '1'\",\n", - ")\n", - "onedoc = loader.load()\n", - "print(onedoc)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "E6Fl7YNvW3Ep" - }, - "source": [ - "The view generated from SQL query can have different schema than default table.\n", - "In such cases, the behavior of ElCarroLoader is the same as loading from table\n", - "with non-default schema. Please refer to\n", - "section [Load documents with customized document page content & metadata](#load-documents-with-customized-document-page-content--metadata)." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "QgsP78MhW4wc" - }, - "source": [ - "### Delete documents\n", - "\n", - "Delete a list of langchain documents from an Oracle table\n", - "with `ElCarroDocumentSaver.delete()`.\n", - "\n", - "For a table with a default schema (page_content, langchain_metadata), the\n", - "deletion criteria is:\n", - "\n", - "A `row` should be deleted if there exists a `document` in the list, such that\n", - "\n", - "- `document.page_content` equals `row[page_content]`\n", - "- `document.metadata` equals `row[langchain_metadata]`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "QSYRHGHXW6IN" - }, - "outputs": [], - "source": [ - "docs = loader.load()\n", - "print(\"Documents before delete:\", docs)\n", - "saver.delete(onedoc)\n", - "print(\"Documents after delete:\", loader.load())" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "RerPkBRAW8yR" - }, - "source": [ - "## Advanced Usage\n", - "\n", - "### Load documents with customized document page content & metadata\n", - "\n", - "First we prepare an example table with non-default schema, and populate it with\n", - "some arbitrary data." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "u0Fd46aqW-8k" - }, - "outputs": [], - "source": [ - "import sqlalchemy\n", - "\n", - "create_table_query = f\"\"\"CREATE TABLE {TABLE_NAME} (\n", - " fruit_id NUMBER GENERATED BY DEFAULT AS IDENTITY (START WITH 1),\n", - " fruit_name VARCHAR2(100) NOT NULL,\n", - " variety VARCHAR2(50),\n", - " quantity_in_stock NUMBER(10) NOT NULL,\n", - " price_per_unit NUMBER(6,2) NOT NULL,\n", - " organic NUMBER(3) NOT NULL\n", - ")\"\"\"\n", - "elcarro_engine.drop_document_table(TABLE_NAME)\n", - "\n", - "with elcarro_engine.connect() as conn:\n", - " conn.execute(sqlalchemy.text(create_table_query))\n", - " conn.commit()\n", - " conn.execute(\n", - " sqlalchemy.text(\n", - " f\"\"\"\n", - " INSERT INTO {TABLE_NAME} (fruit_name, variety, quantity_in_stock, price_per_unit, organic)\n", - " VALUES ('Apple', 'Granny Smith', 150, 0.99, 1)\n", - " \"\"\"\n", - " )\n", - " )\n", - " conn.execute(\n", - " sqlalchemy.text(\n", - " f\"\"\"\n", - " INSERT INTO {TABLE_NAME} (fruit_name, variety, quantity_in_stock, price_per_unit, organic)\n", - " VALUES ('Banana', 'Cavendish', 200, 0.59, 0)\n", - " \"\"\"\n", - " )\n", - " )\n", - " conn.execute(\n", - " sqlalchemy.text(\n", - " f\"\"\"\n", - " INSERT INTO {TABLE_NAME} (fruit_name, variety, quantity_in_stock, price_per_unit, organic)\n", - " VALUES ('Orange', 'Navel', 80, 1.29, 1)\n", - " \"\"\"\n", - " )\n", - " )\n", - " conn.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "hGPYiTu7XBh3" - }, - "source": [ - "If we still load langchain documents with default parameters of `ElCarroLoader`\n", - "from this example table, the `page_content` of loaded documents will be the\n", - "first column of the table, and `metadata` will be consisting of key-value pairs\n", - "of all the other columns." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "eQbRapM_XC1S" - }, - "outputs": [], - "source": [ - "loader = ElCarroLoader(\n", - " elcarro_engine=elcarro_engine,\n", - " table_name=TABLE_NAME,\n", - ")\n", - "loaded_docs = loader.load()\n", - "print(f\"Loaded Documents: [{loaded_docs}]\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "tOH6i2jWXFqz" - }, - "source": [ - "We can specify the content and metadata we want to load by setting\n", - "the `content_columns` and `metadata_columns` when initializing\n", - "the `ElCarroLoader`.\n", - "\n", - "1. `content_columns`: The columns to write into the `page_content` of the\n", - " document.\n", - "2. `metadata_columns`: The columns to write into the `metadata` of the document.\n", - "\n", - "For example here, the values of columns in `content_columns` will be joined\n", - "together into a space-separated string, as `page_content` of loaded documents,\n", - "and `metadata` of loaded documents will only contain key-value pairs of columns\n", - "specified in `metadata_columns`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "9gCFWqgGXHD3" - }, - "outputs": [], - "source": [ - "loader = ElCarroLoader(\n", - " elcarro_engine=elcarro_engine,\n", - " table_name=TABLE_NAME,\n", - " content_columns=[\n", - " \"variety\",\n", - " \"quantity_in_stock\",\n", - " \"price_per_unit\",\n", - " \"organic\",\n", - " ],\n", - " metadata_columns=[\"fruit_id\", \"fruit_name\"],\n", - ")\n", - "loaded_docs = loader.load()\n", - "print(f\"Loaded Documents: [{loaded_docs}]\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "4KlSfvPJXKgM" - }, - "source": [ - "### Save document with customized page content & metadata\n", - "\n", - "In order to save langchain document into table with customized metadata fields\n", - "we need first create such a table via `ElCarroEngine.init_document_table()`, and\n", - "specify the list of `metadata_columns` we want it to have. In this example, the\n", - "created table will have table columns:\n", - "\n", - "- content (type: text): for storing fruit description.\n", - "- type (type VARCHAR2(200)): for storing fruit type.\n", - "- weight (type INT): for storing fruit weight.\n", - "- extra_json_metadata (type: JSON): for storing other metadata information of the\n", - " fruit.\n", - "\n", - "We can use the following parameters\n", - "with `elcarro_engine.init_document_table()` to create the table:\n", - "\n", - "1. `table_name`: The name of the table within the Oracle database to store\n", - " langchain documents.\n", - "2. `metadata_columns`: A list of `sqlalchemy.Column` indicating the list of\n", - " metadata columns we need.\n", - "3. `content_column`: column name to store `page_content` of langchain\n", - " document. Default: `\"page_content\", \"VARCHAR2(4000)\"`\n", - "4. `metadata_json_column`: column name to store extra\n", - " JSON `metadata` of langchain document.\n", - " Default: `\"langchain_metadata\", \"VARCHAR2(4000)\"`.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "1Wqs05gpXMW9" - }, - "outputs": [], - "source": [ - "elcarro_engine.drop_document_table(TABLE_NAME)\n", - "elcarro_engine.init_document_table(\n", - " table_name=TABLE_NAME,\n", - " metadata_columns=[\n", - " sqlalchemy.Column(\"type\", sqlalchemy.dialects.oracle.VARCHAR2(200)),\n", - " sqlalchemy.Column(\"weight\", sqlalchemy.INT),\n", - " ],\n", - " content_column=\"content\",\n", - " metadata_json_column=\"extra_json_metadata\",\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "bVEWHYU-XPFt" - }, - "source": [ - "Save documents with `ElCarroDocumentSaver.add_documents()`. As you\n", - "can see in this example,\n", - "\n", - "- `document.page_content` will be saved into `content` column.\n", - "- `document.metadata.type` will be saved into `type` column.\n", - "- `document.metadata.weight` will be saved into `weight` column.\n", - "- `document.metadata.organic` will be saved into `extra_json_metadata` column in\n", - " JSON format.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Iy4wRZLPXQn5" - }, - "outputs": [], - "source": [ - "doc = Document(\n", - " page_content=\"Banana\",\n", - " metadata={\"type\": \"fruit\", \"weight\": 100, \"organic\": 1},\n", - ")\n", - "\n", - "print(f\"Original Document: [{doc}]\")\n", - "\n", - "saver = ElCarroDocumentSaver(\n", - " elcarro_engine=elcarro_engine,\n", - " table_name=TABLE_NAME,\n", - " content_column=\"content\",\n", - " metadata_json_column=\"extra_json_metadata\",\n", - ")\n", - "saver.add_documents([doc])\n", - "\n", - "loader = ElCarroLoader(\n", - " elcarro_engine=elcarro_engine,\n", - " table_name=TABLE_NAME,\n", - " content_columns=[\"content\"],\n", - " metadata_columns=[\n", - " \"type\",\n", - " \"weight\",\n", - " ],\n", - " metadata_json_column=\"extra_json_metadata\",\n", - ")\n", - "\n", - "loaded_docs = loader.load()\n", - "print(f\"Loaded Document: [{loaded_docs[0]}]\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "x0vkL7PKXUmU" - }, - "source": [ - "### Delete documents with customized page content & metadata\n", - "\n", - "We can also delete documents from table with customized metadata columns\n", - "via `ElCarroDocumentSaver.delete()`. The deletion criteria is:\n", - "\n", - "A `row` should be deleted if there exists a `document` in the list, such that\n", - "\n", - "- `document.page_content` equals `row[page_content]`\n", - "- For every metadata field `k` in `document.metadata`\n", - " - `document.metadata[k]` equals `row[k]` or `document.metadata[k]`\n", - " equals `row[langchain_metadata][k]`\n", - "- There is no extra metadata field present in `row` but not\n", - " in `document.metadata`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "OcJPeCuKXWSa" - }, - "outputs": [], - "source": [ - "loader = ElCarroLoader(elcarro_engine=elcarro_engine, table_name=TABLE_NAME)\n", - "saver.delete(loader.load())\n", - "print(f\"Documents left: {len(loader.load())}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "S4SxUoY-XsPN" - }, - "source": [ - "## More examples\n", - "\n", - "Please look\n", - "at [demo_doc_loader_basic.py](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/samples/demo_doc_loader_basic.py)\n", - "and [demo_doc_loader_advanced.py](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/samples/demo_doc_loader_advanced.py)\n", - "for\n", - "complete code examples.\n" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "NKbPFu-GWFDV" + }, + "source": [ + "# Google El Carro for Oracle Workloads\n", + "\n", + "> Google [El Carro Oracle Operator](https://github.com/GoogleCloudPlatform/elcarro-oracle-operator)\n", + "offers a way to run Oracle databases in Kubernetes as a portable, open source,\n", + "community driven, no vendor lock-in container orchestration system. El Carro\n", + "provides a powerful declarative API for comprehensive and consistent\n", + "configuration and deployment as well as for real-time operations and\n", + "monitoring.\n", + "Extend your Oracle database's capabilities to build AI-powered experiences\n", + "by leveraging the El Carro Langchain integration.\n", + "\n", + "This guide goes over how to use El Carro Langchain integration to\n", + "[save, load and delete langchain documents](/docs/how_to#document-loaders)\n", + "with `ElCarroLoader` and `ElCarroDocumentSaver`. This integration works for any Oracle database, regardless of where it is running.\n", + "\n", + "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-el-carro-python/).\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-el-carro-python/blob/main/docs/document_loader.ipynb)" + ] }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + { + "cell_type": "markdown", + "metadata": { + "id": "ZqONzXRcWMJg" + }, + "source": [ + "## Before You Begin\n", + "\n", + "Please complete\n", + "the [Getting Started](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/README.md#getting-started)\n", + "section of\n", + "the README to set up your El Carro Oracle database." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "imbbHxKfWPso" + }, + "source": [ + "### 🦜🔗 Library Installation\n", + "\n", + "The integration lives in its own `langchain-google-el-carro` package, so\n", + "we need to install it." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Su5BMP2zWRwM" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --quiet langchain-google-el-carro" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "azV0k45WWSVI" + }, + "source": [ + "## Basic Usage\n", + "\n", + "### Set Up Oracle Database Connection\n", + "Fill out the following variable with your Oracle database connections details." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# @title Set Your Values Here { display-mode: \"form\" }\n", + "HOST = \"127.0.0.1\" # @param {type: \"string\"}\n", + "PORT = 3307 # @param {type: \"integer\"}\n", + "DATABASE = \"my-database\" # @param {type: \"string\"}\n", + "TABLE_NAME = \"message_store\" # @param {type: \"string\"}\n", + "USER = \"my-user\" # @param {type: \"string\"}\n", + "PASSWORD = input(\"Please provide a password to be used for the database user: \")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": false + }, + "source": [ + "\n", + "If you are using El Carro, you can find the hostname and port values in the\n", + "status of the El Carro Kubernetes instance.\n", + "Use the user password you created for your PDB.\n", + "\n", + "Example Ouput:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": false + }, + "source": [ + "```\n", + "kubectl get -w instances.oracle.db.anthosapis.com -n db\n", + "NAME DB ENGINE VERSION EDITION ENDPOINT URL DB NAMES BACKUP ID READYSTATUS READYREASON DBREADYSTATUS DBREADYREASON\n", + "\n", + "mydb Oracle 18c Express mydb-svc.db 34.71.69.25:6021 ['pdbname'] TRUE CreateComplete True CreateComplete\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": false + }, + "source": [ + "### ElCarroEngine Connection Pool\n", + "\n", + "`ElCarroEngine` configures a connection pool to your Oracle database, enabling successful connections from your application and following industry best practices." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "xG1mYFkEWbkp" + }, + "outputs": [], + "source": [ + "from langchain_google_el_carro import ElCarroEngine\n", + "\n", + "elcarro_engine = ElCarroEngine.from_instance(\n", + " db_host=HOST,\n", + " db_port=PORT,\n", + " db_name=DATABASE,\n", + " db_user=USER,\n", + " db_password=PASSWORD,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ICW3k_qUWgyv" + }, + "source": [ + "### Initialize a table\n", + "\n", + "Initialize a table of default schema\n", + "via `elcarro_engine.init_document_table()`. Table Columns:\n", + "\n", + "- page_content (type: text)\n", + "- langchain_metadata (type: JSON)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "JmlGLukoWdfS" + }, + "outputs": [], + "source": [ + "elcarro_engine.drop_document_table(TABLE_NAME)\n", + "elcarro_engine.init_document_table(\n", + " table_name=TABLE_NAME,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kaI3avj5Wn5O" + }, + "source": [ + "### Save documents\n", + "\n", + "Save langchain documents with `ElCarroDocumentSaver.add_documents()`.\n", + "To initialize `ElCarroDocumentSaver` class you need to provide 2 things:\n", + "\n", + "1. `elcarro_engine` - An instance of a `ElCarroEngine` engine.\n", + "2. `table_name` - The name of the table within the Oracle database to store\n", + " langchain documents." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "skaXpthSWpeg" + }, + "outputs": [], + "source": [ + "from langchain_core.documents import Document\n", + "from langchain_google_el_carro import ElCarroDocumentSaver\n", + "\n", + "doc = Document(\n", + " page_content=\"Banana\",\n", + " metadata={\"type\": \"fruit\", \"weight\": 100, \"organic\": 1},\n", + ")\n", + "\n", + "saver = ElCarroDocumentSaver(\n", + " elcarro_engine=elcarro_engine,\n", + " table_name=TABLE_NAME,\n", + ")\n", + "saver.add_documents([doc])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "owTYQdNyWs9s" + }, + "source": [ + "### Load documents\n", + "\n", + "Load langchain documents with `ElCarroLoader.load()`\n", + "or `ElCarroLoader.lazy_load()`.\n", + "`lazy_load` returns a generator that only queries database during the iteration.\n", + "To initialize `ElCarroLoader` class you need to provide:\n", + "\n", + "1. `elcarro_engine` - An instance of a `ElCarroEngine` engine.\n", + "2. `table_name` - The name of the table within the Oracle database to store\n", + " langchain documents.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "CM6p11amWvYp" + }, + "outputs": [], + "source": [ + "from langchain_google_el_carro import ElCarroLoader\n", + "\n", + "loader = ElCarroLoader(elcarro_engine=elcarro_engine, table_name=TABLE_NAME)\n", + "docs = loader.lazy_load()\n", + "for doc in docs:\n", + " print(\"Loaded documents:\", doc)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OTIDGiZ8WyS3" + }, + "source": [ + "### Load documents via query\n", + "\n", + "Other than loading documents from a table, we can also choose to load documents\n", + "from a view generated from a SQL query. For example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "p3OB9AwgWzrq" + }, + "outputs": [], + "source": [ + "from langchain_google_el_carro import ElCarroLoader\n", + "\n", + "loader = ElCarroLoader(\n", + " elcarro_engine=elcarro_engine,\n", + " query=f\"SELECT * FROM {TABLE_NAME} WHERE json_value(langchain_metadata, '$.organic') = '1'\",\n", + ")\n", + "onedoc = loader.load()\n", + "print(onedoc)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "E6Fl7YNvW3Ep" + }, + "source": [ + "The view generated from SQL query can have different schema than default table.\n", + "In such cases, the behavior of ElCarroLoader is the same as loading from table\n", + "with non-default schema. Please refer to\n", + "section [Load documents with customized document page content & metadata](#load-documents-with-customized-document-page-content--metadata)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QgsP78MhW4wc" + }, + "source": [ + "### Delete documents\n", + "\n", + "Delete a list of langchain documents from an Oracle table\n", + "with `ElCarroDocumentSaver.delete()`.\n", + "\n", + "For a table with a default schema (page_content, langchain_metadata), the\n", + "deletion criteria is:\n", + "\n", + "A `row` should be deleted if there exists a `document` in the list, such that\n", + "\n", + "- `document.page_content` equals `row[page_content]`\n", + "- `document.metadata` equals `row[langchain_metadata]`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "QSYRHGHXW6IN" + }, + "outputs": [], + "source": [ + "docs = loader.load()\n", + "print(\"Documents before delete:\", docs)\n", + "saver.delete(onedoc)\n", + "print(\"Documents after delete:\", loader.load())" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RerPkBRAW8yR" + }, + "source": [ + "## Advanced Usage\n", + "\n", + "### Load documents with customized document page content & metadata\n", + "\n", + "First we prepare an example table with non-default schema, and populate it with\n", + "some arbitrary data." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "u0Fd46aqW-8k" + }, + "outputs": [], + "source": [ + "import sqlalchemy\n", + "\n", + "create_table_query = f\"\"\"CREATE TABLE {TABLE_NAME} (\n", + " fruit_id NUMBER GENERATED BY DEFAULT AS IDENTITY (START WITH 1),\n", + " fruit_name VARCHAR2(100) NOT NULL,\n", + " variety VARCHAR2(50),\n", + " quantity_in_stock NUMBER(10) NOT NULL,\n", + " price_per_unit NUMBER(6,2) NOT NULL,\n", + " organic NUMBER(3) NOT NULL\n", + ")\"\"\"\n", + "elcarro_engine.drop_document_table(TABLE_NAME)\n", + "\n", + "with elcarro_engine.connect() as conn:\n", + " conn.execute(sqlalchemy.text(create_table_query))\n", + " conn.commit()\n", + " conn.execute(\n", + " sqlalchemy.text(\n", + " f\"\"\"\n", + " INSERT INTO {TABLE_NAME} (fruit_name, variety, quantity_in_stock, price_per_unit, organic)\n", + " VALUES ('Apple', 'Granny Smith', 150, 0.99, 1)\n", + " \"\"\"\n", + " )\n", + " )\n", + " conn.execute(\n", + " sqlalchemy.text(\n", + " f\"\"\"\n", + " INSERT INTO {TABLE_NAME} (fruit_name, variety, quantity_in_stock, price_per_unit, organic)\n", + " VALUES ('Banana', 'Cavendish', 200, 0.59, 0)\n", + " \"\"\"\n", + " )\n", + " )\n", + " conn.execute(\n", + " sqlalchemy.text(\n", + " f\"\"\"\n", + " INSERT INTO {TABLE_NAME} (fruit_name, variety, quantity_in_stock, price_per_unit, organic)\n", + " VALUES ('Orange', 'Navel', 80, 1.29, 1)\n", + " \"\"\"\n", + " )\n", + " )\n", + " conn.commit()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hGPYiTu7XBh3" + }, + "source": [ + "If we still load langchain documents with default parameters of `ElCarroLoader`\n", + "from this example table, the `page_content` of loaded documents will be the\n", + "first column of the table, and `metadata` will be consisting of key-value pairs\n", + "of all the other columns." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "eQbRapM_XC1S" + }, + "outputs": [], + "source": [ + "loader = ElCarroLoader(\n", + " elcarro_engine=elcarro_engine,\n", + " table_name=TABLE_NAME,\n", + ")\n", + "loaded_docs = loader.load()\n", + "print(f\"Loaded Documents: [{loaded_docs}]\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tOH6i2jWXFqz" + }, + "source": [ + "We can specify the content and metadata we want to load by setting\n", + "the `content_columns` and `metadata_columns` when initializing\n", + "the `ElCarroLoader`.\n", + "\n", + "1. `content_columns`: The columns to write into the `page_content` of the\n", + " document.\n", + "2. `metadata_columns`: The columns to write into the `metadata` of the document.\n", + "\n", + "For example here, the values of columns in `content_columns` will be joined\n", + "together into a space-separated string, as `page_content` of loaded documents,\n", + "and `metadata` of loaded documents will only contain key-value pairs of columns\n", + "specified in `metadata_columns`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9gCFWqgGXHD3" + }, + "outputs": [], + "source": [ + "loader = ElCarroLoader(\n", + " elcarro_engine=elcarro_engine,\n", + " table_name=TABLE_NAME,\n", + " content_columns=[\n", + " \"variety\",\n", + " \"quantity_in_stock\",\n", + " \"price_per_unit\",\n", + " \"organic\",\n", + " ],\n", + " metadata_columns=[\"fruit_id\", \"fruit_name\"],\n", + ")\n", + "loaded_docs = loader.load()\n", + "print(f\"Loaded Documents: [{loaded_docs}]\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4KlSfvPJXKgM" + }, + "source": [ + "### Save document with customized page content & metadata\n", + "\n", + "In order to save langchain document into table with customized metadata fields\n", + "we need first create such a table via `ElCarroEngine.init_document_table()`, and\n", + "specify the list of `metadata_columns` we want it to have. In this example, the\n", + "created table will have table columns:\n", + "\n", + "- content (type: text): for storing fruit description.\n", + "- type (type VARCHAR2(200)): for storing fruit type.\n", + "- weight (type INT): for storing fruit weight.\n", + "- extra_json_metadata (type: JSON): for storing other metadata information of the\n", + " fruit.\n", + "\n", + "We can use the following parameters\n", + "with `elcarro_engine.init_document_table()` to create the table:\n", + "\n", + "1. `table_name`: The name of the table within the Oracle database to store\n", + " langchain documents.\n", + "2. `metadata_columns`: A list of `sqlalchemy.Column` indicating the list of\n", + " metadata columns we need.\n", + "3. `content_column`: column name to store `page_content` of langchain\n", + " document. Default: `\"page_content\", \"VARCHAR2(4000)\"`\n", + "4. `metadata_json_column`: column name to store extra\n", + " JSON `metadata` of langchain document.\n", + " Default: `\"langchain_metadata\", \"VARCHAR2(4000)\"`.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "1Wqs05gpXMW9" + }, + "outputs": [], + "source": [ + "elcarro_engine.drop_document_table(TABLE_NAME)\n", + "elcarro_engine.init_document_table(\n", + " table_name=TABLE_NAME,\n", + " metadata_columns=[\n", + " sqlalchemy.Column(\"type\", sqlalchemy.dialects.oracle.VARCHAR2(200)),\n", + " sqlalchemy.Column(\"weight\", sqlalchemy.INT),\n", + " ],\n", + " content_column=\"content\",\n", + " metadata_json_column=\"extra_json_metadata\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bVEWHYU-XPFt" + }, + "source": [ + "Save documents with `ElCarroDocumentSaver.add_documents()`. As you\n", + "can see in this example,\n", + "\n", + "- `document.page_content` will be saved into `content` column.\n", + "- `document.metadata.type` will be saved into `type` column.\n", + "- `document.metadata.weight` will be saved into `weight` column.\n", + "- `document.metadata.organic` will be saved into `extra_json_metadata` column in\n", + " JSON format.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Iy4wRZLPXQn5" + }, + "outputs": [], + "source": [ + "doc = Document(\n", + " page_content=\"Banana\",\n", + " metadata={\"type\": \"fruit\", \"weight\": 100, \"organic\": 1},\n", + ")\n", + "\n", + "print(f\"Original Document: [{doc}]\")\n", + "\n", + "saver = ElCarroDocumentSaver(\n", + " elcarro_engine=elcarro_engine,\n", + " table_name=TABLE_NAME,\n", + " content_column=\"content\",\n", + " metadata_json_column=\"extra_json_metadata\",\n", + ")\n", + "saver.add_documents([doc])\n", + "\n", + "loader = ElCarroLoader(\n", + " elcarro_engine=elcarro_engine,\n", + " table_name=TABLE_NAME,\n", + " content_columns=[\"content\"],\n", + " metadata_columns=[\n", + " \"type\",\n", + " \"weight\",\n", + " ],\n", + " metadata_json_column=\"extra_json_metadata\",\n", + ")\n", + "\n", + "loaded_docs = loader.load()\n", + "print(f\"Loaded Document: [{loaded_docs[0]}]\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "x0vkL7PKXUmU" + }, + "source": [ + "### Delete documents with customized page content & metadata\n", + "\n", + "We can also delete documents from table with customized metadata columns\n", + "via `ElCarroDocumentSaver.delete()`. The deletion criteria is:\n", + "\n", + "A `row` should be deleted if there exists a `document` in the list, such that\n", + "\n", + "- `document.page_content` equals `row[page_content]`\n", + "- For every metadata field `k` in `document.metadata`\n", + " - `document.metadata[k]` equals `row[k]` or `document.metadata[k]`\n", + " equals `row[langchain_metadata][k]`\n", + "- There is no extra metadata field present in `row` but not\n", + " in `document.metadata`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "OcJPeCuKXWSa" + }, + "outputs": [], + "source": [ + "loader = ElCarroLoader(elcarro_engine=elcarro_engine, table_name=TABLE_NAME)\n", + "saver.delete(loader.load())\n", + "print(f\"Documents left: {len(loader.load())}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "S4SxUoY-XsPN" + }, + "source": [ + "## More examples\n", + "\n", + "Please look\n", + "at [demo_doc_loader_basic.py](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/samples/demo_doc_loader_basic.py)\n", + "and [demo_doc_loader_advanced.py](https://github.com/googleapis/langchain-google-el-carro-python/tree/main/samples/demo_doc_loader_advanced.py)\n", + "for\n", + "complete code examples.\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/docs/docs/integrations/document_loaders/google_speech_to_text.ipynb b/docs/docs/integrations/document_loaders/google_speech_to_text.ipynb index 35059fceb1d..fd17cea4fd1 100644 --- a/docs/docs/integrations/document_loaders/google_speech_to_text.ipynb +++ b/docs/docs/integrations/document_loaders/google_speech_to_text.ipynb @@ -198,8 +198,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.0" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/lakefs.ipynb b/docs/docs/integrations/document_loaders/lakefs.ipynb index c3bb31a7ee8..b15454414de 100644 --- a/docs/docs/integrations/document_loaders/lakefs.ipynb +++ b/docs/docs/integrations/document_loaders/lakefs.ipynb @@ -13,14 +13,14 @@ }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "## Initializing the lakeFS loader\n", "\n", "Replace `ENDPOINT`, `LAKEFS_ACCESS_KEY`, and `LAKEFS_SECRET_KEY` values with your own." - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", @@ -50,15 +50,15 @@ }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "## Specifying a path\n", "You can specify a prefix or a complete object path to control which files to load.\n", "\n", "Specify the repository, reference (branch, commit id, or tag), and path in the corresponding `REPO`, `REF`, and `PATH` to load the documents from:" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", diff --git a/docs/docs/integrations/document_loaders/llmsherpa.ipynb b/docs/docs/integrations/document_loaders/llmsherpa.ipynb index 1f11d17b62a..d84d66d6bb9 100644 --- a/docs/docs/integrations/document_loaders/llmsherpa.ipynb +++ b/docs/docs/integrations/document_loaders/llmsherpa.ipynb @@ -103,7 +103,9 @@ "outputs": [ { "data": { - "text/plain": "Document(page_content='Abstract\\nWe study how to apply large language models to write grounded and organized long-form articles from scratch, with comparable breadth and depth to Wikipedia pages.\\nThis underexplored problem poses new challenges at the pre-writing stage, including how to research the topic and prepare an outline prior to writing.\\nWe propose STORM, a writing system for the Synthesis of Topic Outlines through\\nReferences\\nFull-length Article\\nTopic\\nOutline\\n2022 Winter Olympics\\nOpening Ceremony\\nResearch via Question Asking\\nRetrieval and Multi-perspective Question Asking.\\nSTORM models the pre-writing stage by\\nLLM\\n(1) discovering diverse perspectives in researching the given topic, (2) simulating conversations where writers carrying different perspectives pose questions to a topic expert grounded on trusted Internet sources, (3) curating the collected information to create an outline.\\nFor evaluation, we curate FreshWiki, a dataset of recent high-quality Wikipedia articles, and formulate outline assessments to evaluate the pre-writing stage.\\nWe further gather feedback from experienced Wikipedia editors.\\nCompared to articles generated by an outlinedriven retrieval-augmented baseline, more of STORM’s articles are deemed to be organized (by a 25% absolute increase) and broad in coverage (by 10%).\\nThe expert feedback also helps identify new challenges for generating grounded long articles, such as source bias transfer and over-association of unrelated facts.\\n1. Can you provide any information about the transportation arrangements for the opening ceremony?\\nLLM\\n2. Can you provide any information about the budget for the 2022 Winter Olympics opening ceremony?…\\nLLM- Role1\\nLLM- Role2\\nLLM- Role1', metadata={'source': 'https://arxiv.org/pdf/2402.14207.pdf', 'section_number': 1, 'section_title': 'Abstract'})" + "text/plain": [ + "Document(page_content='Abstract\\nWe study how to apply large language models to write grounded and organized long-form articles from scratch, with comparable breadth and depth to Wikipedia pages.\\nThis underexplored problem poses new challenges at the pre-writing stage, including how to research the topic and prepare an outline prior to writing.\\nWe propose STORM, a writing system for the Synthesis of Topic Outlines through\\nReferences\\nFull-length Article\\nTopic\\nOutline\\n2022 Winter Olympics\\nOpening Ceremony\\nResearch via Question Asking\\nRetrieval and Multi-perspective Question Asking.\\nSTORM models the pre-writing stage by\\nLLM\\n(1) discovering diverse perspectives in researching the given topic, (2) simulating conversations where writers carrying different perspectives pose questions to a topic expert grounded on trusted Internet sources, (3) curating the collected information to create an outline.\\nFor evaluation, we curate FreshWiki, a dataset of recent high-quality Wikipedia articles, and formulate outline assessments to evaluate the pre-writing stage.\\nWe further gather feedback from experienced Wikipedia editors.\\nCompared to articles generated by an outlinedriven retrieval-augmented baseline, more of STORM’s articles are deemed to be organized (by a 25% absolute increase) and broad in coverage (by 10%).\\nThe expert feedback also helps identify new challenges for generating grounded long articles, such as source bias transfer and over-association of unrelated facts.\\n1. Can you provide any information about the transportation arrangements for the opening ceremony?\\nLLM\\n2. Can you provide any information about the budget for the 2022 Winter Olympics opening ceremony?…\\nLLM- Role1\\nLLM- Role2\\nLLM- Role1', metadata={'source': 'https://arxiv.org/pdf/2402.14207.pdf', 'section_number': 1, 'section_title': 'Abstract'})" + ] }, "execution_count": 6, "metadata": {}, @@ -128,7 +130,9 @@ "outputs": [ { "data": { - "text/plain": "79" + "text/plain": [ + "79" + ] }, "execution_count": 7, "metadata": {}, @@ -188,7 +192,9 @@ "outputs": [ { "data": { - "text/plain": "Document(page_content='Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models\\nStanford University {shaoyj, yuchengj, tkanell, peterxu, okhattab}@stanford.edu lam@cs.stanford.edu', metadata={'source': 'https://arxiv.org/pdf/2402.14207.pdf', 'chunk_number': 1, 'chunk_type': 'para'})" + "text/plain": [ + "Document(page_content='Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models\\nStanford University {shaoyj, yuchengj, tkanell, peterxu, okhattab}@stanford.edu lam@cs.stanford.edu', metadata={'source': 'https://arxiv.org/pdf/2402.14207.pdf', 'chunk_number': 1, 'chunk_type': 'para'})" + ] }, "execution_count": 9, "metadata": {}, @@ -213,7 +219,9 @@ "outputs": [ { "data": { - "text/plain": "306" + "text/plain": [ + "306" + ] }, "execution_count": 10, "metadata": {}, @@ -273,7 +281,9 @@ "outputs": [ { "data": { - "text/plain": "'

Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models

Yijia ShaoYucheng JiangTheodore A. KanellPeter Xu
Omar KhattabMonica S. Lam

Stanford University {shaoyj, yuchengj, '" + "text/plain": [ + "'

Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models

Yijia ShaoYucheng JiangTheodore A. KanellPeter Xu
Omar KhattabMonica S. Lam

Stanford University {shaoyj, yuchengj, '" + ] }, "execution_count": 12, "metadata": {}, @@ -298,7 +308,9 @@ "outputs": [ { "data": { - "text/plain": "1" + "text/plain": [ + "1" + ] }, "execution_count": 13, "metadata": {}, @@ -358,7 +370,9 @@ "outputs": [ { "data": { - "text/plain": "'Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models\\n | Yijia Shao | Yucheng Jiang | Theodore A. Kanell | Peter Xu\\n | --- | --- | --- | ---\\n | | Omar Khattab | Monica S. Lam | \\n\\nStanford University {shaoyj, yuchengj, tkanell, peterxu, okhattab}@stanford.edu lam@cs.stanford.edu\\nAbstract\\nWe study how to apply large language models to write grounded and organized long'" + "text/plain": [ + "'Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models\\n | Yijia Shao | Yucheng Jiang | Theodore A. Kanell | Peter Xu\\n | --- | --- | --- | ---\\n | | Omar Khattab | Monica S. Lam | \\n\\nStanford University {shaoyj, yuchengj, tkanell, peterxu, okhattab}@stanford.edu lam@cs.stanford.edu\\nAbstract\\nWe study how to apply large language models to write grounded and organized long'" + ] }, "execution_count": 3, "metadata": {}, @@ -383,7 +397,9 @@ "outputs": [ { "data": { - "text/plain": "1" + "text/plain": [ + "1" + ] }, "execution_count": 4, "metadata": {}, diff --git a/docs/docs/integrations/document_loaders/microsoft_sharepoint.ipynb b/docs/docs/integrations/document_loaders/microsoft_sharepoint.ipynb index 905a1e06d7c..930346675df 100644 --- a/docs/docs/integrations/document_loaders/microsoft_sharepoint.ipynb +++ b/docs/docs/integrations/document_loaders/microsoft_sharepoint.ipynb @@ -121,8 +121,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/news.ipynb b/docs/docs/integrations/document_loaders/news.ipynb index 4ad0ec2d8cd..a98ee7cfd23 100644 --- a/docs/docs/integrations/document_loaders/news.ipynb +++ b/docs/docs/integrations/document_loaders/news.ipynb @@ -81,13 +81,13 @@ }, { "cell_type": "markdown", - "source": [ - "Use nlp=True to run nlp analysis and generate keywords + summary" - ], + "id": "98ac26c488315bff", "metadata": { "collapsed": false }, - "id": "98ac26c488315bff" + "source": [ + "Use nlp=True to run nlp analysis and generate keywords + summary" + ] }, { "cell_type": "code", @@ -120,10 +120,34 @@ { "cell_type": "code", "execution_count": 5, + "id": "ae37e004e0284b1d", + "metadata": { + "ExecuteTime": { + "end_time": "2023-08-02T21:18:19.585758200Z", + "start_time": "2023-08-02T21:18:19.585758200Z" + }, + "collapsed": false + }, "outputs": [ { "data": { - "text/plain": "['powell',\n 'know',\n 'donald',\n 'trump',\n 'review',\n 'indictment',\n 'telling',\n 'view',\n 'reasonable',\n 'person',\n 'testimony',\n 'coconspirators',\n 'riot',\n 'representatives',\n 'claims']" + "text/plain": [ + "['powell',\n", + " 'know',\n", + " 'donald',\n", + " 'trump',\n", + " 'review',\n", + " 'indictment',\n", + " 'telling',\n", + " 'view',\n", + " 'reasonable',\n", + " 'person',\n", + " 'testimony',\n", + " 'coconspirators',\n", + " 'riot',\n", + " 'representatives',\n", + " 'claims']" + ] }, "execution_count": 5, "metadata": {}, @@ -132,23 +156,25 @@ ], "source": [ "data[0].metadata[\"keywords\"]" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-08-02T21:18:19.585758200Z", - "start_time": "2023-08-02T21:18:19.585758200Z" - } - }, - "id": "ae37e004e0284b1d" + ] }, { "cell_type": "code", "execution_count": 6, + "id": "7676155fb175e53e", + "metadata": { + "ExecuteTime": { + "end_time": "2023-08-02T21:18:19.598966800Z", + "start_time": "2023-08-02T21:18:19.594950200Z" + }, + "collapsed": false + }, "outputs": [ { "data": { - "text/plain": "'In testimony to the congressional committee examining the 6 January riot, Mrs Powell said she did not review all of the many claims of election fraud she made, telling them that \"no reasonable person\" would view her claims as fact.\\nNeither she nor her representatives have commented.'" + "text/plain": [ + "'In testimony to the congressional committee examining the 6 January riot, Mrs Powell said she did not review all of the many claims of election fraud she made, telling them that \"no reasonable person\" would view her claims as fact.\\nNeither she nor her representatives have commented.'" + ] }, "execution_count": 6, "metadata": {}, @@ -157,15 +183,7 @@ ], "source": [ "data[0].metadata[\"summary\"]" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2023-08-02T21:18:19.598966800Z", - "start_time": "2023-08-02T21:18:19.594950200Z" - } - }, - "id": "7676155fb175e53e" + ] } ], "metadata": { diff --git a/docs/docs/integrations/document_loaders/pebblo.ipynb b/docs/docs/integrations/document_loaders/pebblo.ipynb index ef73792ae0d..125a9744f35 100644 --- a/docs/docs/integrations/document_loaders/pebblo.ipynb +++ b/docs/docs/integrations/document_loaders/pebblo.ipynb @@ -32,7 +32,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders.csv_loader import CSVLoader\n", + "from langchain_community.document_loaders import CSVLoader\n", "\n", "loader = CSVLoader(\"data/corp_sens_data.csv\")\n", "documents = loader.load()\n", @@ -52,8 +52,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders.csv_loader import CSVLoader\n", - "from langchain_community.document_loaders import PebbloSafeLoader\n", + "from langchain_community.document_loaders import CSVLoader, PebbloSafeLoader\n", "\n", "loader = PebbloSafeLoader(\n", " CSVLoader(\"data/corp_sens_data.csv\"),\n", @@ -80,8 +79,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders.csv_loader import CSVLoader\n", - "from langchain_community.document_loaders import PebbloSafeLoader\n", + "from langchain_community.document_loaders import CSVLoader, PebbloSafeLoader\n", "\n", "loader = PebbloSafeLoader(\n", " CSVLoader(\"data/corp_sens_data.csv\"),\n", @@ -109,8 +107,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders.csv_loader import CSVLoader\n", - "from langchain_community.document_loaders import PebbloSafeLoader\n", + "from langchain_community.document_loaders import CSVLoader, PebbloSafeLoader\n", "\n", "loader = PebbloSafeLoader(\n", " CSVLoader(\"data/corp_sens_data.csv\"),\n", diff --git a/docs/docs/integrations/document_loaders/rockset.ipynb b/docs/docs/integrations/document_loaders/rockset.ipynb index 3d5ef33b5c3..37a1dc521c0 100644 --- a/docs/docs/integrations/document_loaders/rockset.ipynb +++ b/docs/docs/integrations/document_loaders/rockset.ipynb @@ -239,8 +239,7 @@ "language_info": { "name": "python", "version": "3.11.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_loaders/xml.ipynb b/docs/docs/integrations/document_loaders/xml.ipynb index beb8783d3b7..19135b2dfe0 100644 --- a/docs/docs/integrations/document_loaders/xml.ipynb +++ b/docs/docs/integrations/document_loaders/xml.ipynb @@ -27,14 +27,14 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "Document(page_content='United States\\n\\nWashington, DC\\n\\nJoe Biden\\n\\nBaseball\\n\\nCanada\\n\\nOttawa\\n\\nJustin Trudeau\\n\\nHockey\\n\\nFrance\\n\\nParis\\n\\nEmmanuel Macron\\n\\nSoccer\\n\\nTrinidad & Tobado\\n\\nPort of Spain\\n\\nKeith Rowley\\n\\nTrack & Field', metadata={'source': 'example_data/factbook.xml'})" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" + "data": { + "text/plain": [ + "Document(page_content='United States\\n\\nWashington, DC\\n\\nJoe Biden\\n\\nBaseball\\n\\nCanada\\n\\nOttawa\\n\\nJustin Trudeau\\n\\nHockey\\n\\nFrance\\n\\nParis\\n\\nEmmanuel Macron\\n\\nSoccer\\n\\nTrinidad & Tobado\\n\\nPort of Spain\\n\\nKeith Rowley\\n\\nTrack & Field', metadata={'source': 'example_data/factbook.xml'})" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ diff --git a/docs/docs/integrations/document_loaders/xorbits.ipynb b/docs/docs/integrations/document_loaders/xorbits.ipynb index 4af753db22e..217413f78d8 100644 --- a/docs/docs/integrations/document_loaders/xorbits.ipynb +++ b/docs/docs/integrations/document_loaders/xorbits.ipynb @@ -296,8 +296,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/document_transformers/cross_encoder_reranker.ipynb b/docs/docs/integrations/document_transformers/cross_encoder_reranker.ipynb index e680624b548..8dae12b1604 100644 --- a/docs/docs/integrations/document_transformers/cross_encoder_reranker.ipynb +++ b/docs/docs/integrations/document_transformers/cross_encoder_reranker.ipynb @@ -66,7 +66,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders import TextLoader\n", + "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores import FAISS\n", "from langchain_huggingface import HuggingFaceEmbeddings\n", "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", diff --git a/docs/docs/integrations/document_transformers/google_cloud_vertexai_rerank.ipynb b/docs/docs/integrations/document_transformers/google_cloud_vertexai_rerank.ipynb index ef3c811b737..c265d0d8bb5 100644 --- a/docs/docs/integrations/document_transformers/google_cloud_vertexai_rerank.ipynb +++ b/docs/docs/integrations/document_transformers/google_cloud_vertexai_rerank.ipynb @@ -646,8 +646,7 @@ ], "source": [ "from langchain.chains import LLMChain\n", - "from langchain.docstore.document import Document\n", - "from langchain.prompts import PromptTemplate\n", + "from langchain_core.documents import Document\n", "from langchain_core.prompts import PromptTemplate\n", "from langchain_core.runnables import RunnableParallel, RunnablePassthrough\n", "from langchain_google_vertexai import VertexAI\n", diff --git a/docs/docs/integrations/graphs/amazon_neptune_open_cypher.ipynb b/docs/docs/integrations/graphs/amazon_neptune_open_cypher.ipynb index 520ebc8a42a..d7a29746fac 100644 --- a/docs/docs/integrations/graphs/amazon_neptune_open_cypher.ipynb +++ b/docs/docs/integrations/graphs/amazon_neptune_open_cypher.ipynb @@ -12,8 +12,7 @@ ">\n", ">[Cypher](https://en.wikipedia.org/wiki/Cypher_(query_language)) is a declarative graph query language that allows for expressive and efficient data querying in a property graph.\n", ">\n", - ">[openCypher](https://opencypher.org/) is an open-source implementation of Cypher.", - "# Neptune Open Cypher QA Chain\n", + ">[openCypher](https://opencypher.org/) is an open-source implementation of Cypher.# Neptune Open Cypher QA Chain\n", "This QA chain queries Amazon Neptune using openCypher and returns human readable response\n", "\n", "LangChain supports both [Neptune Database](https://docs.aws.amazon.com/neptune/latest/userguide/intro.html) and [Neptune Analytics](https://docs.aws.amazon.com/neptune-analytics/latest/userguide/what-is-neptune-analytics.html) with `NeptuneOpenCypherQAChain` \n", diff --git a/docs/docs/integrations/graphs/azure_cosmosdb_gremlin.ipynb b/docs/docs/integrations/graphs/azure_cosmosdb_gremlin.ipynb index ebb1d639218..c6ac9dbf63d 100644 --- a/docs/docs/integrations/graphs/azure_cosmosdb_gremlin.ipynb +++ b/docs/docs/integrations/graphs/azure_cosmosdb_gremlin.ipynb @@ -66,9 +66,9 @@ "source": [ "import nest_asyncio\n", "from langchain.chains.graph_qa.gremlin import GremlinQAChain\n", - "from langchain.schema import Document\n", "from langchain_community.graphs import GremlinGraph\n", "from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship\n", + "from langchain_core.documents import Document\n", "from langchain_openai import AzureChatOpenAI" ] }, diff --git a/docs/docs/integrations/llms/ai21.ipynb b/docs/docs/integrations/llms/ai21.ipynb index 9db93083d59..72fbe840fe3 100644 --- a/docs/docs/integrations/llms/ai21.ipynb +++ b/docs/docs/integrations/llms/ai21.ipynb @@ -54,11 +54,11 @@ "execution_count": 5, "id": "035dea0f", "metadata": { - "tags": [], "ExecuteTime": { "end_time": "2024-03-05T20:58:44.465443Z", "start_time": "2024-03-05T20:58:42.399724Z" - } + }, + "tags": [] }, "outputs": [], "source": [ @@ -83,16 +83,18 @@ "execution_count": 6, "id": "98f70927a87e4745", "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-03-05T20:58:45.859265Z", "start_time": "2024-03-05T20:58:44.466637Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "'\\nLangChain is a (database)\\nLangChain is a database for storing and processing documents'" + "text/plain": [ + "'\\nLangChain is a (database)\\nLangChain is a database for storing and processing documents'" + ] }, "execution_count": 6, "metadata": {}, @@ -118,6 +120,10 @@ }, { "cell_type": "markdown", + "id": "9965c10269159ed1", + "metadata": { + "collapsed": false + }, "source": [ "# AI21 Contextual Answer\n", "\n", @@ -126,14 +132,19 @@ "\n", "This means that if the answer to your question is not in the document,\n", "the model will indicate it (instead of providing a false answer)" - ], - "metadata": { - "collapsed": false - }, - "id": "9965c10269159ed1" + ] }, { "cell_type": "code", + "execution_count": 9, + "id": "411adf42eab80829", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-05T20:59:00.943426Z", + "start_time": "2024-03-05T20:59:00.263497Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "from langchain_ai21 import AI21ContextualAnswers\n", @@ -141,29 +152,29 @@ "tsm = AI21ContextualAnswers()\n", "\n", "response = tsm.invoke(input={\"context\": \"Your context\", \"question\": \"Your question\"})" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-03-05T20:59:00.943426Z", - "start_time": "2024-03-05T20:59:00.263497Z" - } - }, - "id": "411adf42eab80829", - "execution_count": 9 + ] }, { "cell_type": "markdown", - "source": [ - "You can also use it with chains and output parsers and vector DBs" - ], + "id": "af59ffdbf4964875", "metadata": { "collapsed": false }, - "id": "af59ffdbf4964875" + "source": [ + "You can also use it with chains and output parsers and vector DBs" + ] }, { "cell_type": "code", + "execution_count": 10, + "id": "bc63830f921b4ac9", + "metadata": { + "ExecuteTime": { + "end_time": "2024-03-05T20:59:07.719225Z", + "start_time": "2024-03-05T20:59:07.102950Z" + }, + "collapsed": false + }, "outputs": [], "source": [ "from langchain_ai21 import AI21ContextualAnswers\n", @@ -175,16 +186,7 @@ "response = chain.invoke(\n", " {\"context\": \"Your context\", \"question\": \"Your question\"},\n", ")" - ], - "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-03-05T20:59:07.719225Z", - "start_time": "2024-03-05T20:59:07.102950Z" - } - }, - "id": "bc63830f921b4ac9", - "execution_count": 10 + ] } ], "metadata": { diff --git a/docs/docs/integrations/llms/azure_openai.ipynb b/docs/docs/integrations/llms/azure_openai.ipynb index 98c8ac18356..85a95912e0f 100644 --- a/docs/docs/integrations/llms/azure_openai.ipynb +++ b/docs/docs/integrations/llms/azure_openai.ipynb @@ -149,7 +149,9 @@ "outputs": [ { "data": { - "text/plain": "\" Why couldn't the bicycle stand up by itself?\\n\\nBecause it was two-tired!\"" + "text/plain": [ + "\" Why couldn't the bicycle stand up by itself?\\n\\nBecause it was two-tired!\"" + ] }, "execution_count": 5, "metadata": {}, @@ -179,7 +181,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001B[1mAzureOpenAI\u001B[0m\n", + "\u001b[1mAzureOpenAI\u001b[0m\n", "Params: {'deployment_name': 'gpt-35-turbo-instruct-0914', 'model_name': 'gpt-3.5-turbo-instruct', 'temperature': 0.7, 'top_p': 1, 'frequency_penalty': 0, 'presence_penalty': 0, 'n': 1, 'logit_bias': {}, 'max_tokens': 256}\n" ] } diff --git a/docs/docs/integrations/llms/baidu_qianfan_endpoint.ipynb b/docs/docs/integrations/llms/baidu_qianfan_endpoint.ipynb index aaedf7891cc..4f8a3cbf10e 100644 --- a/docs/docs/integrations/llms/baidu_qianfan_endpoint.ipynb +++ b/docs/docs/integrations/llms/baidu_qianfan_endpoint.ipynb @@ -254,7 +254,6 @@ "pygments_lexer": "ipython3", "version": "3.11.4" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "6fa70026b407ae751a5c9e6bd7f7d482379da8ad616f98512780b705c84ee157" diff --git a/docs/docs/integrations/llms/beam.ipynb b/docs/docs/integrations/llms/beam.ipynb index d9fe357e579..201365dcea4 100644 --- a/docs/docs/integrations/llms/beam.ipynb +++ b/docs/docs/integrations/llms/beam.ipynb @@ -167,4 +167,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/llms/bedrock.ipynb b/docs/docs/integrations/llms/bedrock.ipynb index e32d5fa840d..2da8a3ff9e7 100644 --- a/docs/docs/integrations/llms/bedrock.ipynb +++ b/docs/docs/integrations/llms/bedrock.ipynb @@ -83,8 +83,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain_community.llms import Bedrock\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "\n", "llm = Bedrock(\n", " credentials_profile_name=\"bedrock-admin\",\n", diff --git a/docs/docs/integrations/llms/bittensor.ipynb b/docs/docs/integrations/llms/bittensor.ipynb index 89981589c7b..664e786de3a 100644 --- a/docs/docs/integrations/llms/bittensor.ipynb +++ b/docs/docs/integrations/llms/bittensor.ipynb @@ -118,8 +118,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.tools import Tool\n", "from langchain_community.utilities import GoogleSearchAPIWrapper\n", + "from langchain_core.tools import Tool\n", "\n", "search = GoogleSearchAPIWrapper()\n", "\n", diff --git a/docs/docs/integrations/llms/chatglm.ipynb b/docs/docs/integrations/llms/chatglm.ipynb index 645f880b3a2..f6904f21d85 100644 --- a/docs/docs/integrations/llms/chatglm.ipynb +++ b/docs/docs/integrations/llms/chatglm.ipynb @@ -41,8 +41,8 @@ "outputs": [], "source": [ "from langchain.chains import LLMChain\n", - "from langchain.schema.messages import AIMessage\n", "from langchain_community.llms.chatglm3 import ChatGLM3\n", + "from langchain_core.messages import AIMessage\n", "from langchain_core.prompts import PromptTemplate" ] }, diff --git a/docs/docs/integrations/llms/cloudflare_workersai.ipynb b/docs/docs/integrations/llms/cloudflare_workersai.ipynb index b90bfb31369..5c6652eb336 100644 --- a/docs/docs/integrations/llms/cloudflare_workersai.ipynb +++ b/docs/docs/integrations/llms/cloudflare_workersai.ipynb @@ -119,8 +119,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/llms/ctransformers.ipynb b/docs/docs/integrations/llms/ctransformers.ipynb index ce7bbce11fe..afc774e046c 100644 --- a/docs/docs/integrations/llms/ctransformers.ipynb +++ b/docs/docs/integrations/llms/ctransformers.ipynb @@ -79,7 +79,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "\n", "llm = CTransformers(\n", " model=\"marella/gpt-2-ggml\", callbacks=[StreamingStdOutCallbackHandler()]\n", @@ -120,8 +120,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/llms/ctranslate2.ipynb b/docs/docs/integrations/llms/ctranslate2.ipynb index 3f177af52c3..352ed078d84 100644 --- a/docs/docs/integrations/llms/ctranslate2.ipynb +++ b/docs/docs/integrations/llms/ctranslate2.ipynb @@ -229,7 +229,6 @@ "pygments_lexer": "ipython3", "version": "3.10.12" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d1d3a3c58a58885896c5459933a599607cdbb9917d7e1ad7516c8786c51f2dd2" diff --git a/docs/docs/integrations/llms/databricks.ipynb b/docs/docs/integrations/llms/databricks.ipynb index 7531c781025..b4ebef8bf3a 100644 --- a/docs/docs/integrations/llms/databricks.ipynb +++ b/docs/docs/integrations/llms/databricks.ipynb @@ -298,8 +298,7 @@ { "attachments": {}, "cell_type": "markdown", - "metadata": { - }, + "metadata": {}, "source": [ "## Wrapping a cluster driver proxy app\n", "\n", diff --git a/docs/docs/integrations/llms/edenai.ipynb b/docs/docs/integrations/llms/edenai.ipynb index be68b1275d7..30a3d9ea5c6 100644 --- a/docs/docs/integrations/llms/edenai.ipynb +++ b/docs/docs/integrations/llms/edenai.ipynb @@ -189,8 +189,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain_community.llms import EdenAI\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "\n", "llm = EdenAI(\n", " callbacks=[StreamingStdOutCallbackHandler()],\n", diff --git a/docs/docs/integrations/llms/gpt4all.ipynb b/docs/docs/integrations/llms/gpt4all.ipynb index 3a1b084e2f3..3188379b211 100644 --- a/docs/docs/integrations/llms/gpt4all.ipynb +++ b/docs/docs/integrations/llms/gpt4all.ipynb @@ -47,9 +47,9 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain.chains import LLMChain\n", "from langchain_community.llms import GPT4All\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "from langchain_core.prompts import PromptTemplate" ] }, diff --git a/docs/docs/integrations/llms/huggingface_endpoint.ipynb b/docs/docs/integrations/llms/huggingface_endpoint.ipynb index 37c7bb373b7..fbb5f8ee9f0 100644 --- a/docs/docs/integrations/llms/huggingface_endpoint.ipynb +++ b/docs/docs/integrations/llms/huggingface_endpoint.ipynb @@ -192,7 +192,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "from langchain_huggingface import HuggingFaceEndpoint\n", "\n", "llm = HuggingFaceEndpoint(\n", diff --git a/docs/docs/integrations/llms/jsonformer_experimental.ipynb b/docs/docs/integrations/llms/jsonformer_experimental.ipynb index 066418c97ff..787bec92ed9 100644 --- a/docs/docs/integrations/llms/jsonformer_experimental.ipynb +++ b/docs/docs/integrations/llms/jsonformer_experimental.ipynb @@ -63,7 +63,7 @@ "import os\n", "\n", "import requests\n", - "from langchain.tools import tool\n", + "from langchain_core.tools import tool\n", "\n", "HF_TOKEN = os.environ.get(\"HUGGINGFACE_API_KEY\")\n", "\n", diff --git a/docs/docs/integrations/llms/llm_caching.ipynb b/docs/docs/integrations/llms/llm_caching.ipynb index 10de9275d42..1bf260e69b5 100644 --- a/docs/docs/integrations/llms/llm_caching.ipynb +++ b/docs/docs/integrations/llms/llm_caching.ipynb @@ -46,7 +46,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.cache import InMemoryCache\n", + "from langchain_community.cache import InMemoryCache\n", "\n", "set_llm_cache(InMemoryCache())" ] @@ -141,7 +141,7 @@ "outputs": [], "source": [ "# We can do the same thing with a SQLite cache\n", - "from langchain.cache import SQLiteCache\n", + "from langchain_community.cache import SQLiteCache\n", "\n", "set_llm_cache(SQLiteCache(database_path=\".langchain.db\"))" ] @@ -235,7 +235,7 @@ "outputs": [], "source": [ "import langchain\n", - "from langchain.cache import UpstashRedisCache\n", + "from langchain_community.cache import UpstashRedisCache\n", "from upstash_redis import Redis\n", "\n", "URL = \"\"\n", @@ -335,7 +335,7 @@ "source": [ "# We can do the same thing with a Redis cache\n", "# (make sure your local Redis instance is running first before running this example)\n", - "from langchain.cache import RedisCache\n", + "from langchain_community.cache import RedisCache\n", "from redis import Redis\n", "\n", "set_llm_cache(RedisCache(redis_=Redis()))" @@ -419,7 +419,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.cache import RedisSemanticCache\n", + "from langchain_community.cache import RedisSemanticCache\n", "from langchain_openai import OpenAIEmbeddings\n", "\n", "set_llm_cache(\n", @@ -517,7 +517,7 @@ "from gptcache import Cache\n", "from gptcache.manager.factory import manager_factory\n", "from gptcache.processor.pre import get_prompt\n", - "from langchain.cache import GPTCache\n", + "from langchain_community.cache import GPTCache\n", "\n", "\n", "def get_hashed_name(name):\n", @@ -616,7 +616,7 @@ "\n", "from gptcache import Cache\n", "from gptcache.adapter.api import init_similar_cache\n", - "from langchain.cache import GPTCache\n", + "from langchain_community.cache import GPTCache\n", "\n", "\n", "def get_hashed_name(name):\n", @@ -765,7 +765,7 @@ "source": [ "from datetime import timedelta\n", "\n", - "from langchain.cache import MomentoCache\n", + "from langchain_community.cache import MomentoCache\n", "\n", "cache_name = \"langchain\"\n", "ttl = timedelta(days=1)\n", @@ -879,7 +879,7 @@ "source": [ "# You can define your own declarative SQLAlchemyCache child class to customize the schema used for caching. For example, to support high-speed fulltext prompt indexing with Postgres, use:\n", "\n", - "from langchain.cache import SQLAlchemyCache\n", + "from langchain_community.cache import SQLAlchemyCache\n", "from sqlalchemy import Column, Computed, Index, Integer, Sequence, String, create_engine\n", "from sqlalchemy.ext.declarative import declarative_base\n", "from sqlalchemy_utils import TSVectorType\n", @@ -1296,8 +1296,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.cache import AstraDBCache\n", "from langchain.globals import set_llm_cache\n", + "from langchain_astradb import AstraDBCache\n", "\n", "set_llm_cache(\n", " AstraDBCache(\n", @@ -1384,7 +1384,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.cache import AstraDBSemanticCache\n", + "from langchain_astradb import AstraDBSemanticCache\n", "\n", "set_llm_cache(\n", " AstraDBSemanticCache(\n", @@ -1868,7 +1868,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "docs = [Document(page_content=t) for t in texts[:3]]\n", "from langchain.chains.summarize import load_summarize_chain" diff --git a/docs/docs/integrations/llms/minimax.ipynb b/docs/docs/integrations/llms/minimax.ipynb index a43cf79f93e..fcdd330deb1 100644 --- a/docs/docs/integrations/llms/minimax.ipynb +++ b/docs/docs/integrations/llms/minimax.ipynb @@ -169,8 +169,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/llms/moonshot.ipynb b/docs/docs/integrations/llms/moonshot.ipynb index 849bb2d2034..405725e20fa 100644 --- a/docs/docs/integrations/llms/moonshot.ipynb +++ b/docs/docs/integrations/llms/moonshot.ipynb @@ -77,8 +77,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/llms/oci_generative_ai.ipynb b/docs/docs/integrations/llms/oci_generative_ai.ipynb index 40332f13e1c..0c2368efdc2 100644 --- a/docs/docs/integrations/llms/oci_generative_ai.ipynb +++ b/docs/docs/integrations/llms/oci_generative_ai.ipynb @@ -117,10 +117,10 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema.output_parser import StrOutputParser\n", - "from langchain.schema.runnable import RunnablePassthrough\n", "from langchain_community.embeddings import OCIGenAIEmbeddings\n", "from langchain_community.vectorstores import FAISS\n", + "from langchain_core.output_parsers import StrOutputParser\n", + "from langchain_core.runnables import RunnablePassthrough\n", "\n", "embeddings = OCIGenAIEmbeddings(\n", " model_id=\"MY_EMBEDDING_MODEL\",\n", diff --git a/docs/docs/integrations/llms/opaqueprompts.ipynb b/docs/docs/integrations/llms/opaqueprompts.ipynb index 272ebfd89ae..6181d8c1a87 100644 --- a/docs/docs/integrations/llms/opaqueprompts.ipynb +++ b/docs/docs/integrations/llms/opaqueprompts.ipynb @@ -58,11 +58,11 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.stdout import StdOutCallbackHandler\n", "from langchain.chains import LLMChain\n", "from langchain.globals import set_debug, set_verbose\n", "from langchain.memory import ConversationBufferWindowMemory\n", "from langchain_community.llms import OpaquePrompts\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_core.prompts import PromptTemplate\n", "from langchain_openai import OpenAI\n", "\n", diff --git a/docs/docs/integrations/llms/predibase.ipynb b/docs/docs/integrations/llms/predibase.ipynb index 50523094694..82ffeddda12 100644 --- a/docs/docs/integrations/llms/predibase.ipynb +++ b/docs/docs/integrations/llms/predibase.ipynb @@ -291,7 +291,6 @@ "pygments_lexer": "ipython3", "version": "3.8.9" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" diff --git a/docs/docs/integrations/llms/predictionguard.ipynb b/docs/docs/integrations/llms/predictionguard.ipynb index e5a632257d0..3a8020b220b 100644 --- a/docs/docs/integrations/llms/predictionguard.ipynb +++ b/docs/docs/integrations/llms/predictionguard.ipynb @@ -250,4 +250,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/llms/replicate.ipynb b/docs/docs/integrations/llms/replicate.ipynb index 4b7068364ed..1c10cf13300 100644 --- a/docs/docs/integrations/llms/replicate.ipynb +++ b/docs/docs/integrations/llms/replicate.ipynb @@ -311,7 +311,7 @@ } ], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "\n", "llm = Replicate(\n", " streaming=True,\n", diff --git a/docs/docs/integrations/llms/sagemaker.ipynb b/docs/docs/integrations/llms/sagemaker.ipynb index 122339077f9..387f91f2edd 100644 --- a/docs/docs/integrations/llms/sagemaker.ipynb +++ b/docs/docs/integrations/llms/sagemaker.ipynb @@ -58,7 +58,7 @@ }, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document" + "from langchain_core.documents import Document" ] }, { diff --git a/docs/docs/integrations/llms/sparkllm.ipynb b/docs/docs/integrations/llms/sparkllm.ipynb index 63642a81c77..24e79b90cb3 100644 --- a/docs/docs/integrations/llms/sparkllm.ipynb +++ b/docs/docs/integrations/llms/sparkllm.ipynb @@ -81,7 +81,9 @@ "outputs": [ { "data": { - "text/plain": "LLMResult(generations=[[Generation(text='Hello! How can I assist you today?')]], llm_output=None, run=[RunInfo(run_id=UUID('d8cdcd41-a698-4cbf-a28d-e74f9cd2037b'))])" + "text/plain": [ + "LLMResult(generations=[[Generation(text='Hello! How can I assist you today?')]], llm_output=None, run=[RunInfo(run_id=UUID('d8cdcd41-a698-4cbf-a28d-e74f9cd2037b'))])" + ] }, "execution_count": 9, "metadata": {}, diff --git a/docs/docs/integrations/llms/textgen.ipynb b/docs/docs/integrations/llms/textgen.ipynb index 1a31298e16d..09211a3158e 100644 --- a/docs/docs/integrations/llms/textgen.ipynb +++ b/docs/docs/integrations/llms/textgen.ipynb @@ -91,10 +91,10 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain.chains import LLMChain\n", "from langchain.globals import set_debug\n", "from langchain_community.llms import TextGen\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "from langchain_core.prompts import PromptTemplate\n", "\n", "set_debug(True)\n", diff --git a/docs/docs/integrations/llms/titan_takeoff.ipynb b/docs/docs/integrations/llms/titan_takeoff.ipynb index 57a3d3679e3..cc38e8c2fc8 100644 --- a/docs/docs/integrations/llms/titan_takeoff.ipynb +++ b/docs/docs/integrations/llms/titan_takeoff.ipynb @@ -29,11 +29,9 @@ "source": [ "import time\n", "\n", - "from langchain.callbacks.manager import CallbackManager\n", - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", - "\n", "# Note importing TitanTakeoffPro instead of TitanTakeoff will work as well both use same object under the hood\n", "from langchain_community.llms import TitanTakeoff\n", + "from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler\n", "from langchain_core.prompts import PromptTemplate" ] }, diff --git a/docs/docs/integrations/llms/volcengine_maas.ipynb b/docs/docs/integrations/llms/volcengine_maas.ipynb index 813f63e93e5..2d3bc4105f9 100644 --- a/docs/docs/integrations/llms/volcengine_maas.ipynb +++ b/docs/docs/integrations/llms/volcengine_maas.ipynb @@ -87,7 +87,9 @@ "outputs": [ { "data": { - "text/plain": "'好的,下面是一个笑话:\\n\\n大学暑假我配了隐形眼镜,回家给爷爷说,我现在配了隐形眼镜。\\n爷爷让我给他看看,于是,我用小镊子夹了一片给爷爷看。\\n爷爷看完便准备出门,边走还边说:“真高级啊,还真是隐形眼镜!”\\n等爷爷出去后我才发现,我刚没夹起来!'" + "text/plain": [ + "'好的,下面是一个笑话:\\n\\n大学暑假我配了隐形眼镜,回家给爷爷说,我现在配了隐形眼镜。\\n爷爷让我给他看看,于是,我用小镊子夹了一片给爷爷看。\\n爷爷看完便准备出门,边走还边说:“真高级啊,还真是隐形眼镜!”\\n等爷爷出去后我才发现,我刚没夹起来!'" + ] }, "execution_count": 8, "metadata": {}, diff --git a/docs/docs/integrations/llms/xinference.ipynb b/docs/docs/integrations/llms/xinference.ipynb index 714db52a43b..9760f1d07d4 100644 --- a/docs/docs/integrations/llms/xinference.ipynb +++ b/docs/docs/integrations/llms/xinference.ipynb @@ -168,8 +168,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/llms/yuan2.ipynb b/docs/docs/integrations/llms/yuan2.ipynb index 86d1c059571..79998911ea4 100644 --- a/docs/docs/integrations/llms/yuan2.ipynb +++ b/docs/docs/integrations/llms/yuan2.ipynb @@ -113,4 +113,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/memory/zep_memory.ipynb b/docs/docs/integrations/memory/zep_memory.ipynb index c7a1f778c5b..02f9775ab86 100644 --- a/docs/docs/integrations/memory/zep_memory.ipynb +++ b/docs/docs/integrations/memory/zep_memory.ipynb @@ -2,6 +2,9 @@ "cells": [ { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "# Zep\n", "> Recall, understand, and extract data from chat histories. Power personalized AI experiences.\n", @@ -29,10 +32,7 @@ "2. Running an agent and having message automatically added to the store.\n", "3. Viewing the enriched messages.\n", "4. Vector search over the conversation history." - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", @@ -47,11 +47,12 @@ "source": [ "from uuid import uuid4\n", "\n", - "from langchain.agents import AgentType, Tool, initialize_agent\n", + "from langchain.agents import AgentType, initialize_agent\n", "from langchain.memory import ZepMemory\n", - "from langchain.retrievers import ZepRetriever\n", + "from langchain_community.retrievers import ZepRetriever\n", "from langchain_community.utilities import WikipediaAPIWrapper\n", "from langchain_core.messages import AIMessage, HumanMessage\n", + "from langchain_core.tools import Tool\n", "from langchain_openai import OpenAI\n", "\n", "# Set this to your Zep server URL\n", @@ -257,11 +258,11 @@ "text": [ "\n", "\n", - "\u001B[1m> Entering new chain...\u001B[0m\n", - "\u001B[32;1m\u001B[1;3mThought: Do I need to use a tool? No\n", - "AI: Parable of the Sower is a prescient novel that speaks to the challenges facing contemporary society, such as climate change, inequality, and violence. It is a cautionary tale that warns of the dangers of unchecked greed and the need for individuals to take responsibility for their own lives and the lives of those around them.\u001B[0m\n", + "\u001b[1m> Entering new chain...\u001b[0m\n", + "\u001b[32;1m\u001b[1;3mThought: Do I need to use a tool? No\n", + "AI: Parable of the Sower is a prescient novel that speaks to the challenges facing contemporary society, such as climate change, inequality, and violence. It is a cautionary tale that warns of the dangers of unchecked greed and the need for individuals to take responsibility for their own lives and the lives of those around them.\u001b[0m\n", "\n", - "\u001B[1m> Finished chain.\u001B[0m\n" + "\u001b[1m> Finished chain.\u001b[0m\n" ] }, { diff --git a/docs/docs/integrations/providers/aim_tracking.ipynb b/docs/docs/integrations/providers/aim_tracking.ipynb index cadf2ba1f85..e078a349f8b 100644 --- a/docs/docs/integrations/providers/aim_tracking.ipynb +++ b/docs/docs/integrations/providers/aim_tracking.ipynb @@ -65,7 +65,8 @@ "import os\n", "from datetime import datetime\n", "\n", - "from langchain.callbacks import AimCallbackHandler, StdOutCallbackHandler\n", + "from langchain_community.callbacks import AimCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_openai import OpenAI" ] }, @@ -307,4 +308,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/providers/arthur_tracking.ipynb b/docs/docs/integrations/providers/arthur_tracking.ipynb index 17f1697ec76..c9d7a773dbb 100644 --- a/docs/docs/integrations/providers/arthur_tracking.ipynb +++ b/docs/docs/integrations/providers/arthur_tracking.ipynb @@ -55,8 +55,8 @@ }, "outputs": [], "source": [ - "from langchain.callbacks import ArthurCallbackHandler\n", - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", + "from langchain_community.callbacks import ArthurCallbackHandler\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "from langchain_core.messages import HumanMessage\n", "from langchain_openai import ChatOpenAI" ] diff --git a/docs/docs/integrations/providers/clearml_tracking.ipynb b/docs/docs/integrations/providers/clearml_tracking.ipynb index 0ee932a4b80..e08b3e9928a 100644 --- a/docs/docs/integrations/providers/clearml_tracking.ipynb +++ b/docs/docs/integrations/providers/clearml_tracking.ipynb @@ -88,7 +88,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks import ClearMLCallbackHandler" + "from langchain_community.callbacks import ClearMLCallbackHandler" ] }, { @@ -105,7 +105,7 @@ } ], "source": [ - "from langchain.callbacks import StdOutCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_openai import OpenAI\n", "\n", "# Setup and use the ClearML Callback\n", diff --git a/docs/docs/integrations/providers/comet_tracking.ipynb b/docs/docs/integrations/providers/comet_tracking.ipynb index 67e427bd235..e8752aed96c 100644 --- a/docs/docs/integrations/providers/comet_tracking.ipynb +++ b/docs/docs/integrations/providers/comet_tracking.ipynb @@ -121,7 +121,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks import CometCallbackHandler, StdOutCallbackHandler\n", + "from langchain_community.callbacks import CometCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_openai import OpenAI\n", "\n", "comet_callback = CometCallbackHandler(\n", @@ -152,8 +153,9 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks import CometCallbackHandler, StdOutCallbackHandler\n", "from langchain.chains import LLMChain\n", + "from langchain_community.callbacks import CometCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_core.prompts import PromptTemplate\n", "from langchain_openai import OpenAI\n", "\n", @@ -191,7 +193,8 @@ "outputs": [], "source": [ "from langchain.agents import initialize_agent, load_tools\n", - "from langchain.callbacks import CometCallbackHandler, StdOutCallbackHandler\n", + "from langchain_community.callbacks import CometCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_openai import OpenAI\n", "\n", "comet_callback = CometCallbackHandler(\n", @@ -249,8 +252,9 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks import CometCallbackHandler, StdOutCallbackHandler\n", "from langchain.chains import LLMChain\n", + "from langchain_community.callbacks import CometCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_core.prompts import PromptTemplate\n", "from langchain_openai import OpenAI\n", "from rouge_score import rouge_scorer\n", @@ -339,7 +343,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks.tracers.comet import CometTracer" + "from langchain_community.callbacks.tracers.comet import CometTracer" ] } ], diff --git a/docs/docs/integrations/providers/dspy.ipynb b/docs/docs/integrations/providers/dspy.ipynb index 6929d9477ed..6f7b75b649d 100644 --- a/docs/docs/integrations/providers/dspy.ipynb +++ b/docs/docs/integrations/providers/dspy.ipynb @@ -75,8 +75,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.cache import SQLiteCache\n", "from langchain.globals import set_llm_cache\n", + "from langchain_community.cache import SQLiteCache\n", "from langchain_openai import OpenAI\n", "\n", "set_llm_cache(SQLiteCache(database_path=\"cache.db\"))\n", diff --git a/docs/docs/integrations/providers/mlflow_tracking.ipynb b/docs/docs/integrations/providers/mlflow_tracking.ipynb index bc1ace7b690..7461e71837e 100644 --- a/docs/docs/integrations/providers/mlflow_tracking.ipynb +++ b/docs/docs/integrations/providers/mlflow_tracking.ipynb @@ -77,7 +77,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.callbacks import MlflowCallbackHandler\n", + "from langchain_community.callbacks import MlflowCallbackHandler\n", "from langchain_openai import OpenAI" ] }, diff --git a/docs/docs/integrations/providers/ray_serve.ipynb b/docs/docs/integrations/providers/ray_serve.ipynb index 20d3ac7489f..583d9f7108b 100644 --- a/docs/docs/integrations/providers/ray_serve.ipynb +++ b/docs/docs/integrations/providers/ray_serve.ipynb @@ -227,8 +227,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/providers/rebuff.ipynb b/docs/docs/integrations/providers/rebuff.ipynb index 259c2d22525..0c9dd875882 100644 --- a/docs/docs/integrations/providers/rebuff.ipynb +++ b/docs/docs/integrations/providers/rebuff.ipynb @@ -177,7 +177,7 @@ "outputs": [], "source": [ "from langchain.chains import SimpleSequentialChain, TransformChain\n", - "from langchain.sql_database import SQLDatabase\n", + "from langchain_community.utilities import SQLDatabase\n", "from langchain_experimental.sql import SQLDatabaseChain" ] }, diff --git a/docs/docs/integrations/providers/vectara/vectara_chat.ipynb b/docs/docs/integrations/providers/vectara/vectara_chat.ipynb index 1debc3ae854..eae68110834 100644 --- a/docs/docs/integrations/providers/vectara/vectara_chat.ipynb +++ b/docs/docs/integrations/providers/vectara/vectara_chat.ipynb @@ -592,13 +592,13 @@ }, "outputs": [], "source": [ - "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n", "from langchain.chains.conversational_retrieval.prompts import (\n", " CONDENSE_QUESTION_PROMPT,\n", " QA_PROMPT,\n", ")\n", "from langchain.chains.llm import LLMChain\n", "from langchain.chains.question_answering import load_qa_chain\n", + "from langchain_core.callbacks import StreamingStdOutCallbackHandler\n", "\n", "# Construct a ConversationalRetrievalChain with a streaming llm for combine docs\n", "# and a separate, non-streaming llm for question generation\n", diff --git a/docs/docs/integrations/providers/wandb_tracing.ipynb b/docs/docs/integrations/providers/wandb_tracing.ipynb index 5d8aa57d14c..89b0dd8d3b7 100644 --- a/docs/docs/integrations/providers/wandb_tracing.ipynb +++ b/docs/docs/integrations/providers/wandb_tracing.ipynb @@ -30,6 +30,8 @@ "source": [ "import os\n", "\n", + "from langchain_community.callbacks import wandb_tracing_enabled\n", + "\n", "os.environ[\"LANGCHAIN_WANDB_TRACING\"] = \"true\"\n", "\n", "# wandb documentation to configure wandb using env variables\n", @@ -38,7 +40,6 @@ "os.environ[\"WANDB_PROJECT\"] = \"langchain-tracing\"\n", "\n", "from langchain.agents import AgentType, initialize_agent, load_tools\n", - "from langchain.callbacks import wandb_tracing_enabled\n", "from langchain_openai import OpenAI" ] }, diff --git a/docs/docs/integrations/providers/wandb_tracking.ipynb b/docs/docs/integrations/providers/wandb_tracking.ipynb index b836d1af067..5f034619867 100644 --- a/docs/docs/integrations/providers/wandb_tracking.ipynb +++ b/docs/docs/integrations/providers/wandb_tracking.ipynb @@ -62,7 +62,8 @@ "source": [ "from datetime import datetime\n", "\n", - "from langchain.callbacks import StdOutCallbackHandler, WandbCallbackHandler\n", + "from langchain_community.callbacks import WandbCallbackHandler\n", + "from langchain_core.callbacks import StdOutCallbackHandler\n", "from langchain_openai import OpenAI" ] }, diff --git a/docs/docs/integrations/providers/whylabs_profiling.ipynb b/docs/docs/integrations/providers/whylabs_profiling.ipynb index cc295b34022..1f4802220c8 100644 --- a/docs/docs/integrations/providers/whylabs_profiling.ipynb +++ b/docs/docs/integrations/providers/whylabs_profiling.ipynb @@ -83,7 +83,7 @@ }, "outputs": [], "source": [ - "from langchain.callbacks import WhyLabsCallbackHandler" + "from langchain_community.callbacks import WhyLabsCallbackHandler" ] }, { diff --git a/docs/docs/integrations/retrievers/azure_ai_search.ipynb b/docs/docs/integrations/retrievers/azure_ai_search.ipynb index 6b2b32afb6b..d978884dee7 100644 --- a/docs/docs/integrations/retrievers/azure_ai_search.ipynb +++ b/docs/docs/integrations/retrievers/azure_ai_search.ipynb @@ -151,11 +151,11 @@ "source": [ "import os\n", "\n", - "from langchain.document_loaders import DirectoryLoader, TextLoader\n", - "from langchain.text_splitter import TokenTextSplitter\n", - "from langchain.vectorstores import AzureSearch\n", + "from langchain_community.document_loaders import DirectoryLoader, TextLoader\n", "from langchain_community.retrievers import AzureAISearchRetriever\n", + "from langchain_community.vectorstores import AzureSearch\n", "from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings\n", + "from langchain_text_splitters import TokenTextSplitter\n", "\n", "os.environ[\"AZURE_AI_SEARCH_SERVICE_NAME\"] = \"\"\n", "os.environ[\"AZURE_AI_SEARCH_INDEX_NAME\"] = \"langchain-vector-demo\"\n", diff --git a/docs/docs/integrations/retrievers/chatgpt-plugin.ipynb b/docs/docs/integrations/retrievers/chatgpt-plugin.ipynb index 13c782983a9..485827823fd 100644 --- a/docs/docs/integrations/retrievers/chatgpt-plugin.ipynb +++ b/docs/docs/integrations/retrievers/chatgpt-plugin.ipynb @@ -32,6 +32,7 @@ "# This is from https://langchain.readthedocs.io/en/latest/modules/document_loaders/examples/csv.html\n", "\n", "from langchain_community.document_loaders import CSVLoader\n", + "from langchain_core.documents import Document\n", "\n", "loader = CSVLoader(\n", " file_path=\"../../document_loaders/examples/example_data/mlb_teams_2012.csv\"\n", @@ -45,8 +46,6 @@ "import json\n", "from typing import List\n", "\n", - "from langchain_community.docstore.document import Document\n", - "\n", "\n", "def write_json(path: str, documents: List[Document]) -> None:\n", " results = [{\"text\": doc.page_content} for doc in documents]\n", diff --git a/docs/docs/integrations/retrievers/docarray_retriever.ipynb b/docs/docs/integrations/retrievers/docarray_retriever.ipynb index 162d7914ece..25a89613fad 100644 --- a/docs/docs/integrations/retrievers/docarray_retriever.ipynb +++ b/docs/docs/integrations/retrievers/docarray_retriever.ipynb @@ -647,7 +647,7 @@ } ], "source": [ - "from langchain.retrievers import DocArrayRetriever\n", + "from langchain_community.retrievers import DocArrayRetriever\n", "\n", "# create a retriever\n", "retriever = DocArrayRetriever(\n", @@ -687,7 +687,7 @@ } ], "source": [ - "from langchain.retrievers import DocArrayRetriever\n", + "from langchain_community.retrievers import DocArrayRetriever\n", "\n", "# create a retriever\n", "retriever = DocArrayRetriever(\n", @@ -729,7 +729,7 @@ } ], "source": [ - "from langchain.retrievers import DocArrayRetriever\n", + "from langchain_community.retrievers import DocArrayRetriever\n", "\n", "# create a retriever\n", "retriever = DocArrayRetriever(\n", diff --git a/docs/docs/integrations/retrievers/elasticsearch_retriever.ipynb b/docs/docs/integrations/retrievers/elasticsearch_retriever.ipynb index e24914a80ce..2343aacf5de 100644 --- a/docs/docs/integrations/retrievers/elasticsearch_retriever.ipynb +++ b/docs/docs/integrations/retrievers/elasticsearch_retriever.ipynb @@ -37,7 +37,7 @@ "\n", "from elasticsearch import Elasticsearch\n", "from elasticsearch.helpers import bulk\n", - "from langchain.embeddings import DeterministicFakeEmbedding\n", + "from langchain_community.embeddings import DeterministicFakeEmbedding\n", "from langchain_core.documents import Document\n", "from langchain_core.embeddings import Embeddings\n", "from langchain_elasticsearch import ElasticsearchRetriever" diff --git a/docs/docs/integrations/retrievers/kinetica.ipynb b/docs/docs/integrations/retrievers/kinetica.ipynb index c045fb982a1..79aaa63ad90 100644 --- a/docs/docs/integrations/retrievers/kinetica.ipynb +++ b/docs/docs/integrations/retrievers/kinetica.ipynb @@ -62,14 +62,14 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.docstore.document import Document\n", - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores import (\n", " Kinetica,\n", " KineticaSettings,\n", ")\n", - "from langchain_openai import OpenAIEmbeddings" + "from langchain_core.documents import Document\n", + "from langchain_openai import OpenAIEmbeddings\n", + "from langchain_text_splitters import CharacterTextSplitter" ] }, { diff --git a/docs/docs/integrations/retrievers/self_query/astradb.ipynb b/docs/docs/integrations/retrievers/self_query/astradb.ipynb index 441d8971794..96b8ad83ff8 100644 --- a/docs/docs/integrations/retrievers/self_query/astradb.ipynb +++ b/docs/docs/integrations/retrievers/self_query/astradb.ipynb @@ -87,7 +87,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.vectorstores import AstraDB\n", + "from langchain_community.vectorstores import AstraDB\n", "from langchain_core.documents import Document\n", "\n", "docs = [\n", @@ -146,8 +146,8 @@ "outputs": [], "source": [ "from langchain.chains.query_constructor.base import AttributeInfo\n", - "from langchain.llms import OpenAI\n", "from langchain.retrievers.self_query.base import SelfQueryRetriever\n", + "from langchain_openai import OpenAI\n", "\n", "metadata_field_info = [\n", " AttributeInfo(\n", diff --git a/docs/docs/integrations/retrievers/self_query/dingo.ipynb b/docs/docs/integrations/retrievers/self_query/dingo.ipynb index 5afbd187201..95bda4d1513 100644 --- a/docs/docs/integrations/retrievers/self_query/dingo.ipynb +++ b/docs/docs/integrations/retrievers/self_query/dingo.ipynb @@ -72,8 +72,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.schema import Document\n", "from langchain_community.vectorstores import Dingo\n", + "from langchain_core.documents import Document\n", "from langchain_openai import OpenAIEmbeddings\n", "\n", "embeddings = OpenAIEmbeddings()\n", diff --git a/docs/docs/integrations/retrievers/self_query/opensearch_self_query.ipynb b/docs/docs/integrations/retrievers/self_query/opensearch_self_query.ipynb index 55f8ae12486..130512180b2 100644 --- a/docs/docs/integrations/retrievers/self_query/opensearch_self_query.ipynb +++ b/docs/docs/integrations/retrievers/self_query/opensearch_self_query.ipynb @@ -443,4 +443,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/retrievers/self_query/tencentvectordb.ipynb b/docs/docs/integrations/retrievers/self_query/tencentvectordb.ipynb index 3ab481619e9..a2e37fe85f5 100644 --- a/docs/docs/integrations/retrievers/self_query/tencentvectordb.ipynb +++ b/docs/docs/integrations/retrievers/self_query/tencentvectordb.ipynb @@ -288,7 +288,12 @@ "outputs": [ { "data": { - "text/plain": "[Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'science fiction', 'director': 'Christopher Nolan'}),\n Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'}),\n Document(page_content='Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.', metadata={'year': 2018, 'rating': '7.3', 'genre': 'science fiction', 'director': 'Ryan Coogler'}),\n Document(page_content='The Godfather is a 1972 American crime film directed by Francis Ford Coppola.', metadata={'year': 1972, 'rating': '9.2', 'genre': 'crime', 'director': 'Francis Ford Coppola'})]" + "text/plain": [ + "[Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'science fiction', 'director': 'Christopher Nolan'}),\n", + " Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'}),\n", + " Document(page_content='Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.', metadata={'year': 2018, 'rating': '7.3', 'genre': 'science fiction', 'director': 'Ryan Coogler'}),\n", + " Document(page_content='The Godfather is a 1972 American crime film directed by Francis Ford Coppola.', metadata={'year': 1972, 'rating': '9.2', 'genre': 'crime', 'director': 'Francis Ford Coppola'})]" + ] }, "execution_count": 6, "metadata": {}, @@ -314,7 +319,10 @@ "outputs": [ { "data": { - "text/plain": "[Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'}),\n Document(page_content='Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.', metadata={'year': 2018, 'rating': '7.3', 'genre': 'science fiction', 'director': 'Ryan Coogler'})]" + "text/plain": [ + "[Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'}),\n", + " Document(page_content='Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.', metadata={'year': 2018, 'rating': '7.3', 'genre': 'science fiction', 'director': 'Ryan Coogler'})]" + ] }, "execution_count": 7, "metadata": {}, @@ -340,7 +348,10 @@ "outputs": [ { "data": { - "text/plain": "[Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'}),\n Document(page_content='Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.', metadata={'year': 2018, 'rating': '7.3', 'genre': 'science fiction', 'director': 'Ryan Coogler'})]" + "text/plain": [ + "[Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'}),\n", + " Document(page_content='Black Panther is a 2018 American superhero film based on the Marvel Comics character of the same name.', metadata={'year': 2018, 'rating': '7.3', 'genre': 'science fiction', 'director': 'Ryan Coogler'})]" + ] }, "execution_count": 8, "metadata": {}, @@ -403,7 +414,10 @@ "outputs": [ { "data": { - "text/plain": "[Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'science fiction', 'director': 'Christopher Nolan'}),\n Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'})]" + "text/plain": [ + "[Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'science fiction', 'director': 'Christopher Nolan'}),\n", + " Document(page_content='The Avengers is a 2012 American superhero film based on the Marvel Comics superhero team of the same name.', metadata={'year': 2012, 'rating': '8.0', 'genre': 'science fiction', 'director': 'Joss Whedon'})]" + ] }, "execution_count": 10, "metadata": {}, diff --git a/docs/docs/integrations/retrievers/zep_memorystore.ipynb b/docs/docs/integrations/retrievers/zep_memorystore.ipynb index 65733bfea27..7cb2126423a 100644 --- a/docs/docs/integrations/retrievers/zep_memorystore.ipynb +++ b/docs/docs/integrations/retrievers/zep_memorystore.ipynb @@ -2,6 +2,9 @@ "cells": [ { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "# Zep\n", "## Retriever Example for [Zep](https://docs.getzep.com/)\n", @@ -18,10 +21,7 @@ "\n", "> Zep Open Source project: [https://github.com/getzep/zep](https://github.com/getzep/zep)\n", "> Zep Open Source Docs: [https://docs.getzep.com/](https://docs.getzep.com/)" - ], - "metadata": { - "collapsed": false - } + ] }, { "attachments": {}, diff --git a/docs/docs/integrations/stores/astradb.ipynb b/docs/docs/integrations/stores/astradb.ipynb index a5b58632815..87bb7e67aed 100644 --- a/docs/docs/integrations/stores/astradb.ipynb +++ b/docs/docs/integrations/stores/astradb.ipynb @@ -132,7 +132,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.embeddings import CacheBackedEmbeddings, OpenAIEmbeddings\n", + "from langchain.embeddings import CacheBackedEmbeddings\n", + "from langchain_openai import OpenAIEmbeddings\n", "\n", "embeddings = CacheBackedEmbeddings(\n", " underlying_embeddings=OpenAIEmbeddings(), document_embedding_store=store\n", diff --git a/docs/docs/integrations/stores/redis.ipynb b/docs/docs/integrations/stores/redis.ipynb index c7d37470aa7..9f0da976350 100644 --- a/docs/docs/integrations/stores/redis.ipynb +++ b/docs/docs/integrations/stores/redis.ipynb @@ -43,7 +43,7 @@ } ], "source": [ - "from langchain.storage import RedisStore\n", + "from langchain_community.storage import RedisStore\n", "\n", "store = RedisStore(redis_url=\"redis://localhost:6379\")\n", "\n", diff --git a/docs/docs/integrations/stores/upstash_redis.ipynb b/docs/docs/integrations/stores/upstash_redis.ipynb index 186dbf93cab..91df14f86c3 100644 --- a/docs/docs/integrations/stores/upstash_redis.ipynb +++ b/docs/docs/integrations/stores/upstash_redis.ipynb @@ -45,7 +45,7 @@ } ], "source": [ - "from langchain.storage import UpstashRedisByteStore\n", + "from langchain_community.storage import UpstashRedisByteStore\n", "from upstash_redis import Redis\n", "\n", "URL = \"\"\n", diff --git a/docs/docs/integrations/text_embedding/baidu_qianfan_endpoint.ipynb b/docs/docs/integrations/text_embedding/baidu_qianfan_endpoint.ipynb index f2814b3f954..ab0b372f509 100644 --- a/docs/docs/integrations/text_embedding/baidu_qianfan_endpoint.ipynb +++ b/docs/docs/integrations/text_embedding/baidu_qianfan_endpoint.ipynb @@ -152,7 +152,6 @@ "pygments_lexer": "ipython3", "version": "3.11.4" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "6fa70026b407ae751a5c9e6bd7f7d482379da8ad616f98512780b705c84ee157" diff --git a/docs/docs/integrations/text_embedding/dashscope.ipynb b/docs/docs/integrations/text_embedding/dashscope.ipynb index d38b910f3d2..d3f22457bd0 100644 --- a/docs/docs/integrations/text_embedding/dashscope.ipynb +++ b/docs/docs/integrations/text_embedding/dashscope.ipynb @@ -77,8 +77,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/text_embedding/edenai.ipynb b/docs/docs/integrations/text_embedding/edenai.ipynb index 1da964ba321..b17fa04badd 100644 --- a/docs/docs/integrations/text_embedding/edenai.ipynb +++ b/docs/docs/integrations/text_embedding/edenai.ipynb @@ -155,8 +155,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/text_embedding/gigachat.ipynb b/docs/docs/integrations/text_embedding/gigachat.ipynb index d50c2a5fda6..855ec550d6f 100644 --- a/docs/docs/integrations/text_embedding/gigachat.ipynb +++ b/docs/docs/integrations/text_embedding/gigachat.ipynb @@ -2,36 +2,36 @@ "cells": [ { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "# GigaChat\n", "This notebook shows how to use LangChain with [GigaChat embeddings](https://developers.sber.ru/portal/products/gigachat).\n", "To use you need to install ```gigachat``` python package." - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "collapsed": false + }, "outputs": [], "source": [ "%pip install --upgrade --quiet gigachat" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "To get GigaChat credentials you need to [create account](https://developers.sber.ru/studio/login) and [get access to API](https://developers.sber.ru/docs/ru/gigachat/individuals-quickstart)\n", "\n", "## Example" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", @@ -50,34 +50,43 @@ { "cell_type": "code", "execution_count": 5, + "metadata": { + "collapsed": false + }, "outputs": [], "source": [ "from langchain_community.embeddings import GigaChatEmbeddings\n", "\n", "embeddings = GigaChatEmbeddings(verify_ssl_certs=False, scope=\"GIGACHAT_API_PERS\")" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": 7, + "metadata": { + "collapsed": false + }, "outputs": [], "source": [ "query_result = embeddings.embed_query(\"The quick brown fox jumps over the lazy dog\")" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": 8, + "metadata": { + "collapsed": false + }, "outputs": [ { "data": { - "text/plain": "[0.8398333191871643,\n -0.14180311560630798,\n -0.6161925792694092,\n -0.17103666067123413,\n 1.2884578704833984]" + "text/plain": [ + "[0.8398333191871643,\n", + " -0.14180311560630798,\n", + " -0.6161925792694092,\n", + " -0.17103666067123413,\n", + " 1.2884578704833984]" + ] }, "execution_count": 8, "metadata": {}, @@ -86,10 +95,7 @@ ], "source": [ "query_result[:5]" - ], - "metadata": { - "collapsed": false - } + ] } ], "metadata": { diff --git a/docs/docs/integrations/text_embedding/sparkllm.ipynb b/docs/docs/integrations/text_embedding/sparkllm.ipynb index c0c6de7f380..021ba7bb665 100644 --- a/docs/docs/integrations/text_embedding/sparkllm.ipynb +++ b/docs/docs/integrations/text_embedding/sparkllm.ipynb @@ -62,7 +62,16 @@ "outputs": [ { "data": { - "text/plain": "[-0.043609619140625,\n 0.2017822265625,\n 0.0270843505859375,\n -0.250244140625,\n -0.024993896484375,\n -0.0382080078125,\n 0.06207275390625,\n -0.0146331787109375]" + "text/plain": [ + "[-0.043609619140625,\n", + " 0.2017822265625,\n", + " 0.0270843505859375,\n", + " -0.250244140625,\n", + " -0.024993896484375,\n", + " -0.0382080078125,\n", + " 0.06207275390625,\n", + " -0.0146331787109375]" + ] }, "execution_count": 3, "metadata": {}, @@ -92,7 +101,16 @@ "outputs": [ { "data": { - "text/plain": "[-0.161865234375,\n 0.58984375,\n 0.998046875,\n 0.365966796875,\n 0.72900390625,\n 0.6015625,\n -0.8408203125,\n -0.2666015625]" + "text/plain": [ + "[-0.161865234375,\n", + " 0.58984375,\n", + " 0.998046875,\n", + " 0.365966796875,\n", + " 0.72900390625,\n", + " 0.6015625,\n", + " -0.8408203125,\n", + " -0.2666015625]" + ] }, "execution_count": 5, "metadata": {}, @@ -106,13 +124,13 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { "name": "python" - }, - "kernelspec": { - "name": "python3", - "language": "python", - "display_name": "Python 3 (ipykernel)" } }, "nbformat": 4, diff --git a/docs/docs/integrations/text_embedding/voyageai.ipynb b/docs/docs/integrations/text_embedding/voyageai.ipynb index a4f12b3cd0f..eb301a6cc94 100644 --- a/docs/docs/integrations/text_embedding/voyageai.ipynb +++ b/docs/docs/integrations/text_embedding/voyageai.ipynb @@ -197,7 +197,7 @@ } ], "source": [ - "from langchain.retrievers import KNNRetriever\n", + "from langchain_community.retrievers import KNNRetriever\n", "\n", "retriever = KNNRetriever.from_texts(documents, embeddings)\n", "\n", diff --git a/docs/docs/integrations/text_embedding/xinference.ipynb b/docs/docs/integrations/text_embedding/xinference.ipynb index 2bbb8720868..ab028750dc4 100644 --- a/docs/docs/integrations/text_embedding/xinference.ipynb +++ b/docs/docs/integrations/text_embedding/xinference.ipynb @@ -135,8 +135,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/toolkits/airbyte_structured_qa.ipynb b/docs/docs/integrations/toolkits/airbyte_structured_qa.ipynb index 68db356ce7c..08868528133 100644 --- a/docs/docs/integrations/toolkits/airbyte_structured_qa.ipynb +++ b/docs/docs/integrations/toolkits/airbyte_structured_qa.ipynb @@ -113,8 +113,7 @@ "metadata": { "language_info": { "name": "python" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/toolkits/connery.ipynb b/docs/docs/integrations/toolkits/connery.ipynb index 335fbcf34e3..4289ca8de7b 100644 --- a/docs/docs/integrations/toolkits/connery.ipynb +++ b/docs/docs/integrations/toolkits/connery.ipynb @@ -75,8 +75,8 @@ "\n", "from langchain.agents import AgentType, initialize_agent\n", "from langchain_community.agent_toolkits.connery import ConneryToolkit\n", - "from langchain_community.chat_models import ChatOpenAI\n", "from langchain_community.tools.connery import ConneryService\n", + "from langchain_openai import ChatOpenAI\n", "\n", "# Specify your Connery Runner credentials.\n", "os.environ[\"CONNERY_RUNNER_URL\"] = \"\"\n", diff --git a/docs/docs/integrations/toolkits/document_comparison_toolkit.ipynb b/docs/docs/integrations/toolkits/document_comparison_toolkit.ipynb index 6a7ea058b2e..f78cf034fb0 100644 --- a/docs/docs/integrations/toolkits/document_comparison_toolkit.ipynb +++ b/docs/docs/integrations/toolkits/document_comparison_toolkit.ipynb @@ -19,10 +19,10 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import Tool\n", "from langchain.chains import RetrievalQA\n", "from langchain_community.document_loaders import PyPDFLoader\n", "from langchain_community.vectorstores import FAISS\n", + "from langchain_core.tools import Tool\n", "from langchain_openai import ChatOpenAI, OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter\n", "from pydantic import BaseModel, Field" diff --git a/docs/docs/integrations/toolkits/github.ipynb b/docs/docs/integrations/toolkits/github.ipynb index 8e4a55ec71b..b2e68b3904b 100644 --- a/docs/docs/integrations/toolkits/github.ipynb +++ b/docs/docs/integrations/toolkits/github.ipynb @@ -701,8 +701,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import Tool\n", - "from langchain.tools import DuckDuckGoSearchRun\n", + "from langchain_community.tools import DuckDuckGoSearchRun\n", + "from langchain_core.tools import Tool\n", "from langchain_openai import ChatOpenAI\n", "\n", "tools = []\n", diff --git a/docs/docs/integrations/toolkits/json.ipynb b/docs/docs/integrations/toolkits/json.ipynb index 972149326e9..ba9f433e49d 100644 --- a/docs/docs/integrations/toolkits/json.ipynb +++ b/docs/docs/integrations/toolkits/json.ipynb @@ -33,8 +33,7 @@ "outputs": [], "source": [ "import yaml\n", - "from langchain.agents import create_json_agent\n", - "from langchain_community.agent_toolkits import JsonToolkit\n", + "from langchain_community.agent_toolkits import JsonToolkit, create_json_agent\n", "from langchain_community.tools.json.tool import JsonSpec\n", "from langchain_openai import OpenAI" ] diff --git a/docs/docs/integrations/toolkits/openapi.ipynb b/docs/docs/integrations/toolkits/openapi.ipynb index 2f2d6569117..0c9a049b340 100644 --- a/docs/docs/integrations/toolkits/openapi.ipynb +++ b/docs/docs/integrations/toolkits/openapi.ipynb @@ -608,8 +608,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import create_openapi_agent\n", - "from langchain_community.agent_toolkits import OpenAPIToolkit\n", + "from langchain_community.agent_toolkits import OpenAPIToolkit, create_openapi_agent\n", "from langchain_community.tools.json.tool import JsonSpec\n", "from langchain_openai import OpenAI" ] diff --git a/docs/docs/integrations/toolkits/openapi_nla.ipynb b/docs/docs/integrations/toolkits/openapi_nla.ipynb index 16c07c27aa3..4ff98f3f92b 100644 --- a/docs/docs/integrations/toolkits/openapi_nla.ipynb +++ b/docs/docs/integrations/toolkits/openapi_nla.ipynb @@ -24,8 +24,8 @@ "outputs": [], "source": [ "from langchain.agents import AgentType, initialize_agent\n", - "from langchain.requests import Requests\n", "from langchain_community.agent_toolkits import NLAToolkit\n", + "from langchain_community.utilities import Requests\n", "from langchain_openai import OpenAI" ] }, diff --git a/docs/docs/integrations/toolkits/playwright.ipynb b/docs/docs/integrations/toolkits/playwright.ipynb index ba3e2c12717..16c5b73b00c 100644 --- a/docs/docs/integrations/toolkits/playwright.ipynb +++ b/docs/docs/integrations/toolkits/playwright.ipynb @@ -221,7 +221,7 @@ "outputs": [], "source": [ "from langchain.agents import AgentType, initialize_agent\n", - "from langchain_community.chat_models import ChatAnthropic\n", + "from langchain_anthropic import ChatAnthropic\n", "\n", "llm = ChatAnthropic(temperature=0) # or any other LLM, e.g., ChatOpenAI(), OpenAI()\n", "\n", diff --git a/docs/docs/integrations/toolkits/python.ipynb b/docs/docs/integrations/toolkits/python.ipynb index 5949c1a6db6..ca4d25869b2 100644 --- a/docs/docs/integrations/toolkits/python.ipynb +++ b/docs/docs/integrations/toolkits/python.ipynb @@ -129,7 +129,7 @@ "outputs": [], "source": [ "from langchain.agents import create_react_agent\n", - "from langchain_community.chat_models import ChatAnthropic" + "from langchain_anthropic import ChatAnthropic" ] }, { diff --git a/docs/docs/integrations/toolkits/spark_sql.ipynb b/docs/docs/integrations/toolkits/spark_sql.ipynb index a0c16371e7e..79229c243be 100644 --- a/docs/docs/integrations/toolkits/spark_sql.ipynb +++ b/docs/docs/integrations/toolkits/spark_sql.ipynb @@ -24,8 +24,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import create_spark_sql_agent\n", - "from langchain_community.agent_toolkits import SparkSQLToolkit\n", + "from langchain_community.agent_toolkits import SparkSQLToolkit, create_spark_sql_agent\n", "from langchain_community.utilities.spark_sql import SparkSQL\n", "from langchain_openai import ChatOpenAI" ] diff --git a/docs/docs/integrations/tools/arxiv.ipynb b/docs/docs/integrations/tools/arxiv.ipynb index 74b5b134f76..bb206a44da7 100644 --- a/docs/docs/integrations/tools/arxiv.ipynb +++ b/docs/docs/integrations/tools/arxiv.ipynb @@ -84,7 +84,10 @@ }, { "data": { - "text/plain": "{'input': \"What's the paper 1605.08386 about?\",\n 'output': 'The paper \"1605.08386\" is about heat-bath random walks with Markov bases.'}" + "text/plain": [ + "{'input': \"What's the paper 1605.08386 about?\",\n", + " 'output': 'The paper \"1605.08386\" is about heat-bath random walks with Markov bases.'}" + ] }, "execution_count": 3, "metadata": {}, @@ -147,7 +150,9 @@ "outputs": [ { "data": { - "text/plain": "'Published: 2016-05-26\\nTitle: Heat-bath random walks with Markov bases\\nAuthors: Caprice Stanley, Tobias Windisch\\nSummary: Graphs on lattice points are studied whose edges come from a finite set of\\nallowed moves of arbitrary length. We show that the diameter of these graphs on\\nfibers of a fixed integer matrix can be bounded from above by a constant. We\\nthen study the mixing behaviour of heat-bath random walks on these graphs. We\\nalso state explicit conditions on the set of moves so that the heat-bath random\\nwalk, a generalization of the Glauber dynamics, is an expander in fixed\\ndimension.'" + "text/plain": [ + "'Published: 2016-05-26\\nTitle: Heat-bath random walks with Markov bases\\nAuthors: Caprice Stanley, Tobias Windisch\\nSummary: Graphs on lattice points are studied whose edges come from a finite set of\\nallowed moves of arbitrary length. We show that the diameter of these graphs on\\nfibers of a fixed integer matrix can be bounded from above by a constant. We\\nthen study the mixing behaviour of heat-bath random walks on these graphs. We\\nalso state explicit conditions on the set of moves so that the heat-bath random\\nwalk, a generalization of the Glauber dynamics, is an expander in fixed\\ndimension.'" + ] }, "execution_count": 5, "metadata": {}, @@ -180,7 +185,9 @@ "outputs": [ { "data": { - "text/plain": "'Published: 2017-10-10\\nTitle: On Mixing Behavior of a Family of Random Walks Determined by a Linear Recurrence\\nAuthors: Caprice Stanley, Seth Sullivant\\nSummary: We study random walks on the integers mod $G_n$ that are determined by an\\ninteger sequence $\\\\{ G_n \\\\}_{n \\\\geq 1}$ generated by a linear recurrence\\nrelation. Fourier analysis provides explicit formulas to compute the\\neigenvalues of the transition matrices and we use this to bound the mixing time\\nof the random walks.\\n\\nPublished: 2016-05-26\\nTitle: Heat-bath random walks with Markov bases\\nAuthors: Caprice Stanley, Tobias Windisch\\nSummary: Graphs on lattice points are studied whose edges come from a finite set of\\nallowed moves of arbitrary length. We show that the diameter of these graphs on\\nfibers of a fixed integer matrix can be bounded from above by a constant. We\\nthen study the mixing behaviour of heat-bath random walks on these graphs. We\\nalso state explicit conditions on the set of moves so that the heat-bath random\\nwalk, a generalization of the Glauber dynamics, is an expander in fixed\\ndimension.\\n\\nPublished: 2003-03-18\\nTitle: Calculation of fluxes of charged particles and neutrinos from atmospheric showers\\nAuthors: V. Plyaskin\\nSummary: The results on the fluxes of charged particles and neutrinos from a\\n3-dimensional (3D) simulation of atmospheric showers are presented. An\\nagreement of calculated fluxes with data on charged particles from the AMS and\\nCAPRICE detectors is demonstrated. Predictions on neutrino fluxes at different\\nexperimental sites are compared with results from other calculations.'" + "text/plain": [ + "'Published: 2017-10-10\\nTitle: On Mixing Behavior of a Family of Random Walks Determined by a Linear Recurrence\\nAuthors: Caprice Stanley, Seth Sullivant\\nSummary: We study random walks on the integers mod $G_n$ that are determined by an\\ninteger sequence $\\\\{ G_n \\\\}_{n \\\\geq 1}$ generated by a linear recurrence\\nrelation. Fourier analysis provides explicit formulas to compute the\\neigenvalues of the transition matrices and we use this to bound the mixing time\\nof the random walks.\\n\\nPublished: 2016-05-26\\nTitle: Heat-bath random walks with Markov bases\\nAuthors: Caprice Stanley, Tobias Windisch\\nSummary: Graphs on lattice points are studied whose edges come from a finite set of\\nallowed moves of arbitrary length. We show that the diameter of these graphs on\\nfibers of a fixed integer matrix can be bounded from above by a constant. We\\nthen study the mixing behaviour of heat-bath random walks on these graphs. We\\nalso state explicit conditions on the set of moves so that the heat-bath random\\nwalk, a generalization of the Glauber dynamics, is an expander in fixed\\ndimension.\\n\\nPublished: 2003-03-18\\nTitle: Calculation of fluxes of charged particles and neutrinos from atmospheric showers\\nAuthors: V. Plyaskin\\nSummary: The results on the fluxes of charged particles and neutrinos from a\\n3-dimensional (3D) simulation of atmospheric showers are presented. An\\nagreement of calculated fluxes with data on charged particles from the AMS and\\nCAPRICE detectors is demonstrated. Predictions on neutrino fluxes at different\\nexperimental sites are compared with results from other calculations.'" + ] }, "execution_count": 6, "metadata": {}, @@ -210,7 +217,9 @@ "outputs": [ { "data": { - "text/plain": "'No good Arxiv Result was found'" + "text/plain": [ + "'No good Arxiv Result was found'" + ] }, "execution_count": 7, "metadata": {}, diff --git a/docs/docs/integrations/tools/dataforseo.ipynb b/docs/docs/integrations/tools/dataforseo.ipynb index a7fd208d6fa..ba96e920a0e 100644 --- a/docs/docs/integrations/tools/dataforseo.ipynb +++ b/docs/docs/integrations/tools/dataforseo.ipynb @@ -189,7 +189,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import Tool\n", + "from langchain_core.tools import Tool\n", "\n", "search = DataForSeoAPIWrapper(\n", " top_count=3,\n", diff --git a/docs/docs/integrations/tools/exa_search.ipynb b/docs/docs/integrations/tools/exa_search.ipynb index 8347c2cb5b8..db3efad940e 100644 --- a/docs/docs/integrations/tools/exa_search.ipynb +++ b/docs/docs/integrations/tools/exa_search.ipynb @@ -154,7 +154,7 @@ "outputs": [], "source": [ "from exa_py import Exa\n", - "from langchain.agents import tool\n", + "from langchain_core.tools import tool\n", "\n", "exa = Exa(api_key=os.environ[\"EXA_API_KEY\"])\n", "\n", @@ -334,7 +334,7 @@ "outputs": [], "source": [ "from exa_py import Exa\n", - "from langchain.agents import tool\n", + "from langchain_core.tools import tool\n", "\n", "exa = Exa(api_key=os.environ[\"Exa_API_KEY\"])\n", "\n", diff --git a/docs/docs/integrations/tools/golden_query.ipynb b/docs/docs/integrations/tools/golden_query.ipynb index e734b6a1f40..2118ac74fef 100644 --- a/docs/docs/integrations/tools/golden_query.ipynb +++ b/docs/docs/integrations/tools/golden_query.ipynb @@ -1,160 +1,160 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "245a954a", - "metadata": { - "id": "245a954a" - }, - "source": [ - "# Golden Query\n", - "\n", - ">[Golden](https://golden.com) provides a set of natural language APIs for querying and enrichment using the Golden Knowledge Graph e.g. queries such as: `Products from OpenAI`, `Generative ai companies with series a funding`, and `rappers who invest` can be used to retrieve structured data about relevant entities.\n", - ">\n", - ">The `golden-query` langchain tool is a wrapper on top of the [Golden Query API](https://docs.golden.com/reference/query-api) which enables programmatic access to these results.\n", - ">See the [Golden Query API docs](https://docs.golden.com/reference/query-api) for more information.\n", - "\n", - "\n", - "This notebook goes over how to use the `golden-query` tool.\n", - "\n", - "- Go to the [Golden API docs](https://docs.golden.com/) to get an overview about the Golden API.\n", - "- Get your API key from the [Golden API Settings](https://golden.com/settings/api) page.\n", - "- Save your API key into GOLDEN_API_KEY env variable" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "34bb5968", - "metadata": { - "id": "34bb5968" - }, - "outputs": [], - "source": [ - "import os\n", - "\n", - "os.environ[\"GOLDEN_API_KEY\"] = \"\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ac4910f8", - "metadata": { - "id": "ac4910f8" - }, - "outputs": [], - "source": [ - "from langchain_community.utilities.golden_query import GoldenQueryAPIWrapper" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "84b8f773", - "metadata": { - "id": "84b8f773" - }, - "outputs": [], - "source": [ - "golden_query = GoldenQueryAPIWrapper()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "068991a6", - "metadata": { - "id": "068991a6", - "outputId": "c5cdc6ec-03cf-4084-cc6f-6ae792d91d39" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'results': [{'id': 4673886,\n", - " 'latestVersionId': 60276991,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Samsung', 'citations': []}]}]},\n", - " {'id': 7008,\n", - " 'latestVersionId': 61087416,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Intel', 'citations': []}]}]},\n", - " {'id': 24193,\n", - " 'latestVersionId': 60274482,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Texas Instruments', 'citations': []}]}]},\n", - " {'id': 1142,\n", - " 'latestVersionId': 61406205,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Advanced Micro Devices', 'citations': []}]}]},\n", - " {'id': 193948,\n", - " 'latestVersionId': 58326582,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Freescale Semiconductor', 'citations': []}]}]},\n", - " {'id': 91316,\n", - " 'latestVersionId': 60387380,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Agilent Technologies', 'citations': []}]}]},\n", - " {'id': 90014,\n", - " 'latestVersionId': 60388078,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Novartis', 'citations': []}]}]},\n", - " {'id': 237458,\n", - " 'latestVersionId': 61406160,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'Analog Devices', 'citations': []}]}]},\n", - " {'id': 3941943,\n", - " 'latestVersionId': 60382250,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'AbbVie Inc.', 'citations': []}]}]},\n", - " {'id': 4178762,\n", - " 'latestVersionId': 60542667,\n", - " 'properties': [{'predicateId': 'name',\n", - " 'instances': [{'value': 'IBM', 'citations': []}]}]}],\n", - " 'next': 'https://golden.com/api/v2/public/queries/59044/results/?cursor=eyJwb3NpdGlvbiI6IFsxNzYxNiwgIklCTS04M1lQM1oiXX0%3D&pageSize=10',\n", - " 'previous': None}" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import json\n", - "\n", - "json.loads(golden_query.run(\"companies in nanotech\"))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".venv", - "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.9.13" - }, - "vscode": { - "interpreter": { - "hash": "53f3bc57609c7a84333bb558594977aa5b4026b1d6070b93987956689e367341" - } - }, - "colab": { - "provenance": [] - } + "cells": [ + { + "cell_type": "markdown", + "id": "245a954a", + "metadata": { + "id": "245a954a" + }, + "source": [ + "# Golden Query\n", + "\n", + ">[Golden](https://golden.com) provides a set of natural language APIs for querying and enrichment using the Golden Knowledge Graph e.g. queries such as: `Products from OpenAI`, `Generative ai companies with series a funding`, and `rappers who invest` can be used to retrieve structured data about relevant entities.\n", + ">\n", + ">The `golden-query` langchain tool is a wrapper on top of the [Golden Query API](https://docs.golden.com/reference/query-api) which enables programmatic access to these results.\n", + ">See the [Golden Query API docs](https://docs.golden.com/reference/query-api) for more information.\n", + "\n", + "\n", + "This notebook goes over how to use the `golden-query` tool.\n", + "\n", + "- Go to the [Golden API docs](https://docs.golden.com/) to get an overview about the Golden API.\n", + "- Get your API key from the [Golden API Settings](https://golden.com/settings/api) page.\n", + "- Save your API key into GOLDEN_API_KEY env variable" + ] }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file + { + "cell_type": "code", + "execution_count": null, + "id": "34bb5968", + "metadata": { + "id": "34bb5968" + }, + "outputs": [], + "source": [ + "import os\n", + "\n", + "os.environ[\"GOLDEN_API_KEY\"] = \"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac4910f8", + "metadata": { + "id": "ac4910f8" + }, + "outputs": [], + "source": [ + "from langchain_community.utilities.golden_query import GoldenQueryAPIWrapper" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84b8f773", + "metadata": { + "id": "84b8f773" + }, + "outputs": [], + "source": [ + "golden_query = GoldenQueryAPIWrapper()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "068991a6", + "metadata": { + "id": "068991a6", + "outputId": "c5cdc6ec-03cf-4084-cc6f-6ae792d91d39" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'results': [{'id': 4673886,\n", + " 'latestVersionId': 60276991,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Samsung', 'citations': []}]}]},\n", + " {'id': 7008,\n", + " 'latestVersionId': 61087416,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Intel', 'citations': []}]}]},\n", + " {'id': 24193,\n", + " 'latestVersionId': 60274482,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Texas Instruments', 'citations': []}]}]},\n", + " {'id': 1142,\n", + " 'latestVersionId': 61406205,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Advanced Micro Devices', 'citations': []}]}]},\n", + " {'id': 193948,\n", + " 'latestVersionId': 58326582,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Freescale Semiconductor', 'citations': []}]}]},\n", + " {'id': 91316,\n", + " 'latestVersionId': 60387380,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Agilent Technologies', 'citations': []}]}]},\n", + " {'id': 90014,\n", + " 'latestVersionId': 60388078,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Novartis', 'citations': []}]}]},\n", + " {'id': 237458,\n", + " 'latestVersionId': 61406160,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'Analog Devices', 'citations': []}]}]},\n", + " {'id': 3941943,\n", + " 'latestVersionId': 60382250,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'AbbVie Inc.', 'citations': []}]}]},\n", + " {'id': 4178762,\n", + " 'latestVersionId': 60542667,\n", + " 'properties': [{'predicateId': 'name',\n", + " 'instances': [{'value': 'IBM', 'citations': []}]}]}],\n", + " 'next': 'https://golden.com/api/v2/public/queries/59044/results/?cursor=eyJwb3NpdGlvbiI6IFsxNzYxNiwgIklCTS04M1lQM1oiXX0%3D&pageSize=10',\n", + " 'previous': None}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import json\n", + "\n", + "json.loads(golden_query.run(\"companies in nanotech\"))" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": ".venv", + "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.9.13" + }, + "vscode": { + "interpreter": { + "hash": "53f3bc57609c7a84333bb558594977aa5b4026b1d6070b93987956689e367341" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/docs/integrations/tools/google_scholar.ipynb b/docs/docs/integrations/tools/google_scholar.ipynb index 6c1c7ab05f6..a94714783be 100644 --- a/docs/docs/integrations/tools/google_scholar.ipynb +++ b/docs/docs/integrations/tools/google_scholar.ipynb @@ -91,7 +91,6 @@ "pygments_lexer": "ipython3", "version": "3.9.16" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "15e58ce194949b77a891bd4339ce3d86a9bd138e905926019517993f97db9e6c" diff --git a/docs/docs/integrations/tools/google_serper.ipynb b/docs/docs/integrations/tools/google_serper.ipynb index d93ce03449b..fc83b6c3bfe 100644 --- a/docs/docs/integrations/tools/google_serper.ipynb +++ b/docs/docs/integrations/tools/google_serper.ipynb @@ -158,8 +158,9 @@ } ], "source": [ - "from langchain.agents import AgentType, Tool, initialize_agent\n", + "from langchain.agents import AgentType, initialize_agent\n", "from langchain_community.utilities import GoogleSerperAPIWrapper\n", + "from langchain_core.tools import Tool\n", "from langchain_openai import OpenAI\n", "\n", "llm = OpenAI(temperature=0)\n", diff --git a/docs/docs/integrations/tools/google_trends.ipynb b/docs/docs/integrations/tools/google_trends.ipynb index a7dbcc4f375..c5a6ff81d48 100644 --- a/docs/docs/integrations/tools/google_trends.ipynb +++ b/docs/docs/integrations/tools/google_trends.ipynb @@ -97,7 +97,6 @@ "pygments_lexer": "ipython3", "version": "3.11.4" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "15e58ce194949b77a891bd4339ce3d86a9bd138e905926019517993f97db9e6c" diff --git a/docs/docs/integrations/tools/infobip.ipynb b/docs/docs/integrations/tools/infobip.ipynb index 72561b2fc92..f9cc46b8aff 100644 --- a/docs/docs/integrations/tools/infobip.ipynb +++ b/docs/docs/integrations/tools/infobip.ipynb @@ -105,9 +105,9 @@ "source": [ "from langchain import hub\n", "from langchain.agents import AgentExecutor, create_openai_functions_agent\n", - "from langchain.tools import StructuredTool\n", "from langchain_community.utilities.infobip import InfobipAPIWrapper\n", "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from langchain_core.tools import StructuredTool\n", "from langchain_openai import ChatOpenAI\n", "\n", "instructions = \"You are a coding teacher. You are teaching a student how to code. The student asks you a question. You answer the question.\"\n", diff --git a/docs/docs/integrations/tools/python.ipynb b/docs/docs/integrations/tools/python.ipynb index 34a18e6bda5..a098a4420ef 100644 --- a/docs/docs/integrations/tools/python.ipynb +++ b/docs/docs/integrations/tools/python.ipynb @@ -19,7 +19,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import Tool\n", + "from langchain_core.tools import Tool\n", "from langchain_experimental.utilities import PythonREPL" ] }, diff --git a/docs/docs/integrations/tools/reddit_search.ipynb b/docs/docs/integrations/tools/reddit_search.ipynb index 9c4eca4c4a2..3a40377fd8f 100644 --- a/docs/docs/integrations/tools/reddit_search.ipynb +++ b/docs/docs/integrations/tools/reddit_search.ipynb @@ -169,12 +169,13 @@ "source": [ "# Adapted code from /docs/modules/agents/how_to/sharedmemory_for_tools\n", "\n", - "from langchain.agents import AgentExecutor, StructuredChatAgent, Tool\n", + "from langchain.agents import AgentExecutor, StructuredChatAgent\n", "from langchain.chains import LLMChain\n", "from langchain.memory import ConversationBufferMemory, ReadOnlySharedMemory\n", "from langchain_community.tools.reddit_search.tool import RedditSearchRun\n", "from langchain_community.utilities.reddit_search import RedditSearchAPIWrapper\n", "from langchain_core.prompts import PromptTemplate\n", + "from langchain_core.tools import Tool\n", "from langchain_openai import ChatOpenAI\n", "\n", "# Provide keys for Reddit\n", diff --git a/docs/docs/integrations/tools/searchapi.ipynb b/docs/docs/integrations/tools/searchapi.ipynb index acd5af2c258..c086b4d18d1 100644 --- a/docs/docs/integrations/tools/searchapi.ipynb +++ b/docs/docs/integrations/tools/searchapi.ipynb @@ -124,8 +124,9 @@ } ], "source": [ - "from langchain.agents import AgentType, Tool, initialize_agent\n", + "from langchain.agents import AgentType, initialize_agent\n", "from langchain_community.utilities import SearchApiAPIWrapper\n", + "from langchain_core.tools import Tool\n", "from langchain_openai import OpenAI\n", "\n", "llm = OpenAI(temperature=0)\n", diff --git a/docs/docs/integrations/tools/serpapi.ipynb b/docs/docs/integrations/tools/serpapi.ipynb index b9e32f1d40d..c2dc69cec13 100644 --- a/docs/docs/integrations/tools/serpapi.ipynb +++ b/docs/docs/integrations/tools/serpapi.ipynb @@ -103,7 +103,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.agents import Tool\n", + "from langchain_core.tools import Tool\n", "\n", "# You can create the tool to pass to an agent\n", "repl_tool = Tool(\n", diff --git a/docs/docs/integrations/tools/wikipedia.ipynb b/docs/docs/integrations/tools/wikipedia.ipynb index 723b2eb0744..b4cfdae9515 100644 --- a/docs/docs/integrations/tools/wikipedia.ipynb +++ b/docs/docs/integrations/tools/wikipedia.ipynb @@ -33,7 +33,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.tools import WikipediaQueryRun\n", + "from langchain_community.tools import WikipediaQueryRun\n", "from langchain_community.utilities import WikipediaAPIWrapper" ] }, diff --git a/docs/docs/integrations/vectorstores/annoy.ipynb b/docs/docs/integrations/vectorstores/annoy.ipynb index 315a3b7576f..72792259e6e 100644 --- a/docs/docs/integrations/vectorstores/annoy.ipynb +++ b/docs/docs/integrations/vectorstores/annoy.ipynb @@ -497,8 +497,8 @@ "import uuid\n", "\n", "from annoy import AnnoyIndex\n", - "from langchain_community.docstore.document import Document\n", "from langchain_community.docstore.in_memory import InMemoryDocstore\n", + "from langchain_core.documents import Document\n", "\n", "metadatas = [{\"x\": \"food\"}, {\"x\": \"food\"}, {\"x\": \"stuff\"}, {\"x\": \"animal\"}]\n", "\n", diff --git a/docs/docs/integrations/vectorstores/azure_cosmos_db.ipynb b/docs/docs/integrations/vectorstores/azure_cosmos_db.ipynb index db5daf7ec47..2fa1ce9794c 100644 --- a/docs/docs/integrations/vectorstores/azure_cosmos_db.ipynb +++ b/docs/docs/integrations/vectorstores/azure_cosmos_db.ipynb @@ -178,7 +178,13 @@ "outputs": [ { "data": { - "text/plain": "{'raw': {'defaultShard': {'numIndexesBefore': 1,\n 'numIndexesAfter': 2,\n 'createdCollectionAutomatically': False,\n 'ok': 1}},\n 'ok': 1}" + "text/plain": [ + "{'raw': {'defaultShard': {'numIndexesBefore': 1,\n", + " 'numIndexesAfter': 2,\n", + " 'createdCollectionAutomatically': False,\n", + " 'ok': 1}},\n", + " 'ok': 1}" + ] }, "execution_count": 5, "metadata": {}, diff --git a/docs/docs/integrations/vectorstores/azuresearch.ipynb b/docs/docs/integrations/vectorstores/azuresearch.ipynb index ffa429d9a80..f6345272f5e 100644 --- a/docs/docs/integrations/vectorstores/azuresearch.ipynb +++ b/docs/docs/integrations/vectorstores/azuresearch.ipynb @@ -770,7 +770,6 @@ "pygments_lexer": "ipython3", "version": "3.11.7" }, - "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "645053d6307d413a1a75681b5ebb6449bb2babba4bcb0bf65a1ddc3dbefb108a" diff --git a/docs/docs/integrations/vectorstores/bagel.ipynb b/docs/docs/integrations/vectorstores/bagel.ipynb index c29f5847409..29ac3cf9eec 100644 --- a/docs/docs/integrations/vectorstores/bagel.ipynb +++ b/docs/docs/integrations/vectorstores/bagel.ipynb @@ -292,8 +292,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/vectorstores/bageldb.ipynb b/docs/docs/integrations/vectorstores/bageldb.ipynb index ed07db31c8b..e3605d7ee3b 100644 --- a/docs/docs/integrations/vectorstores/bageldb.ipynb +++ b/docs/docs/integrations/vectorstores/bageldb.ipynb @@ -292,8 +292,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/vectorstores/baiduvectordb.ipynb b/docs/docs/integrations/vectorstores/baiduvectordb.ipynb index 63fe0cbbd40..89cdc1a22ae 100644 --- a/docs/docs/integrations/vectorstores/baiduvectordb.ipynb +++ b/docs/docs/integrations/vectorstores/baiduvectordb.ipynb @@ -37,11 +37,11 @@ }, "outputs": [], "source": [ - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.embeddings.fake import FakeEmbeddings\n", "from langchain_community.vectorstores import BaiduVectorDB\n", - "from langchain_community.vectorstores.baiduvectordb import ConnectionParams" + "from langchain_community.vectorstores.baiduvectordb import ConnectionParams\n", + "from langchain_text_splitters import CharacterTextSplitter" ] }, { diff --git a/docs/docs/integrations/vectorstores/couchbase.ipynb b/docs/docs/integrations/vectorstores/couchbase.ipynb index 76a4b398612..9e18bf91970 100644 --- a/docs/docs/integrations/vectorstores/couchbase.ipynb +++ b/docs/docs/integrations/vectorstores/couchbase.ipynb @@ -341,8 +341,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", + "from langchain_text_splitters import CharacterTextSplitter\n", "\n", "loader = TextLoader(\"../../how_to/state_of_the_union.txt\")\n", "documents = loader.load()\n", diff --git a/docs/docs/integrations/vectorstores/documentdb.ipynb b/docs/docs/integrations/vectorstores/documentdb.ipynb index 7ac610f299c..64be6f516d8 100644 --- a/docs/docs/integrations/vectorstores/documentdb.ipynb +++ b/docs/docs/integrations/vectorstores/documentdb.ipynb @@ -142,13 +142,13 @@ }, "outputs": [], "source": [ - "from langchain.document_loaders import TextLoader\n", - "from langchain.embeddings import OpenAIEmbeddings\n", - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain.vectorstores.documentdb import (\n", " DocumentDBSimilarityType,\n", " DocumentDBVectorSearch,\n", ")\n", + "from langchain_community.document_loaders import TextLoader\n", + "from langchain_openai import OpenAIEmbeddings\n", + "from langchain_text_splitters import CharacterTextSplitter\n", "\n", "SOURCE_FILE_NAME = \"../../how_to/state_of_the_union.txt\"\n", "\n", diff --git a/docs/docs/integrations/vectorstores/duckdb.ipynb b/docs/docs/integrations/vectorstores/duckdb.ipynb index 3be07eace0b..bff41b1278e 100644 --- a/docs/docs/integrations/vectorstores/duckdb.ipynb +++ b/docs/docs/integrations/vectorstores/duckdb.ipynb @@ -42,8 +42,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.embeddings import OpenAIEmbeddings\n", - "from langchain.vectorstores import DuckDB" + "from langchain.vectorstores import DuckDB\n", + "from langchain_openai import OpenAIEmbeddings" ] }, { @@ -52,7 +52,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders import TextLoader\n", + "from langchain_community.document_loaders import TextLoader\n", "from langchain_text_splitters import CharacterTextSplitter\n", "\n", "loader = TextLoader(\"../../how_to/state_of_the_union.txt\")\n", diff --git a/docs/docs/integrations/vectorstores/ecloud_vector_search.ipynb b/docs/docs/integrations/vectorstores/ecloud_vector_search.ipynb index d11d5ca411e..0082c5c0b6e 100644 --- a/docs/docs/integrations/vectorstores/ecloud_vector_search.ipynb +++ b/docs/docs/integrations/vectorstores/ecloud_vector_search.ipynb @@ -66,10 +66,10 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders import TextLoader\n", - "from langchain.embeddings.openai import OpenAIEmbeddings\n", - "from langchain.text_splitter import CharacterTextSplitter\n", - "from langchain.vectorstores import EcloudESVectorStore" + "from langchain.vectorstores import EcloudESVectorStore\n", + "from langchain_community.document_loaders import TextLoader\n", + "from langchain_openai import OpenAIEmbeddings\n", + "from langchain_text_splitters import CharacterTextSplitter" ] }, { diff --git a/docs/docs/integrations/vectorstores/epsilla.ipynb b/docs/docs/integrations/vectorstores/epsilla.ipynb index f8377859b34..e0bfbd84c4d 100644 --- a/docs/docs/integrations/vectorstores/epsilla.ipynb +++ b/docs/docs/integrations/vectorstores/epsilla.ipynb @@ -154,8 +154,7 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.17" - }, - "orig_nbformat": 4 + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/docs/docs/integrations/vectorstores/faiss.ipynb b/docs/docs/integrations/vectorstores/faiss.ipynb index 39997d1adf5..13425e7cc90 100644 --- a/docs/docs/integrations/vectorstores/faiss.ipynb +++ b/docs/docs/integrations/vectorstores/faiss.ipynb @@ -83,7 +83,7 @@ "metadata": { "tags": [] }, - "outputs": [ + "outputs": [ { "data": { "text/plain": [ diff --git a/docs/docs/integrations/vectorstores/google_bigquery_vector_search.ipynb b/docs/docs/integrations/vectorstores/google_bigquery_vector_search.ipynb index 5238e2cdfc5..e7d336d3361 100644 --- a/docs/docs/integrations/vectorstores/google_bigquery_vector_search.ipynb +++ b/docs/docs/integrations/vectorstores/google_bigquery_vector_search.ipynb @@ -239,8 +239,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.vectorstores.utils import DistanceStrategy\n", "from langchain_community.vectorstores import BigQueryVectorSearch\n", + "from langchain_community.vectorstores.utils import DistanceStrategy\n", "\n", "store = BigQueryVectorSearch(\n", " project_id=PROJECT_ID,\n", diff --git a/docs/docs/integrations/vectorstores/google_cloud_sql_mysql.ipynb b/docs/docs/integrations/vectorstores/google_cloud_sql_mysql.ipynb index c42ccfbe578..60b8ccce2b2 100644 --- a/docs/docs/integrations/vectorstores/google_cloud_sql_mysql.ipynb +++ b/docs/docs/integrations/vectorstores/google_cloud_sql_mysql.ipynb @@ -1,585 +1,585 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Google Cloud SQL for MySQL\n", - "\n", - "> [Cloud SQL](https://cloud.google.com/sql) is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability. It offers PostgreSQL, MySQL, and SQL Server database engines. Extend your database application to build AI-powered experiences leveraging Cloud SQL's LangChain integrations.\n", - "\n", - "This notebook goes over how to use `Cloud SQL for MySQL` to store vector embeddings with the `MySQLVectorStore` class.\n", - "\n", - "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/).\n", - "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/docs/vector_store.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Before you begin\n", - "\n", - "To run this notebook, you will need to do the following:\n", - "\n", - " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", - " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com)\n", - " * [Create a Cloud SQL instance.](https://cloud.google.com/sql/docs/mysql/connect-instance-auth-proxy#create-instance) (version must be >= **8.0.36** with **cloudsql_vector** database flag configured to \"On\")\n", - " * [Create a Cloud SQL database.](https://cloud.google.com/sql/docs/mysql/create-manage-databases)\n", - " * [Add a User to the database.](https://cloud.google.com/sql/docs/mysql/create-manage-users)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 🦜🔗 Library Installation\n", - "Install the integration library, `langchain-google-cloud-sql-mysql`, and the library for the embedding service, `langchain-google-vertexai`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "0ZITIDE160OD" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --quiet langchain-google-cloud-sql-mysql langchain-google-vertexai" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "v40bB_GMcr9f" - }, - "source": [ - "**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "v6jBDnYnNM08" - }, - "outputs": [], - "source": [ - "# # Automatically restart kernel after installs so that your environment can access the new packages\n", - "# import IPython\n", - "\n", - "# app = IPython.Application.instance()\n", - "# app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "yygMe6rPWxHS" - }, - "source": [ - "### 🔐 Authentication\n", - "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", - "\n", - "* If you are using Colab to run this notebook, use the cell below and continue.\n", - "* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "PTXN1_DSXj2b" - }, - "outputs": [], - "source": [ - "from google.colab import auth\n", - "\n", - "auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "NEvB9BoLEulY" - }, - "source": [ - "### ☁ Set Your Google Cloud Project\n", - "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", - "\n", - "If you don't know your project ID, try the following:\n", - "\n", - "* Run `gcloud config list`.\n", - "* Run `gcloud projects list`.\n", - "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "gfkS3yVRE4_W" - }, - "outputs": [], - "source": [ - "# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n", - "\n", - "PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n", - "\n", - "# Set the project id\n", - "!gcloud config set project {PROJECT_ID}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "f8f2830ee9ca1e01" - }, - "source": [ - "## Basic Usage" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "OMvzMWRrR6n7" - }, - "source": [ - "### Set Cloud SQL database values\n", - "Find your database values, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql?_ga=2.223735448.2062268965.1707700487-2088871159.1707257687).\n", - "\n", - "**Note:** MySQL vector support is only available on MySQL instances with version **>= 8.0.36**.\n", - "\n", - "For existing instances, you may need to perform a [self-service maintenance update](https://cloud.google.com/sql/docs/mysql/self-service-maintenance) to update your maintenance version to **MYSQL_8_0_36.R20240401.03_00** or greater. Once updated, [configure your database flags](https://cloud.google.com/sql/docs/mysql/flags) to have the new **cloudsql_vector** flag to \"On\"." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title Set Your Values Here { display-mode: \"form\" }\n", - "REGION = \"us-central1\" # @param {type: \"string\"}\n", - "INSTANCE = \"my-mysql-instance\" # @param {type: \"string\"}\n", - "DATABASE = \"my-database\" # @param {type: \"string\"}\n", - "TABLE_NAME = \"vector_store\" # @param {type: \"string\"}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "QuQigs4UoFQ2" - }, - "source": [ - "### MySQLEngine Connection Pool\n", - "\n", - "One of the requirements and arguments to establish Cloud SQL as a vector store is a `MySQLEngine` object. The `MySQLEngine` configures a connection pool to your Cloud SQL database, enabling successful connections from your application and following industry best practices.\n", - "\n", - "To create a `MySQLEngine` using `MySQLEngine.from_instance()` you need to provide only 4 things:\n", - "\n", - "1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n", - "1. `region` : Region where the Cloud SQL instance is located.\n", - "1. `instance` : The name of the Cloud SQL instance.\n", - "1. `database` : The name of the database to connect to on the Cloud SQL instance.\n", - "\n", - "By default, [IAM database authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication#iam-db-auth) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the envionment.\n", - "\n", - "For more informatin on IAM database authentication please see:\n", - "\n", - "* [Configure an instance for IAM database authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances)\n", - "* [Manage users with IAM database authentication](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users)\n", - "\n", - "Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/mysql/built-in-authentication) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `MySQLEngine.from_instance()`:\n", - "\n", - "* `user` : Database user to use for built-in database authentication and login\n", - "* `password` : Database password to use for built-in database authentication and login.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "guVURf1QLL53" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_mysql import MySQLEngine\n", - "\n", - "engine = MySQLEngine.from_instance(\n", - " project_id=PROJECT_ID, region=REGION, instance=INSTANCE, database=DATABASE\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Initialize a table\n", - "The `MySQLVectorStore` class requires a database table. The `MySQLEngine` class has a helper method `init_vectorstore_table()` that can be used to create a table with the proper schema for you." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "avlyHEMn6gzU" - }, - "outputs": [], - "source": [ - "engine.init_vectorstore_table(\n", - " table_name=TABLE_NAME,\n", - " vector_size=768, # Vector size for VertexAI model(textembedding-gecko@latest)\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create an embedding class instance\n", - "\n", - "You can use any [LangChain embeddings model](/docs/integrations/text_embedding/).\n", - "You may need to enable the Vertex AI API to use `VertexAIEmbeddings`.\n", - "\n", - "We recommend pinning the embedding model's version for production, learn more about the [Text embeddings models](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text-embeddings)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "5utKIdq7KYi5" - }, - "outputs": [], - "source": [ - "# enable Vertex AI API\n", - "!gcloud services enable aiplatform.googleapis.com" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Vb2RJocV9_LQ" - }, - "outputs": [], - "source": [ - "from langchain_google_vertexai import VertexAIEmbeddings\n", - "\n", - "embedding = VertexAIEmbeddings(\n", - " model_name=\"textembedding-gecko@latest\", project=PROJECT_ID\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "e1tl0aNx7SWy" - }, - "source": [ - "### Initialize a default MySQLVectorStore\n", - "\n", - "To initialize a `MySQLVectorStore` class you need to provide only 3 things:\n", - "\n", - "1. `engine` - An instance of a `MySQLEngine` engine.\n", - "1. `embedding_service` - An instance of a LangChain embedding model.\n", - "1. `table_name` : The name of the table within the Cloud SQL database to use as the vector store." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "z-AZyzAQ7bsf" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_mysql import MySQLVectorStore\n", - "\n", - "store = MySQLVectorStore(\n", - " engine=engine,\n", - " embedding_service=embedding,\n", - " table_name=TABLE_NAME,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Add texts" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "nrDvGWIOLL54" - }, - "outputs": [], - "source": [ - "import uuid\n", - "\n", - "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", - "metadatas = [{\"len\": len(t)} for t in all_texts]\n", - "ids = [str(uuid.uuid4()) for _ in all_texts]\n", - "\n", - "store.add_texts(all_texts, metadatas=metadatas, ids=ids)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Delete texts\n", - "\n", - "Delete vectors from the vector store by ID." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "store.delete([ids[1]])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Search for documents" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "id": "fpqeZgUeLL54", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "f674a3af-452c-4d58-bb62-cbf514a9e1e3" - }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Pineapple\n" - ] - } - ], - "source": [ - "query = \"I'd like a fruit.\"\n", - "docs = store.similarity_search(query)\n", - "print(docs[0].page_content)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Search for documents by vector\n", - "\n", - "It is also possible to do a search for documents similar to a given embedding vector using `similarity_search_by_vector` which accepts an embedding vector as a parameter instead of a string." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "N-NC5jgGLL55", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "69a1f9de-a830-450d-8a5e-118b36815a46" - }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[Document(page_content='Pineapple', metadata={'len': 9}), Document(page_content='Banana', metadata={'len': 6})]\n" - ] - } - ], - "source": [ - "query_vector = embedding.embed_query(query)\n", - "docs = store.similarity_search_by_vector(query_vector, k=2)\n", - "print(docs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Add an index\n", - "Speed up vector search queries by applying a vector index. Learn more about [MySQL vector indexes](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/src/langchain_google_cloud_sql_mysql/indexes.py).\n", - "\n", - "**Note:** For IAM database authentication (default usage), the IAM database user will need to be granted the following permissions by a privileged database user for full control of vector indexes.\n", - "\n", - "```\n", - "GRANT EXECUTE ON PROCEDURE mysql.create_vector_index TO ''@'%';\n", - "GRANT EXECUTE ON PROCEDURE mysql.alter_vector_index TO ''@'%';\n", - "GRANT EXECUTE ON PROCEDURE mysql.drop_vector_index TO ''@'%';\n", - "GRANT SELECT ON mysql.vector_indexes TO ''@'%';\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_mysql import VectorIndex\n", - "\n", - "store.apply_vector_index(VectorIndex())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Remove an index" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "store.drop_vector_index()" - ] - }, - { - "cell_type": "markdown", - "source": [ - "## Advanced Usage" - ], - "metadata": {} - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create a MySQLVectorStore with custom metadata\n", - "\n", - "A vector store can take advantage of relational data to filter similarity searches.\n", - "\n", - "Create a table and `MySQLVectorStore` instance with custom metadata columns." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "eANG7_8qLL55" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_mysql import Column\n", - "\n", - "# set table name\n", - "CUSTOM_TABLE_NAME = \"vector_store_custom\"\n", - "\n", - "engine.init_vectorstore_table(\n", - " table_name=CUSTOM_TABLE_NAME,\n", - " vector_size=768, # VertexAI model: textembedding-gecko@latest\n", - " metadata_columns=[Column(\"len\", \"INTEGER\")],\n", - ")\n", - "\n", - "\n", - "# initialize MySQLVectorStore with custom metadata columns\n", - "custom_store = MySQLVectorStore(\n", - " engine=engine,\n", - " embedding_service=embedding,\n", - " table_name=CUSTOM_TABLE_NAME,\n", - " metadata_columns=[\"len\"],\n", - " # connect to an existing VectorStore by customizing the table schema:\n", - " # id_column=\"uuid\",\n", - " # content_column=\"documents\",\n", - " # embedding_column=\"vectors\",\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "bj2d-c2sLL5-" - }, - "source": [ - "### Search for documents with metadata filter\n", - "\n", - "It can be helpful to narrow down the documents before working with them.\n", - "\n", - "For example, documents can be filtered on metadata using the `filter` argument." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "Sqfgk6EOLL5-", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "a10c74e2-fe48-4cf9-ba2f-85aecb2490d0" - }, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[Document(page_content='Pineapple', metadata={'len': 9}), Document(page_content='Banana', metadata={'len': 6}), Document(page_content='Apples and oranges', metadata={'len': 18}), Document(page_content='Cars and airplanes', metadata={'len': 18})]\n" - ] - } - ], - "source": [ - "import uuid\n", - "\n", - "# add texts to the vector store\n", - "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", - "metadatas = [{\"len\": len(t)} for t in all_texts]\n", - "ids = [str(uuid.uuid4()) for _ in all_texts]\n", - "custom_store.add_texts(all_texts, metadatas=metadatas, ids=ids)\n", - "\n", - "# use filter on search\n", - "query_vector = embedding.embed_query(\"I'd like a fruit.\")\n", - "docs = custom_store.similarity_search_by_vector(query_vector, filter=\"len >= 6\")\n", - "\n", - "print(docs)" - ] - } - ], - "metadata": { - "colab": { - "provenance": [], - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3", - "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.11.5" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Google Cloud SQL for MySQL\n", + "\n", + "> [Cloud SQL](https://cloud.google.com/sql) is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability. It offers PostgreSQL, MySQL, and SQL Server database engines. Extend your database application to build AI-powered experiences leveraging Cloud SQL's LangChain integrations.\n", + "\n", + "This notebook goes over how to use `Cloud SQL for MySQL` to store vector embeddings with the `MySQLVectorStore` class.\n", + "\n", + "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/).\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/docs/vector_store.ipynb)" + ] }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Before you begin\n", + "\n", + "To run this notebook, you will need to do the following:\n", + "\n", + " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", + " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com)\n", + " * [Create a Cloud SQL instance.](https://cloud.google.com/sql/docs/mysql/connect-instance-auth-proxy#create-instance) (version must be >= **8.0.36** with **cloudsql_vector** database flag configured to \"On\")\n", + " * [Create a Cloud SQL database.](https://cloud.google.com/sql/docs/mysql/create-manage-databases)\n", + " * [Add a User to the database.](https://cloud.google.com/sql/docs/mysql/create-manage-users)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 🦜🔗 Library Installation\n", + "Install the integration library, `langchain-google-cloud-sql-mysql`, and the library for the embedding service, `langchain-google-vertexai`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0ZITIDE160OD" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --quiet langchain-google-cloud-sql-mysql langchain-google-vertexai" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v40bB_GMcr9f" + }, + "source": [ + "**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "v6jBDnYnNM08" + }, + "outputs": [], + "source": [ + "# # Automatically restart kernel after installs so that your environment can access the new packages\n", + "# import IPython\n", + "\n", + "# app = IPython.Application.instance()\n", + "# app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yygMe6rPWxHS" + }, + "source": [ + "### 🔐 Authentication\n", + "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", + "\n", + "* If you are using Colab to run this notebook, use the cell below and continue.\n", + "* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "PTXN1_DSXj2b" + }, + "outputs": [], + "source": [ + "from google.colab import auth\n", + "\n", + "auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NEvB9BoLEulY" + }, + "source": [ + "### ☁ Set Your Google Cloud Project\n", + "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", + "\n", + "If you don't know your project ID, try the following:\n", + "\n", + "* Run `gcloud config list`.\n", + "* Run `gcloud projects list`.\n", + "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "gfkS3yVRE4_W" + }, + "outputs": [], + "source": [ + "# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n", + "\n", + "PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n", + "\n", + "# Set the project id\n", + "!gcloud config set project {PROJECT_ID}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "f8f2830ee9ca1e01" + }, + "source": [ + "## Basic Usage" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OMvzMWRrR6n7" + }, + "source": [ + "### Set Cloud SQL database values\n", + "Find your database values, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql?_ga=2.223735448.2062268965.1707700487-2088871159.1707257687).\n", + "\n", + "**Note:** MySQL vector support is only available on MySQL instances with version **>= 8.0.36**.\n", + "\n", + "For existing instances, you may need to perform a [self-service maintenance update](https://cloud.google.com/sql/docs/mysql/self-service-maintenance) to update your maintenance version to **MYSQL_8_0_36.R20240401.03_00** or greater. Once updated, [configure your database flags](https://cloud.google.com/sql/docs/mysql/flags) to have the new **cloudsql_vector** flag to \"On\"." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# @title Set Your Values Here { display-mode: \"form\" }\n", + "REGION = \"us-central1\" # @param {type: \"string\"}\n", + "INSTANCE = \"my-mysql-instance\" # @param {type: \"string\"}\n", + "DATABASE = \"my-database\" # @param {type: \"string\"}\n", + "TABLE_NAME = \"vector_store\" # @param {type: \"string\"}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QuQigs4UoFQ2" + }, + "source": [ + "### MySQLEngine Connection Pool\n", + "\n", + "One of the requirements and arguments to establish Cloud SQL as a vector store is a `MySQLEngine` object. The `MySQLEngine` configures a connection pool to your Cloud SQL database, enabling successful connections from your application and following industry best practices.\n", + "\n", + "To create a `MySQLEngine` using `MySQLEngine.from_instance()` you need to provide only 4 things:\n", + "\n", + "1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n", + "1. `region` : Region where the Cloud SQL instance is located.\n", + "1. `instance` : The name of the Cloud SQL instance.\n", + "1. `database` : The name of the database to connect to on the Cloud SQL instance.\n", + "\n", + "By default, [IAM database authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication#iam-db-auth) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the envionment.\n", + "\n", + "For more informatin on IAM database authentication please see:\n", + "\n", + "* [Configure an instance for IAM database authentication](https://cloud.google.com/sql/docs/mysql/create-edit-iam-instances)\n", + "* [Manage users with IAM database authentication](https://cloud.google.com/sql/docs/mysql/add-manage-iam-users)\n", + "\n", + "Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/mysql/built-in-authentication) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `MySQLEngine.from_instance()`:\n", + "\n", + "* `user` : Database user to use for built-in database authentication and login\n", + "* `password` : Database password to use for built-in database authentication and login.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "guVURf1QLL53" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_mysql import MySQLEngine\n", + "\n", + "engine = MySQLEngine.from_instance(\n", + " project_id=PROJECT_ID, region=REGION, instance=INSTANCE, database=DATABASE\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Initialize a table\n", + "The `MySQLVectorStore` class requires a database table. The `MySQLEngine` class has a helper method `init_vectorstore_table()` that can be used to create a table with the proper schema for you." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "avlyHEMn6gzU" + }, + "outputs": [], + "source": [ + "engine.init_vectorstore_table(\n", + " table_name=TABLE_NAME,\n", + " vector_size=768, # Vector size for VertexAI model(textembedding-gecko@latest)\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create an embedding class instance\n", + "\n", + "You can use any [LangChain embeddings model](/docs/integrations/text_embedding/).\n", + "You may need to enable the Vertex AI API to use `VertexAIEmbeddings`.\n", + "\n", + "We recommend pinning the embedding model's version for production, learn more about the [Text embeddings models](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text-embeddings)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "5utKIdq7KYi5" + }, + "outputs": [], + "source": [ + "# enable Vertex AI API\n", + "!gcloud services enable aiplatform.googleapis.com" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Vb2RJocV9_LQ" + }, + "outputs": [], + "source": [ + "from langchain_google_vertexai import VertexAIEmbeddings\n", + "\n", + "embedding = VertexAIEmbeddings(\n", + " model_name=\"textembedding-gecko@latest\", project=PROJECT_ID\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e1tl0aNx7SWy" + }, + "source": [ + "### Initialize a default MySQLVectorStore\n", + "\n", + "To initialize a `MySQLVectorStore` class you need to provide only 3 things:\n", + "\n", + "1. `engine` - An instance of a `MySQLEngine` engine.\n", + "1. `embedding_service` - An instance of a LangChain embedding model.\n", + "1. `table_name` : The name of the table within the Cloud SQL database to use as the vector store." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "z-AZyzAQ7bsf" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_mysql import MySQLVectorStore\n", + "\n", + "store = MySQLVectorStore(\n", + " engine=engine,\n", + " embedding_service=embedding,\n", + " table_name=TABLE_NAME,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Add texts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "nrDvGWIOLL54" + }, + "outputs": [], + "source": [ + "import uuid\n", + "\n", + "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", + "metadatas = [{\"len\": len(t)} for t in all_texts]\n", + "ids = [str(uuid.uuid4()) for _ in all_texts]\n", + "\n", + "store.add_texts(all_texts, metadatas=metadatas, ids=ids)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Delete texts\n", + "\n", + "Delete vectors from the vector store by ID." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "store.delete([ids[1]])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Search for documents" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "fpqeZgUeLL54", + "outputId": "f674a3af-452c-4d58-bb62-cbf514a9e1e3" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Pineapple\n" + ] + } + ], + "source": [ + "query = \"I'd like a fruit.\"\n", + "docs = store.similarity_search(query)\n", + "print(docs[0].page_content)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Search for documents by vector\n", + "\n", + "It is also possible to do a search for documents similar to a given embedding vector using `similarity_search_by_vector` which accepts an embedding vector as a parameter instead of a string." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "N-NC5jgGLL55", + "outputId": "69a1f9de-a830-450d-8a5e-118b36815a46" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Document(page_content='Pineapple', metadata={'len': 9}), Document(page_content='Banana', metadata={'len': 6})]\n" + ] + } + ], + "source": [ + "query_vector = embedding.embed_query(query)\n", + "docs = store.similarity_search_by_vector(query_vector, k=2)\n", + "print(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Add an index\n", + "Speed up vector search queries by applying a vector index. Learn more about [MySQL vector indexes](https://github.com/googleapis/langchain-google-cloud-sql-mysql-python/blob/main/src/langchain_google_cloud_sql_mysql/indexes.py).\n", + "\n", + "**Note:** For IAM database authentication (default usage), the IAM database user will need to be granted the following permissions by a privileged database user for full control of vector indexes.\n", + "\n", + "```\n", + "GRANT EXECUTE ON PROCEDURE mysql.create_vector_index TO ''@'%';\n", + "GRANT EXECUTE ON PROCEDURE mysql.alter_vector_index TO ''@'%';\n", + "GRANT EXECUTE ON PROCEDURE mysql.drop_vector_index TO ''@'%';\n", + "GRANT SELECT ON mysql.vector_indexes TO ''@'%';\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_mysql import VectorIndex\n", + "\n", + "store.apply_vector_index(VectorIndex())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Remove an index" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "store.drop_vector_index()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Advanced Usage" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a MySQLVectorStore with custom metadata\n", + "\n", + "A vector store can take advantage of relational data to filter similarity searches.\n", + "\n", + "Create a table and `MySQLVectorStore` instance with custom metadata columns." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "eANG7_8qLL55" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_mysql import Column\n", + "\n", + "# set table name\n", + "CUSTOM_TABLE_NAME = \"vector_store_custom\"\n", + "\n", + "engine.init_vectorstore_table(\n", + " table_name=CUSTOM_TABLE_NAME,\n", + " vector_size=768, # VertexAI model: textembedding-gecko@latest\n", + " metadata_columns=[Column(\"len\", \"INTEGER\")],\n", + ")\n", + "\n", + "\n", + "# initialize MySQLVectorStore with custom metadata columns\n", + "custom_store = MySQLVectorStore(\n", + " engine=engine,\n", + " embedding_service=embedding,\n", + " table_name=CUSTOM_TABLE_NAME,\n", + " metadata_columns=[\"len\"],\n", + " # connect to an existing VectorStore by customizing the table schema:\n", + " # id_column=\"uuid\",\n", + " # content_column=\"documents\",\n", + " # embedding_column=\"vectors\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bj2d-c2sLL5-" + }, + "source": [ + "### Search for documents with metadata filter\n", + "\n", + "It can be helpful to narrow down the documents before working with them.\n", + "\n", + "For example, documents can be filtered on metadata using the `filter` argument." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Sqfgk6EOLL5-", + "outputId": "a10c74e2-fe48-4cf9-ba2f-85aecb2490d0" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Document(page_content='Pineapple', metadata={'len': 9}), Document(page_content='Banana', metadata={'len': 6}), Document(page_content='Apples and oranges', metadata={'len': 18}), Document(page_content='Cars and airplanes', metadata={'len': 18})]\n" + ] + } + ], + "source": [ + "import uuid\n", + "\n", + "# add texts to the vector store\n", + "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", + "metadatas = [{\"len\": len(t)} for t in all_texts]\n", + "ids = [str(uuid.uuid4()) for _ in all_texts]\n", + "custom_store.add_texts(all_texts, metadatas=metadatas, ids=ids)\n", + "\n", + "# use filter on search\n", + "query_vector = embedding.embed_query(\"I'd like a fruit.\")\n", + "docs = custom_store.similarity_search_by_vector(query_vector, filter=\"len >= 6\")\n", + "\n", + "print(docs)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/docs/docs/integrations/vectorstores/google_cloud_sql_pg.ipynb b/docs/docs/integrations/vectorstores/google_cloud_sql_pg.ipynb index 8e1b6fd68f3..2cc42250a52 100644 --- a/docs/docs/integrations/vectorstores/google_cloud_sql_pg.ipynb +++ b/docs/docs/integrations/vectorstores/google_cloud_sql_pg.ipynb @@ -1,548 +1,548 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Google Cloud SQL for PostgreSQL\n", - "\n", - "> [Cloud SQL](https://cloud.google.com/sql) is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability. It offers PostgreSQL, PostgreSQL, and SQL Server database engines. Extend your database application to build AI-powered experiences leveraging Cloud SQL's Langchain integrations.\n", - "\n", - "This notebook goes over how to use `Cloud SQL for PostgreSQL` to store vector embeddings with the `PostgresVectorStore` class.\n", - "\n", - "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/).\n", - "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-pg-python/blob/main/docs/vector_store.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Before you begin\n", - "\n", - "To run this notebook, you will need to do the following:\n", - "\n", - " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", - " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com)\n", - " * [Create a Cloud SQL instance.](https://cloud.google.com/sql/docs/postgres/connect-instance-auth-proxy#create-instance)\n", - " * [Create a Cloud SQL database.](https://cloud.google.com/sql/docs/postgres/create-manage-databases)\n", - " * [Add a User to the database.](https://cloud.google.com/sql/docs/postgres/create-manage-users)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "IR54BmgvdHT_" - }, - "source": [ - "### 🦜🔗 Library Installation\n", - "Install the integration library, `langchain-google-cloud-sql-pg`, and the library for the embedding service, `langchain-google-vertexai`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 1000 - }, - "id": "0ZITIDE160OD", - "outputId": "e184bc0d-6541-4e0a-82d2-1e216db00a2d" - }, - "outputs": [], - "source": [ - "%pip install --upgrade --quiet langchain-google-cloud-sql-pg langchain-google-vertexai" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "v40bB_GMcr9f" - }, - "source": [ - "**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "v6jBDnYnNM08", - "metadata": { - "id": "v6jBDnYnNM08" - }, - "outputs": [], - "source": [ - "# # Automatically restart kernel after installs so that your environment can access the new packages\n", - "# import IPython\n", - "\n", - "# app = IPython.Application.instance()\n", - "# app.kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "id": "yygMe6rPWxHS", - "metadata": { - "id": "yygMe6rPWxHS" - }, - "source": [ - "### 🔐 Authentication\n", - "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", - "\n", - "* If you are using Colab to run this notebook, use the cell below and continue.\n", - "* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "PTXN1_DSXj2b", - "metadata": { - "id": "PTXN1_DSXj2b" - }, - "outputs": [], - "source": [ - "from google.colab import auth\n", - "\n", - "auth.authenticate_user()" - ] - }, - { - "cell_type": "markdown", - "id": "NEvB9BoLEulY", - "metadata": { - "id": "NEvB9BoLEulY" - }, - "source": [ - "### ☁ Set Your Google Cloud Project\n", - "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", - "\n", - "If you don't know your project ID, try the following:\n", - "\n", - "* Run `gcloud config list`.\n", - "* Run `gcloud projects list`.\n", - "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "gfkS3yVRE4_W", - "metadata": { - "cellView": "form", - "id": "gfkS3yVRE4_W" - }, - "outputs": [], - "source": [ - "# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n", - "\n", - "PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n", - "\n", - "# Set the project id\n", - "!gcloud config set project {PROJECT_ID}" - ] - }, - { - "cell_type": "markdown", - "id": "f8f2830ee9ca1e01", - "metadata": { - "id": "f8f2830ee9ca1e01" - }, - "source": [ - "## Basic Usage" - ] - }, - { - "cell_type": "markdown", - "id": "OMvzMWRrR6n7", - "metadata": { - "id": "OMvzMWRrR6n7" - }, - "source": [ - "### Set Cloud SQL database values\n", - "Find your database values, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql?_ga=2.223735448.2062268965.1707700487-2088871159.1707257687)." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "irl7eMFnSPZr", - "metadata": { - "id": "irl7eMFnSPZr" - }, - "outputs": [], - "source": [ - "# @title Set Your Values Here { display-mode: \"form\" }\n", - "REGION = \"us-central1\" # @param {type: \"string\"}\n", - "INSTANCE = \"my-pg-instance\" # @param {type: \"string\"}\n", - "DATABASE = \"my-database\" # @param {type: \"string\"}\n", - "TABLE_NAME = \"vector_store\" # @param {type: \"string\"}" - ] - }, - { - "cell_type": "markdown", - "id": "QuQigs4UoFQ2", - "metadata": { - "id": "QuQigs4UoFQ2" - }, - "source": [ - "### PostgresEngine Connection Pool\n", - "\n", - "One of the requirements and arguments to establish Cloud SQL as a vector store is a `PostgresEngine` object. The `PostgresEngine` configures a connection pool to your Cloud SQL database, enabling successful connections from your application and following industry best practices.\n", - "\n", - "To create a `PostgresEngine` using `PostgresEngine.from_instance()` you need to provide only 4 things:\n", - "\n", - "1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n", - "1. `region` : Region where the Cloud SQL instance is located.\n", - "1. `instance` : The name of the Cloud SQL instance.\n", - "1. `database` : The name of the database to connect to on the Cloud SQL instance.\n", - "\n", - "By default, [IAM database authentication](https://cloud.google.com/sql/docs/postgres/iam-authentication#iam-db-auth) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the envionment.\n", - "\n", - "For more informatin on IAM database authentication please see:\n", - "\n", - "* [Configure an instance for IAM database authentication](https://cloud.google.com/sql/docs/postgres/create-edit-iam-instances)\n", - "* [Manage users with IAM database authentication](https://cloud.google.com/sql/docs/postgres/add-manage-iam-users)\n", - "\n", - "Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/postgres/built-in-authentication) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `PostgresEngine.from_instance()`:\n", - "\n", - "* `user` : Database user to use for built-in database authentication and login\n", - "* `password` : Database password to use for built-in database authentication and login.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\"**Note**: This tutorial demonstrates the async interface. All async methods have corresponding sync methods.\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import PostgresEngine\n", - "\n", - "engine = await PostgresEngine.afrom_instance(\n", - " project_id=PROJECT_ID, region=REGION, instance=INSTANCE, database=DATABASE\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "D9Xs2qhm6X56" - }, - "source": [ - "### Initialize a table\n", - "The `PostgresVectorStore` class requires a database table. The `PostgresEngine` engine has a helper method `init_vectorstore_table()` that can be used to create a table with the proper schema for you." - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": { - "id": "avlyHEMn6gzU" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import PostgresEngine\n", - "\n", - "await engine.ainit_vectorstore_table(\n", - " table_name=TABLE_NAME,\n", - " vector_size=768, # Vector size for VertexAI model(textembedding-gecko@latest)\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create an embedding class instance\n", - "\n", - "You can use any [LangChain embeddings model](/docs/integrations/text_embedding/).\n", - "You may need to enable Vertex AI API to use `VertexAIEmbeddings`. We recommend setting the embedding model's version for production, learn more about the [Text embeddings models](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text-embeddings)." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "5utKIdq7KYi5", - "metadata": { - "id": "5utKIdq7KYi5" - }, - "outputs": [], - "source": [ - "# enable Vertex AI API\n", - "!gcloud services enable aiplatform.googleapis.com" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "Vb2RJocV9_LQ", - "outputId": "37f5dc74-2512-47b2-c135-f34c10afdcf4" - }, - "outputs": [], - "source": [ - "from langchain_google_vertexai import VertexAIEmbeddings\n", - "\n", - "embedding = VertexAIEmbeddings(\n", - " model_name=\"textembedding-gecko@latest\", project=PROJECT_ID\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "e1tl0aNx7SWy" - }, - "source": [ - "### Initialize a default PostgresVectorStore" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "z-AZyzAQ7bsf" - }, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import PostgresVectorStore\n", - "\n", - "store = await PostgresVectorStore.create( # Use .create() to initialize an async vector store\n", - " engine=engine,\n", - " table_name=TABLE_NAME,\n", - " embedding_service=embedding,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Add texts" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import uuid\n", - "\n", - "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", - "metadatas = [{\"len\": len(t)} for t in all_texts]\n", - "ids = [str(uuid.uuid4()) for _ in all_texts]\n", - "\n", - "await store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Delete texts" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "await store.adelete([ids[1]])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Search for documents" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "query = \"I'd like a fruit.\"\n", - "docs = await store.asimilarity_search(query)\n", - "print(docs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Search for documents by vector" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "query_vector = embedding.embed_query(query)\n", - "docs = await store.asimilarity_search_by_vector(query_vector, k=2)\n", - "print(docs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Add a Index\n", - "Speed up vector search queries by applying a vector index. Learn more about [vector indexes](https://cloud.google.com/blog/products/databases/faster-similarity-search-performance-with-pgvector-indexes)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg.indexes import IVFFlatIndex\n", - "\n", - "index = IVFFlatIndex()\n", - "await store.aapply_vector_index(index)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Re-index" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "await store.areindex() # Re-index using default index name" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Remove an index" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "await store.aadrop_vector_index() # Delete index using default name" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create a custom Vector Store\n", - "A Vector Store can take advantage of relational data to filter similarity searches.\n", - "\n", - "Create a table with custom metadata columns." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_google_cloud_sql_pg import Column\n", - "\n", - "# Set table name\n", - "TABLE_NAME = \"vectorstore_custom\"\n", - "\n", - "await engine.ainit_vectorstore_table(\n", - " table_name=TABLE_NAME,\n", - " vector_size=768, # VertexAI model: textembedding-gecko@latest\n", - " metadata_columns=[Column(\"len\", \"INTEGER\")],\n", - ")\n", - "\n", - "\n", - "# Initialize PostgresVectorStore\n", - "custom_store = await PostgresVectorStore.create(\n", - " engine=engine,\n", - " table_name=TABLE_NAME,\n", - " embedding_service=embedding,\n", - " metadata_columns=[\"len\"],\n", - " # Connect to a existing VectorStore by customizing the table schema:\n", - " # id_column=\"uuid\",\n", - " # content_column=\"documents\",\n", - " # embedding_column=\"vectors\",\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Search for documents with metadata filter" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import uuid\n", - "\n", - "# Add texts to the Vector Store\n", - "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", - "metadatas = [{\"len\": len(t)} for t in all_texts]\n", - "ids = [str(uuid.uuid4()) for _ in all_texts]\n", - "await store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n", - "\n", - "# Use filter on search\n", - "docs = await custom_store.asimilarity_search_by_vector(query_vector, filter=\"len >= 6\")\n", - "\n", - "print(docs)" - ] - } - ], - "metadata": { - "colab": { - "provenance": [], - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3", - "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.11.5" - } + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Google Cloud SQL for PostgreSQL\n", + "\n", + "> [Cloud SQL](https://cloud.google.com/sql) is a fully managed relational database service that offers high performance, seamless integration, and impressive scalability. It offers PostgreSQL, PostgreSQL, and SQL Server database engines. Extend your database application to build AI-powered experiences leveraging Cloud SQL's Langchain integrations.\n", + "\n", + "This notebook goes over how to use `Cloud SQL for PostgreSQL` to store vector embeddings with the `PostgresVectorStore` class.\n", + "\n", + "Learn more about the package on [GitHub](https://github.com/googleapis/langchain-google-cloud-sql-pg-python/).\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/googleapis/langchain-google-cloud-sql-pg-python/blob/main/docs/vector_store.ipynb)" + ] }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Before you begin\n", + "\n", + "To run this notebook, you will need to do the following:\n", + "\n", + " * [Create a Google Cloud Project](https://developers.google.com/workspace/guides/create-project)\n", + " * [Enable the Cloud SQL Admin API.](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin.googleapis.com)\n", + " * [Create a Cloud SQL instance.](https://cloud.google.com/sql/docs/postgres/connect-instance-auth-proxy#create-instance)\n", + " * [Create a Cloud SQL database.](https://cloud.google.com/sql/docs/postgres/create-manage-databases)\n", + " * [Add a User to the database.](https://cloud.google.com/sql/docs/postgres/create-manage-users)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IR54BmgvdHT_" + }, + "source": [ + "### 🦜🔗 Library Installation\n", + "Install the integration library, `langchain-google-cloud-sql-pg`, and the library for the embedding service, `langchain-google-vertexai`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "0ZITIDE160OD", + "outputId": "e184bc0d-6541-4e0a-82d2-1e216db00a2d" + }, + "outputs": [], + "source": [ + "%pip install --upgrade --quiet langchain-google-cloud-sql-pg langchain-google-vertexai" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v40bB_GMcr9f" + }, + "source": [ + "**Colab only:** Uncomment the following cell to restart the kernel or use the button to restart the kernel. For Vertex AI Workbench you can restart the terminal using the button on top." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "v6jBDnYnNM08", + "metadata": { + "id": "v6jBDnYnNM08" + }, + "outputs": [], + "source": [ + "# # Automatically restart kernel after installs so that your environment can access the new packages\n", + "# import IPython\n", + "\n", + "# app = IPython.Application.instance()\n", + "# app.kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "id": "yygMe6rPWxHS", + "metadata": { + "id": "yygMe6rPWxHS" + }, + "source": [ + "### 🔐 Authentication\n", + "Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.\n", + "\n", + "* If you are using Colab to run this notebook, use the cell below and continue.\n", + "* If you are using Vertex AI Workbench, check out the setup instructions [here](https://github.com/GoogleCloudPlatform/generative-ai/tree/main/setup-env)." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "PTXN1_DSXj2b", + "metadata": { + "id": "PTXN1_DSXj2b" + }, + "outputs": [], + "source": [ + "from google.colab import auth\n", + "\n", + "auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "id": "NEvB9BoLEulY", + "metadata": { + "id": "NEvB9BoLEulY" + }, + "source": [ + "### ☁ Set Your Google Cloud Project\n", + "Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook.\n", + "\n", + "If you don't know your project ID, try the following:\n", + "\n", + "* Run `gcloud config list`.\n", + "* Run `gcloud projects list`.\n", + "* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "gfkS3yVRE4_W", + "metadata": { + "cellView": "form", + "id": "gfkS3yVRE4_W" + }, + "outputs": [], + "source": [ + "# @markdown Please fill in the value below with your Google Cloud project ID and then run the cell.\n", + "\n", + "PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n", + "\n", + "# Set the project id\n", + "!gcloud config set project {PROJECT_ID}" + ] + }, + { + "cell_type": "markdown", + "id": "f8f2830ee9ca1e01", + "metadata": { + "id": "f8f2830ee9ca1e01" + }, + "source": [ + "## Basic Usage" + ] + }, + { + "cell_type": "markdown", + "id": "OMvzMWRrR6n7", + "metadata": { + "id": "OMvzMWRrR6n7" + }, + "source": [ + "### Set Cloud SQL database values\n", + "Find your database values, in the [Cloud SQL Instances page](https://console.cloud.google.com/sql?_ga=2.223735448.2062268965.1707700487-2088871159.1707257687)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "irl7eMFnSPZr", + "metadata": { + "id": "irl7eMFnSPZr" + }, + "outputs": [], + "source": [ + "# @title Set Your Values Here { display-mode: \"form\" }\n", + "REGION = \"us-central1\" # @param {type: \"string\"}\n", + "INSTANCE = \"my-pg-instance\" # @param {type: \"string\"}\n", + "DATABASE = \"my-database\" # @param {type: \"string\"}\n", + "TABLE_NAME = \"vector_store\" # @param {type: \"string\"}" + ] + }, + { + "cell_type": "markdown", + "id": "QuQigs4UoFQ2", + "metadata": { + "id": "QuQigs4UoFQ2" + }, + "source": [ + "### PostgresEngine Connection Pool\n", + "\n", + "One of the requirements and arguments to establish Cloud SQL as a vector store is a `PostgresEngine` object. The `PostgresEngine` configures a connection pool to your Cloud SQL database, enabling successful connections from your application and following industry best practices.\n", + "\n", + "To create a `PostgresEngine` using `PostgresEngine.from_instance()` you need to provide only 4 things:\n", + "\n", + "1. `project_id` : Project ID of the Google Cloud Project where the Cloud SQL instance is located.\n", + "1. `region` : Region where the Cloud SQL instance is located.\n", + "1. `instance` : The name of the Cloud SQL instance.\n", + "1. `database` : The name of the database to connect to on the Cloud SQL instance.\n", + "\n", + "By default, [IAM database authentication](https://cloud.google.com/sql/docs/postgres/iam-authentication#iam-db-auth) will be used as the method of database authentication. This library uses the IAM principal belonging to the [Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials) sourced from the envionment.\n", + "\n", + "For more informatin on IAM database authentication please see:\n", + "\n", + "* [Configure an instance for IAM database authentication](https://cloud.google.com/sql/docs/postgres/create-edit-iam-instances)\n", + "* [Manage users with IAM database authentication](https://cloud.google.com/sql/docs/postgres/add-manage-iam-users)\n", + "\n", + "Optionally, [built-in database authentication](https://cloud.google.com/sql/docs/postgres/built-in-authentication) using a username and password to access the Cloud SQL database can also be used. Just provide the optional `user` and `password` arguments to `PostgresEngine.from_instance()`:\n", + "\n", + "* `user` : Database user to use for built-in database authentication and login\n", + "* `password` : Database password to use for built-in database authentication and login.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"**Note**: This tutorial demonstrates the async interface. All async methods have corresponding sync methods.\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import PostgresEngine\n", + "\n", + "engine = await PostgresEngine.afrom_instance(\n", + " project_id=PROJECT_ID, region=REGION, instance=INSTANCE, database=DATABASE\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "D9Xs2qhm6X56" + }, + "source": [ + "### Initialize a table\n", + "The `PostgresVectorStore` class requires a database table. The `PostgresEngine` engine has a helper method `init_vectorstore_table()` that can be used to create a table with the proper schema for you." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "id": "avlyHEMn6gzU" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import PostgresEngine\n", + "\n", + "await engine.ainit_vectorstore_table(\n", + " table_name=TABLE_NAME,\n", + " vector_size=768, # Vector size for VertexAI model(textembedding-gecko@latest)\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create an embedding class instance\n", + "\n", + "You can use any [LangChain embeddings model](/docs/integrations/text_embedding/).\n", + "You may need to enable Vertex AI API to use `VertexAIEmbeddings`. We recommend setting the embedding model's version for production, learn more about the [Text embeddings models](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/text-embeddings)." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5utKIdq7KYi5", + "metadata": { + "id": "5utKIdq7KYi5" + }, + "outputs": [], + "source": [ + "# enable Vertex AI API\n", + "!gcloud services enable aiplatform.googleapis.com" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Vb2RJocV9_LQ", + "outputId": "37f5dc74-2512-47b2-c135-f34c10afdcf4" + }, + "outputs": [], + "source": [ + "from langchain_google_vertexai import VertexAIEmbeddings\n", + "\n", + "embedding = VertexAIEmbeddings(\n", + " model_name=\"textembedding-gecko@latest\", project=PROJECT_ID\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "e1tl0aNx7SWy" + }, + "source": [ + "### Initialize a default PostgresVectorStore" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "z-AZyzAQ7bsf" + }, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import PostgresVectorStore\n", + "\n", + "store = await PostgresVectorStore.create( # Use .create() to initialize an async vector store\n", + " engine=engine,\n", + " table_name=TABLE_NAME,\n", + " embedding_service=embedding,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Add texts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import uuid\n", + "\n", + "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", + "metadatas = [{\"len\": len(t)} for t in all_texts]\n", + "ids = [str(uuid.uuid4()) for _ in all_texts]\n", + "\n", + "await store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Delete texts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "await store.adelete([ids[1]])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Search for documents" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "query = \"I'd like a fruit.\"\n", + "docs = await store.asimilarity_search(query)\n", + "print(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Search for documents by vector" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "query_vector = embedding.embed_query(query)\n", + "docs = await store.asimilarity_search_by_vector(query_vector, k=2)\n", + "print(docs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add a Index\n", + "Speed up vector search queries by applying a vector index. Learn more about [vector indexes](https://cloud.google.com/blog/products/databases/faster-similarity-search-performance-with-pgvector-indexes)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg.indexes import IVFFlatIndex\n", + "\n", + "index = IVFFlatIndex()\n", + "await store.aapply_vector_index(index)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Re-index" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "await store.areindex() # Re-index using default index name" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Remove an index" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "await store.aadrop_vector_index() # Delete index using default name" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create a custom Vector Store\n", + "A Vector Store can take advantage of relational data to filter similarity searches.\n", + "\n", + "Create a table with custom metadata columns." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_google_cloud_sql_pg import Column\n", + "\n", + "# Set table name\n", + "TABLE_NAME = \"vectorstore_custom\"\n", + "\n", + "await engine.ainit_vectorstore_table(\n", + " table_name=TABLE_NAME,\n", + " vector_size=768, # VertexAI model: textembedding-gecko@latest\n", + " metadata_columns=[Column(\"len\", \"INTEGER\")],\n", + ")\n", + "\n", + "\n", + "# Initialize PostgresVectorStore\n", + "custom_store = await PostgresVectorStore.create(\n", + " engine=engine,\n", + " table_name=TABLE_NAME,\n", + " embedding_service=embedding,\n", + " metadata_columns=[\"len\"],\n", + " # Connect to a existing VectorStore by customizing the table schema:\n", + " # id_column=\"uuid\",\n", + " # content_column=\"documents\",\n", + " # embedding_column=\"vectors\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Search for documents with metadata filter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import uuid\n", + "\n", + "# Add texts to the Vector Store\n", + "all_texts = [\"Apples and oranges\", \"Cars and airplanes\", \"Pineapple\", \"Train\", \"Banana\"]\n", + "metadatas = [{\"len\": len(t)} for t in all_texts]\n", + "ids = [str(uuid.uuid4()) for _ in all_texts]\n", + "await store.aadd_texts(all_texts, metadatas=metadatas, ids=ids)\n", + "\n", + "# Use filter on search\n", + "docs = await custom_store.asimilarity_search_by_vector(query_vector, filter=\"len >= 6\")\n", + "\n", + "print(docs)" + ] + } + ], + "metadata": { + "colab": { + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/docs/docs/integrations/vectorstores/google_memorystore_redis.ipynb b/docs/docs/integrations/vectorstores/google_memorystore_redis.ipynb index 7ae476c5da4..75fcf5238bc 100644 --- a/docs/docs/integrations/vectorstores/google_memorystore_redis.ipynb +++ b/docs/docs/integrations/vectorstores/google_memorystore_redis.ipynb @@ -187,8 +187,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", + "from langchain_text_splitters import CharacterTextSplitter\n", "\n", "loader = TextLoader(\"./state_of_the_union.txt\")\n", "documents = loader.load()\n", diff --git a/docs/docs/integrations/vectorstores/kdbai.ipynb b/docs/docs/integrations/vectorstores/kdbai.ipynb index e0121796ad0..302bf5cb7d8 100644 --- a/docs/docs/integrations/vectorstores/kdbai.ipynb +++ b/docs/docs/integrations/vectorstores/kdbai.ipynb @@ -35,7 +35,7 @@ "import pandas as pd\n", "import requests\n", "from langchain.chains import RetrievalQA\n", - "from langchain.document_loaders import PyPDFLoader\n", + "from langchain_community.document_loaders import PyPDFLoader\n", "from langchain_community.vectorstores import KDBAI\n", "from langchain_openai import ChatOpenAI, OpenAIEmbeddings" ] diff --git a/docs/docs/integrations/vectorstores/kinetica.ipynb b/docs/docs/integrations/vectorstores/kinetica.ipynb index 7798418b9a6..ef29f4b97be 100644 --- a/docs/docs/integrations/vectorstores/kinetica.ipynb +++ b/docs/docs/integrations/vectorstores/kinetica.ipynb @@ -113,13 +113,13 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores import (\n", " DistanceStrategy,\n", " Kinetica,\n", " KineticaSettings,\n", ")\n", + "from langchain_core.documents import Document\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter" ] diff --git a/docs/docs/integrations/vectorstores/lancedb.ipynb b/docs/docs/integrations/vectorstores/lancedb.ipynb index 52a1b365795..bcdd38756fe 100644 --- a/docs/docs/integrations/vectorstores/lancedb.ipynb +++ b/docs/docs/integrations/vectorstores/lancedb.ipynb @@ -62,8 +62,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.document_loaders import TextLoader\n", - "from langchain.vectorstores import LanceDB\n", + "from langchain_community.document_loaders import TextLoader\n", + "from langchain_community.vectorstores import LanceDB\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter\n", "\n", diff --git a/docs/docs/integrations/vectorstores/lantern.ipynb b/docs/docs/integrations/vectorstores/lantern.ipynb index d1599a68900..01fb3447283 100644 --- a/docs/docs/integrations/vectorstores/lantern.ipynb +++ b/docs/docs/integrations/vectorstores/lantern.ipynb @@ -108,9 +108,9 @@ "outputs": [], "source": [ "from langchain_community.document_loaders import TextLoader\n", - "from langchain_community.embeddings import OpenAIEmbeddings\n", "from langchain_community.vectorstores import Lantern\n", "from langchain_core.documents import Document\n", + "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter" ] }, diff --git a/docs/docs/integrations/vectorstores/milvus.ipynb b/docs/docs/integrations/vectorstores/milvus.ipynb index 48283001f7a..6eaabfef79e 100644 --- a/docs/docs/integrations/vectorstores/milvus.ipynb +++ b/docs/docs/integrations/vectorstores/milvus.ipynb @@ -340,7 +340,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", + "from langchain_core.documents import Document\n", "\n", "# Insert data sample\n", "docs = [\n", diff --git a/docs/docs/integrations/vectorstores/neo4jvector.ipynb b/docs/docs/integrations/vectorstores/neo4jvector.ipynb index c18fe20e3ff..20788d0d28a 100644 --- a/docs/docs/integrations/vectorstores/neo4jvector.ipynb +++ b/docs/docs/integrations/vectorstores/neo4jvector.ipynb @@ -73,9 +73,9 @@ }, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores import Neo4jVector\n", + "from langchain_core.documents import Document\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter" ] diff --git a/docs/docs/integrations/vectorstores/pgembedding.ipynb b/docs/docs/integrations/vectorstores/pgembedding.ipynb index c4128704a05..838a1be2d8b 100644 --- a/docs/docs/integrations/vectorstores/pgembedding.ipynb +++ b/docs/docs/integrations/vectorstores/pgembedding.ipynb @@ -81,9 +81,9 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores import PGEmbedding\n", + "from langchain_core.documents import Document\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter" ] diff --git a/docs/docs/integrations/vectorstores/pgvecto_rs.ipynb b/docs/docs/integrations/vectorstores/pgvecto_rs.ipynb index 8771b0d88a6..2eb6aa9f755 100644 --- a/docs/docs/integrations/vectorstores/pgvecto_rs.ipynb +++ b/docs/docs/integrations/vectorstores/pgvecto_rs.ipynb @@ -26,10 +26,10 @@ "source": [ "from typing import List\n", "\n", - "from langchain_community.docstore.document import Document\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.embeddings.fake import FakeEmbeddings\n", "from langchain_community.vectorstores.pgvecto_rs import PGVecto_rs\n", + "from langchain_core.documents import Document\n", "from langchain_text_splitters import CharacterTextSplitter" ] }, diff --git a/docs/docs/integrations/vectorstores/sap_hanavector.ipynb b/docs/docs/integrations/vectorstores/sap_hanavector.ipynb index e364d9e5f04..ff84478a188 100644 --- a/docs/docs/integrations/vectorstores/sap_hanavector.ipynb +++ b/docs/docs/integrations/vectorstores/sap_hanavector.ipynb @@ -109,9 +109,9 @@ }, "outputs": [], "source": [ - "from langchain_community.docstore.document import Document\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores.hanavector import HanaDB\n", + "from langchain_core.documents import Document\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter\n", "\n", diff --git a/docs/docs/integrations/vectorstores/tencentvectordb.ipynb b/docs/docs/integrations/vectorstores/tencentvectordb.ipynb index bdd646a4b67..f07d46449ed 100644 --- a/docs/docs/integrations/vectorstores/tencentvectordb.ipynb +++ b/docs/docs/integrations/vectorstores/tencentvectordb.ipynb @@ -157,7 +157,9 @@ "outputs": [ { "data": { - "text/plain": "'Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.'" + "text/plain": [ + "'Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.'" + ] }, "execution_count": 8, "metadata": {}, @@ -182,7 +184,9 @@ "outputs": [ { "data": { - "text/plain": "'Ankush went to Princeton'" + "text/plain": [ + "'Ankush went to Princeton'" + ] }, "execution_count": 9, "metadata": {}, @@ -224,7 +228,12 @@ "outputs": [ { "data": { - "text/plain": "[Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'superhero', 'director': 'Christopher Nolan'}),\n Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'superhero', 'director': 'Christopher Nolan'}),\n Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'superhero', 'director': 'Christopher Nolan'}),\n Document(page_content='Inception is a 2010 science fiction action film written and directed by Christopher Nolan.', metadata={'year': 2010, 'rating': '8.8', 'genre': 'science fiction', 'director': 'Christopher Nolan'})]" + "text/plain": [ + "[Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'superhero', 'director': 'Christopher Nolan'}),\n", + " Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'superhero', 'director': 'Christopher Nolan'}),\n", + " Document(page_content='The Dark Knight is a 2008 superhero film directed by Christopher Nolan.', metadata={'year': 2008, 'rating': '9.0', 'genre': 'superhero', 'director': 'Christopher Nolan'}),\n", + " Document(page_content='Inception is a 2010 science fiction action film written and directed by Christopher Nolan.', metadata={'year': 2010, 'rating': '8.8', 'genre': 'science fiction', 'director': 'Christopher Nolan'})]" + ] }, "execution_count": 2, "metadata": {}, diff --git a/docs/docs/integrations/vectorstores/tidb_vector.ipynb b/docs/docs/integrations/vectorstores/tidb_vector.ipynb index e8ca6c7c82e..0f453cb9c9a 100644 --- a/docs/docs/integrations/vectorstores/tidb_vector.ipynb +++ b/docs/docs/integrations/vectorstores/tidb_vector.ipynb @@ -77,10 +77,10 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores import TiDBVectorStore\n", - "from langchain_openai import OpenAIEmbeddings" + "from langchain_openai import OpenAIEmbeddings\n", + "from langchain_text_splitters import CharacterTextSplitter" ] }, { diff --git a/docs/docs/integrations/vectorstores/timescalevector.ipynb b/docs/docs/integrations/vectorstores/timescalevector.ipynb index 6c48a5e5e6c..8bd067979f7 100644 --- a/docs/docs/integrations/vectorstores/timescalevector.ipynb +++ b/docs/docs/integrations/vectorstores/timescalevector.ipynb @@ -122,10 +122,10 @@ "source": [ "from datetime import datetime, timedelta\n", "\n", - "from langchain_community.docstore.document import Document\n", "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.document_loaders.json_loader import JSONLoader\n", "from langchain_community.vectorstores.timescalevector import TimescaleVector\n", + "from langchain_core.documents import Document\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import CharacterTextSplitter" ] diff --git a/docs/docs/integrations/vectorstores/upstash.ipynb b/docs/docs/integrations/vectorstores/upstash.ipynb index d0e44efa709..fe49cd59666 100644 --- a/docs/docs/integrations/vectorstores/upstash.ipynb +++ b/docs/docs/integrations/vectorstores/upstash.ipynb @@ -104,8 +104,8 @@ } ], "source": [ - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", + "from langchain_text_splitters import CharacterTextSplitter\n", "\n", "loader = TextLoader(\"../../how_to/state_of_the_union.txt\")\n", "documents = loader.load()\n", diff --git a/docs/docs/integrations/vectorstores/vespa.ipynb b/docs/docs/integrations/vectorstores/vespa.ipynb index 41b674b1754..abacdc296ca 100644 --- a/docs/docs/integrations/vectorstores/vespa.ipynb +++ b/docs/docs/integrations/vectorstores/vespa.ipynb @@ -943,4 +943,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/docs/docs/integrations/vectorstores/vikingdb.ipynb b/docs/docs/integrations/vectorstores/vikingdb.ipynb index e309f7b7d9b..3e8d32f4ae2 100644 --- a/docs/docs/integrations/vectorstores/vikingdb.ipynb +++ b/docs/docs/integrations/vectorstores/vikingdb.ipynb @@ -68,7 +68,7 @@ }, "outputs": [], "source": [ - "from langchain.document_loaders import TextLoader\n", + "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.vectorstores.vikingdb import VikingDB, VikingDBConfig\n", "from langchain_openai import OpenAIEmbeddings\n", "from langchain_text_splitters import RecursiveCharacterTextSplitter" diff --git a/docs/docs/integrations/vectorstores/weaviate.ipynb b/docs/docs/integrations/vectorstores/weaviate.ipynb index b2d6d722024..bd610770553 100644 --- a/docs/docs/integrations/vectorstores/weaviate.ipynb +++ b/docs/docs/integrations/vectorstores/weaviate.ipynb @@ -119,9 +119,9 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain_community.document_loaders import TextLoader\n", - "from langchain_community.embeddings.openai import OpenAIEmbeddings" + "from langchain_openai import OpenAIEmbeddings\n", + "from langchain_text_splitters import CharacterTextSplitter" ] }, { @@ -587,7 +587,7 @@ } ], "source": [ - "from langchain_community.chat_models import ChatOpenAI\n", + "from langchain_openai import ChatOpenAI\n", "\n", "llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n", "llm.predict(\"What did the president say about Justice Breyer\")" @@ -633,7 +633,7 @@ "outputs": [], "source": [ "from langchain.chains import RetrievalQAWithSourcesChain\n", - "from langchain_community.llms import OpenAI" + "from langchain_openai import OpenAI" ] }, { @@ -822,7 +822,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_community.chat_models import ChatOpenAI\n", + "from langchain_openai import ChatOpenAI\n", "\n", "llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)" ] diff --git a/docs/docs/integrations/vectorstores/yellowbrick.ipynb b/docs/docs/integrations/vectorstores/yellowbrick.ipynb index dc789a86659..a8ccb56eb7d 100644 --- a/docs/docs/integrations/vectorstores/yellowbrick.ipynb +++ b/docs/docs/integrations/vectorstores/yellowbrick.ipynb @@ -98,8 +98,8 @@ "import psycopg2\n", "from IPython.display import Markdown, display\n", "from langchain.chains import LLMChain, RetrievalQAWithSourcesChain\n", - "from langchain.schema import Document\n", "from langchain_community.vectorstores import Yellowbrick\n", + "from langchain_core.documents import Document\n", "from langchain_openai import ChatOpenAI, OpenAIEmbeddings\n", "from langchain_text_splitters import RecursiveCharacterTextSplitter\n", "\n", diff --git a/docs/docs/integrations/vectorstores/zep.ipynb b/docs/docs/integrations/vectorstores/zep.ipynb index 191f449e013..5e5bd852483 100644 --- a/docs/docs/integrations/vectorstores/zep.ipynb +++ b/docs/docs/integrations/vectorstores/zep.ipynb @@ -2,6 +2,10 @@ "cells": [ { "cell_type": "markdown", + "id": "550edc01b00149cd", + "metadata": { + "collapsed": false + }, "source": [ "# Zep\n", "> Recall, understand, and extract data from chat histories. Power personalized AI experiences.\n", @@ -28,11 +32,7 @@ "- If you pass in an `Embeddings` instance Zep will use this to embed documents rather than auto-embed them.\n", "You must also set your document collection to `isAutoEmbedded === false`. \n", "- If you set your collection to `isAutoEmbedded === false`, you must pass in an `Embeddings` instance." - ], - "metadata": { - "collapsed": false - }, - "id": "550edc01b00149cd" + ] }, { "cell_type": "markdown",