From 21707a9bb5f779dc98469f3f5d16e53192507768 Mon Sep 17 00:00:00 2001 From: choincnp Date: Wed, 22 Jan 2025 22:11:49 +0900 Subject: [PATCH 1/3] feat: Second draft of 02-LangGraph-Naive-RAG --- .../02-LangGraph-Naive-RAG.ipynb | 598 ++++++++++++++++++ .../assets/02-langgraph-naive-rag.png | Bin 0 -> 19915 bytes 2 files changed, 598 insertions(+) create mode 100644 17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb create mode 100644 17-LangGraph/02-Structures/assets/02-langgraph-naive-rag.png diff --git a/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb b/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb new file mode 100644 index 000000000..533bbb74d --- /dev/null +++ b/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb @@ -0,0 +1,598 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "635d8ebb", + "metadata": {}, + "source": [ + "# Naive RAG\n", + "\n", + "- Author: [Youngjun cho](https://github.com/choincnp)\n", + "- Design: \n", + "- Peer Review: \n", + "- This is a part of [LangChain Open Tutorial](https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial)\n", + "\n", + "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/LangChain-OpenTutorial/LangChain-OpenTutorial/blob/main/99-TEMPLATE/00-BASE-TEMPLATE-EXAMPLE.ipynb) [![Open in GitHub](https://img.shields.io/badge/Open%20in%20GitHub-181717?style=flat-square&logo=github&logoColor=white)](https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial/blob/main/99-TEMPLATE/00-BASE-TEMPLATE-EXAMPLE.ipynb)\n", + "\n", + "## Overview\n", + "\n", + "In this chapter, Section 02(Naive-RAG) through Section 05(Add-Query-Rewrite) is not an independent section, but cover one topic.\n", + "\n", + "We'll make a basic RAG on this section, and make more complicated RAG as sections goes by.\n", + "\n", + "### Table of Contents\n", + "\n", + "- [Overview](#overview)\n", + "- [Environment Setup](#environment-setup)\n", + "- [Procedure](#procedure)\n", + "- [Creating a basic PDF based retrieval chain](#creating-a-basic-pdf-based-retrieval-chain)\n", + "- [Defining State](#defining-state)\n", + "- [Defining Node](#defining-nodes)\n", + "- [Creating the graph](#creating-the-graph)\n", + "- [Excuting the graph](#executing-the-graph)\n", + "\n", + "### References\n", + "\n", + "- [LangGraph Streaming](https://python.langchain.com/docs/concepts/streaming/)\n", + "----" + ] + }, + { + "cell_type": "markdown", + "id": "c6c7aba4", + "metadata": {}, + "source": [ + "## Environment Setup\n", + "\n", + "Setting up your environment is the first step. See the [Environment Setup](https://wikidocs.net/257836) guide for more details.\n", + "\n", + "\n", + "**[Note]**\n", + "\n", + "The langchain-opentutorial is a package of easy-to-use environment setup guidance, useful functions and utilities for tutorials.\n", + "Check out the [`langchain-opentutorial`](https://github.com/LangChain-OpenTutorial/langchain-opentutorial-pypi) for more details." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "21943adb", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture --no-stderr\n", + "%pip install langchain-opentutorial" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "f25ec196", + "metadata": {}, + "outputs": [], + "source": [ + "# Install required packages\n", + "from langchain_opentutorial import package\n", + "\n", + "package.install(\n", + " [\n", + " \"langsmith\",\n", + " \"langchain\",\n", + " \"langchain_core\",\n", + " \"langchain_community\",\n", + " \"langgraph\",\n", + " \"typing\",\n", + " \"langchain-opentutorial\"\n", + " ],\n", + " verbose=False,\n", + " upgrade=False,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "690a9ae0", + "metadata": {}, + "source": [ + "You can set API keys in a `.env` file or set them manually.\n", + "\n", + "[Note] If you’re not using the `.env` file, no worries! Just enter the keys directly in the cell below, and you’re good to go." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "327c2c7c", + "metadata": {}, + "outputs": [], + "source": [ + "from dotenv import load_dotenv\n", + "from langchain_opentutorial import set_env\n", + "\n", + "# Attempt to load environment variables from a .env file; if unsuccessful, set them manually.\n", + "if not load_dotenv():\n", + " set_env(\n", + " {\n", + " \"OPENAI_API_KEY\": \"\",\n", + " \"LANGCHAIN_API_KEY\": \"\",\n", + " \"LANGCHAIN_TRACING_V2\": \"true\",\n", + " \"LANGCHAIN_ENDPOINT\": \"https://api.smith.langchain.com\",\n", + " \"LANGCHAIN_PROJECT\": \"02-LangGraph-Naive-RAG\", # set the project name same as the title\n", + " }\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "aa00c3f4", + "metadata": {}, + "source": [ + "## Procedure\n", + "\n", + "Perform `Naive RAG`, the basic RAG system which has 2 progress, **Retrieve** and **Generate** .\n", + "\n", + "You can see the structure in the image below.\n", + "\n", + "![](./assets/02-langgraph-naive-rag.png)" + ] + }, + { + "cell_type": "markdown", + "id": "56b83578", + "metadata": {}, + "source": [ + "## Creating a Basic PDF-Based Retrieval Chain\n", + "\n", + "This section creates a Retrieval Chain based on a **PDF document** . It is the simplest structure of a Retrieval Chain.\n", + "\n", + "In `LangGraph` , Retrievers and Chains are created separately. This allows detailed processing for each node." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "d8a4062a", + "metadata": {}, + "outputs": [], + "source": [ + "from rag.pdf import PDFRetrievalChain\n", + "\n", + "# Load the PDF document\n", + "pdf = PDFRetrievalChain([\"data/Newwhitepaper_Agents2.pdf\"]).create_chain()\n", + "\n", + "# Create retriever and chain\n", + "pdf_retriever = pdf.retriever\n", + "pdf_chain = pdf.chain" + ] + }, + { + "cell_type": "markdown", + "id": "34f7150f", + "metadata": {}, + "source": [ + "First, use the `pdf_retriever` to fetch search results.\n", + "\n", + "You can control the quantity to retrieve, by changing `self_k` argument in `pdf.py` file." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "6c98f04a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Document(id='401c509e-7251-4311-82b8-c554295717e0', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 3, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nThis combination of reasoning,\\nlogic, and access to external\\ninformation that are all connected\\nto a Generative AI model invokes\\nthe concept of an agent.\\nIntroduction\\nHumans are fantastic at messy pattern recognition tasks. However, they often rely on tools'),\n", + " Document(id='60d91217-f452-445b-abee-1ae4d9ec219f', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 37, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='frameworks, and continuous improvement mechanisms. Google’s Vertex AI platform\\nsimplifies this process by offering a fully managed environment with all the fundamental\\nelements covered earlier. Using a natural language interface, developers can rapidly'),\n", + " Document(id='cb6c39d2-5c6c-4b14-a74d-e91fbf2a70ec', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 3, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='- like books, Google Search, or a calculator - to supplement their prior knowledge before\\narriving at a conclusion. Just like humans, Generative AI models can be trained to use tools\\nto access real-time information or suggest a real-world action. For example, a model can'),\n", + " Document(id='8aee372d-85f4-4d27-a176-f49bed516922', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 37, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nProduction applications with Vertex\\nAI agents\\nWhile this whitepaper explored the core components of agents, building production-grade\\napplications requires integrating them with additional tools like user interfaces, evaluation'),\n", + " Document(id='7c6e2c4c-72da-4d7b-8d25-516f3adafafb', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 4, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='achieve its ultimate goal. While the notion of agents in AI is quite general and powerful, this\\nwhitepaper focuses on the specific types of agents that Generative AI models are capable of\\nbuilding at the time of publication.'),\n", + " Document(id='e7a0ff06-7dcf-4962-a79a-b6f28c920fd7', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 27, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Implementation and application\\nIn the context of Generative AI agents, Data Stores are typically implemented as a vector\\ndatabase that the developer wants the agent to have access to at runtime. While we won’t\\ncover vector databases in depth here, the key point to understand is that they store data'),\n", + " Document(id='412ed5e4-0454-40a3-9797-ae87174d3229', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 39, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nSummary\\nIn this whitepaper we’ve discussed the foundational building blocks of Generative AI\\nagents, their compositions, and effective ways to implement them in the form of cognitive\\narchitectures. Some key takeaways from this whitepaper include:'),\n", + " Document(id='aed6e11c-81b8-41d3-b05d-554554f19ece', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 6, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='while others may contain chained logic, involve additional machine learning algorithms, or\\nimplement other probabilistic reasoning techniques. We’ll discuss more about the detailed\\nimplementation of the agent orchestration layers in the cognitive architecture section.\\nSeptember 2024 7'),\n", + " Document(id='be854960-6503-4bdd-be0f-deee39d4a795', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 4, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nWhat is an agent?\\nIn its most fundamental form, a Generative AI agent can be defined as an application that\\nattempts to achieve a goal by observing the world and acting upon it using the tools that it\\nhas at its disposal. Agents are autonomous and can act independently of human intervention,'),\n", + " Document(id='d4ad3438-3453-4706-9fbb-0786fcf4ccc8', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 28, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nGeneration (RAG) based applications. These applications seek to extend the breadth and\\ndepth of a model’s knowledge beyond the foundational training data by giving the model\\naccess to data in various formats like:\\n• Website content')]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "search_result = pdf_retriever.invoke(\n", + " \"Where has the application of AI in healthcare been confined to so far?\"\n", + ")\n", + "search_result" + ] + }, + { + "cell_type": "markdown", + "id": "abf7eabc", + "metadata": {}, + "source": [ + "Pass the search result as context to the chain." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "80f1eea5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The application of AI in healthcare has so far been confined primarily to areas such as diagnostic assistance, patient management, and personalized treatment plans. Specific implementations include using AI for pattern recognition in medical imaging, predictive analytics for patient outcomes, and automating administrative tasks to improve efficiency.\n", + "\n", + "**Source**\n", + "- data/Newwhitepaper_Agents2.pdf (page 4)\n" + ] + } + ], + "source": [ + "# Generate an answer based on the search results\n", + "answer = pdf_chain.invoke(\n", + " {\n", + " \"question\": \"Where has the application of AI in healthcare been confined to so far?\",\n", + " \"context\": search_result,\n", + " \"chat_history\": [],\n", + " }\n", + ")\n", + "print(answer)" + ] + }, + { + "cell_type": "markdown", + "id": "0430cc3f", + "metadata": {}, + "source": [ + "## Defining State\n", + "\n", + "`State` defines the **shared state** among the nodes and another nodes.\n", + "\n", + "Typically, the `TypedDict` format is used." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "4e392f46", + "metadata": {}, + "outputs": [], + "source": [ + "from typing import Annotated, TypedDict\n", + "from langgraph.graph.message import add_messages\n", + "\n", + "# Define GraphState\n", + "class GraphState(TypedDict):\n", + " question: Annotated[str, \"Question\"] # Question\n", + " context: Annotated[str, \"Context\"] # Search results from the document\n", + " answer: Annotated[str, \"Answer\"] # Answer\n", + " messages: Annotated[list, add_messages] # Messages (accumulated list)" + ] + }, + { + "cell_type": "markdown", + "id": "c9e26176", + "metadata": {}, + "source": [ + "## Defining Nodes\n", + "\n", + "`Nodes` : These are nodes that handle each stage, typically implemented as Python functions. Inputs and outputs are the State values.\n", + "\n", + "[ **Note** ] \n", + "- A `State` is taken as input, performs the defined logic, and returns an **updated** `State` ." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "2892e164", + "metadata": {}, + "outputs": [], + "source": [ + "from rag.utils import format_docs\n", + "from langchain_opentutorial.messages import messages_to_history\n", + "\n", + "# Node that retrieve document\n", + "def retrieve_document(state: GraphState) -> GraphState:\n", + " # Get the question from the state\n", + " latest_question = state[\"question\"]\n", + "\n", + " # Search the document to find relevant sections\n", + " retrieved_docs = pdf_retriever.invoke(latest_question)\n", + "\n", + " # Format the retrieved documents (to input into a prompt)\n", + " retrieved_docs = format_docs(retrieved_docs)\n", + " \n", + " # Save the retrieved documents in the key named context\n", + " return {\"context\": retrieved_docs}\n", + "\n", + "\n", + "# Node that generate answer\n", + "def llm_answer(state: GraphState) -> GraphState:\n", + " # Get the question from the state\n", + " latest_question = state[\"question\"]\n", + "\n", + " # Get the retrieved documents from the state\n", + " context = state[\"context\"]\n", + "\n", + " # Call the chain to generate an answer\n", + " response = pdf_chain.invoke(\n", + " {\n", + " \"question\": latest_question,\n", + " \"context\": context,\n", + " \"chat_history\": messages_to_history(state[\"messages\"]),\n", + " }\n", + " )\n", + "\n", + " # Save the generated answer and (user question, answer) messages in the state\n", + " return {\n", + " \"answer\": response,\n", + " \"messages\": [(\"user\", latest_question), (\"assistant\", response)],\n", + " }" + ] + }, + { + "cell_type": "markdown", + "id": "303edffd", + "metadata": {}, + "source": [ + "## Creating the Graph\n", + "\n", + "`Edges` : Python functions that determine the next `Node` to execute based on the **current** `State` .\n", + "\n", + "There can be general edges and conditional edges." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "4ea7f66c", + "metadata": {}, + "outputs": [], + "source": [ + "from langgraph.graph import END, StateGraph\n", + "from langgraph.checkpoint.memory import MemorySaver\n", + "\n", + "# Create a graph\n", + "workflow = StateGraph(GraphState)\n", + "\n", + "# Define nodes\n", + "workflow.add_node(\"retrieve\", retrieve_document)\n", + "workflow.add_node(\"llm_answer\", llm_answer)\n", + "\n", + "# Define edges\n", + "workflow.add_edge(\"retrieve\", \"llm_answer\") # Retrieval -> Answer generation\n", + "workflow.add_edge(\"llm_answer\", END) # Answer generation -> End\n", + "\n", + "# Set entry point for the graph\n", + "workflow.set_entry_point(\"retrieve\")\n", + "\n", + "# Set up a checkpointer\n", + "memory = MemorySaver()\n", + "\n", + "# Compile the graph\n", + "app = workflow.compile(checkpointer=memory)" + ] + }, + { + "cell_type": "markdown", + "id": "1f5b7377", + "metadata": {}, + "source": [ + "Visualize the compiled graph." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "74add1cc", + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIQAAAFNCAIAAABOtlA4AAAAAXNSR0IArs4c6QAAIABJREFUeJztnXd8FOXWx8/2vtn0ZJNNNgkpBAIk1AABhSAtIKFJMYgFwXoFL5YXVBT02gALCHKvinCFawABEZTeIYC0QHrZ9E3b7Cbby8y8fyxGhCTgzmx2dpjvH/nMTjn7ZH57njZnnsPAMAxoyAHT0wWg+RNaDBJBi0EiaDFIBC0GiaDFIBHs7vmaeovpmq4pkC8oNugcGDY7PI7NYGyvKSbzNgrY7PA4DINLLQ3RYp8gnsDdd8mNYrTZbXvU5UbE/rgiocigrbEY+Gy2GXHYULTZZuYwmCTfRgE0NisTsP0NFepK0/p+I1EMqzMbY8Q+brpjDHcM+sqNrQqh5LymXmM1p/gGidkcwr/CI9hQZHXJ1WiRz/PRSe6wT7wYWyoLyk1tL8X0JdYseagwtcWJZbmtmmH+ocRaJrIBRzDUhiI+HB6FlQAApVBqQ1E2g7k8P4dYy4R5Boph/67Imx7WgxBrXkG92eTP5YUIREQZJMYzEAx76frJB0oJAAgRCDksVnZNCVEGifEMG4oYHPYHc/pXYzV/X1X4fq9U/KYIEOOsRs1nsZRCKf7SeCkWBOGzmP5cvAMRvNXUzVbNyebaB1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DPsLEKDPo+EyWxQ2zhIlLnyvichqOnqnbf1QcFRE67mHnfqOqSqz8c0RtUFUL5CFMDgcAEl9/oeDTjZXb9jD5vPBHx9pb9W5qMARMFoEPmgibKKy3mF7OPaWj4tO9LlAIxKt7D5dxiQlUIHLW9pK2cVn++S5OOD5ubof7fXrFt+YV3b2fI5UMz95IVPEA4NLzbxrKq+7ezwvytzZqXCjA+4mpA32DiCoekWLo7Na38y8UGjqdqzGrO+n+OsOn7t7NZPKDA4gqHgBYmlswewfjIdRuZ3YUMd11AZRC6cqeg4M7ySftAkTGQ8o4vEAev9DQ6QmCUMJ+RK7BD/Aj0JpSICFQCeKf9L0ZN2CAzMN3vHsYFxTxenx/Ym0SLAabyVyVOKTr3L4UYJAs+PnoJAKfZDghvuvNZDDSA8MF7gnzIgMiFnt6WAyfoIHe7bglhv6hwHAuk/VTXWluW4s77HuQwb7BY4Mi+skC3WHcjbG2FtTxSfHV05o6N9nvfvpI/T9JGu6+hdfdG4VuQ5HRIp3GAAAAw0lEQVRVhZfqLMYqc+d9LG8gRugTyOMvTxjopihbJ93xfkaDxaQytX1Rdr3FZvGuhQyYwOCzWG/E9U+U+HXDWzPd9+ZSndl4tKlaxOZo7dZjjdV2DAvlizgMRqVJ7wAsUihhAwm2GcxKY5sdRSaGRsVLfEv0utGB4UqRtHtukWfe6dPYzM1WS5RIymWy8vUtdhRNlPpxGEwybJcZWiVsThCho7n7xOtfsKQS3v3qMcWgxSARtBgkghaDRNBikAhaDBLx/3wyeFgvhXDqAAAAAElFTkSuQmCC", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from langchain_opentutorial.graphs import visualize_graph\n", + "\n", + "visualize_graph(app) " + ] + }, + { + "cell_type": "markdown", + "id": "0cf924d4", + "metadata": {}, + "source": [ + "## Executing the Graph\n", + "\n", + "- The `config` parameter provides configuration informations necessary for graph execution.\n", + "- `recursion_limit` : Sets the maximum recursion depth for graph execution.\n", + "- `inputs` : Provides the input data for the graph execution.\n", + "\n", + "The `stream_graph` function below streams only specific nodes.\n", + "\n", + "You can easily check the **streaming output** of a **specific node** ." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "b6765d83", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "==================================================\n", + "🔄 Node: \u001b[1;36mretrieve\u001b[0m 🔄\n", + "- - - - - - - - - - - - - - - - - - - - - - - - - \n", + "\u001b[1;32mcontext\u001b[0m:\n", + "Agents\n", + "This combination of reasoning,\n", + "logic, and access to external\n", + "information that are all connected\n", + "to a Generative AI model invokes\n", + "the concept of an agent.\n", + "Introduction\n", + "Humans are fantastic at messy pattern recognition tasks. However, they often rely on toolsdata/Newwhitepaper_Agents2.pdf4\n", + "frameworks, and continuous improvement mechanisms. Google’s Vertex AI platform\n", + "simplifies this process by offering a fully managed environment with all the fundamental\n", + "elements covered earlier. Using a natural language interface, developers can rapidlydata/Newwhitepaper_Agents2.pdf38\n", + "- like books, Google Search, or a calculator - to supplement their prior knowledge before\n", + "arriving at a conclusion. Just like humans, Generative AI models can be trained to use tools\n", + "to access real-time information or suggest a real-world action. For example, a model candata/Newwhitepaper_Agents2.pdf4\n", + "Agents\n", + "Production applications with Vertex\n", + "AI agents\n", + "While this whitepaper explored the core components of agents, building production-grade\n", + "applications requires integrating them with additional tools like user interfaces, evaluationdata/Newwhitepaper_Agents2.pdf38\n", + "achieve its ultimate goal. While the notion of agents in AI is quite general and powerful, this\n", + "whitepaper focuses on the specific types of agents that Generative AI models are capable of\n", + "building at the time of publication.data/Newwhitepaper_Agents2.pdf5\n", + "Implementation and application\n", + "In the context of Generative AI agents, Data Stores are typically implemented as a vector\n", + "database that the developer wants the agent to have access to at runtime. While we won’t\n", + "cover vector databases in depth here, the key point to understand is that they store datadata/Newwhitepaper_Agents2.pdf28\n", + "Agents\n", + "Summary\n", + "In this whitepaper we’ve discussed the foundational building blocks of Generative AI\n", + "agents, their compositions, and effective ways to implement them in the form of cognitive\n", + "architectures. Some key takeaways from this whitepaper include:data/Newwhitepaper_Agents2.pdf40\n", + "while others may contain chained logic, involve additional machine learning algorithms, or\n", + "implement other probabilistic reasoning techniques. We’ll discuss more about the detailed\n", + "implementation of the agent orchestration layers in the cognitive architecture section.\n", + "September 2024 7data/Newwhitepaper_Agents2.pdf7\n", + "Agents\n", + "What is an agent?\n", + "In its most fundamental form, a Generative AI agent can be defined as an application that\n", + "attempts to achieve a goal by observing the world and acting upon it using the tools that it\n", + "has at its disposal. Agents are autonomous and can act independently of human intervention,data/Newwhitepaper_Agents2.pdf5\n", + "Agents\n", + "Generation (RAG) based applications. These applications seek to extend the breadth and\n", + "depth of a model’s knowledge beyond the foundational training data by giving the model\n", + "access to data in various formats like:\n", + "• Website contentdata/Newwhitepaper_Agents2.pdf29\n", + "==================================================\n", + "\n", + "==================================================\n", + "🔄 Node: \u001b[1;36mllm_answer\u001b[0m 🔄\n", + "- - - - - - - - - - - - - - - - - - - - - - - - - \n", + "\u001b[1;32manswer\u001b[0m:\n", + "The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals. However, the context does not provide specific examples or limitations regarding the application of AI in healthcare.\n", + "\n", + "**Source**\n", + "- data/Newwhitepaper_Agents2.pdf (page 5)\n", + "('user', 'Where has the application of AI in healthcare been confined to so far?')\n", + "('assistant', 'The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals. However, the context does not provide specific examples or limitations regarding the application of AI in healthcare.\\n\\n**Source**\\n- data/Newwhitepaper_Agents2.pdf (page 5)')\n", + "==================================================\n" + ] + } + ], + "source": [ + "from langchain_core.runnables import RunnableConfig\n", + "from langchain_opentutorial.messages import invoke_graph, stream_graph, random_uuid\n", + "\n", + "# Configure settings (recursion limit, thread_id)\n", + "config = RunnableConfig(recursion_limit=20, configurable={\"thread_id\": random_uuid()})\n", + "\n", + "# Question input\n", + "inputs = GraphState(\n", + " question=\"Where has the application of AI in healthcare been confined to so far?\"\n", + ")\n", + "\n", + "# Execute the graph\n", + "invoke_graph(app, inputs, config)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "07a4505e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "==================================================\n", + "🔄 Node: \u001b[1;36mllm_answer\u001b[0m 🔄\n", + "- - - - - - - - - - - - - - - - - - - - - - - - - \n", + "The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals.\n", + "\n", + "**Source**\n", + "- data/Newwhitepaper_Agents2.pdf (page 5)" + ] + } + ], + "source": [ + "# Stream the graph outputs\n", + "stream_graph(app, inputs, config)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "405b1c79", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Question: Where has the application of AI in healthcare been confined to so far?\n", + "============================================================\n", + "Answer:\n", + "The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals.\n", + "\n", + "**Source**\n", + "- data/Newwhitepaper_Agents2.pdf (page 5)\n" + ] + } + ], + "source": [ + "outputs = app.get_state(config).values\n", + "\n", + "print(f'Question: {outputs[\"question\"]}')\n", + "print(\"===\" * 20)\n", + "print(f'Answer:\\n{outputs[\"answer\"]}')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "langchain-opentutorial-lQfVMvH8-py3.11", + "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.11.11" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/17-LangGraph/02-Structures/assets/02-langgraph-naive-rag.png b/17-LangGraph/02-Structures/assets/02-langgraph-naive-rag.png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fNp66r8X6``}r2ko|H>Z&O z@9=s1U{7F7R04G@U%MISvfA?9Je#5oNEIu@;=h#L5y10YkJrfH{K8wWcOXX$ugwQvi4 zDmMxJms~2}^8nb)5lGdSKs)DiDDxf2EVGv&Sn3eml^`F$>TVk0{B*57pE<{(#nWE5 zPlBP{)BbPIxPmp^a26O7l-vDgFoc~KFlvp(5ESM~(}1lRp1C!L(%Rywlj!xe3Ydo! zbSfI}0OQK#O`J2^69|5PZPb9c^<|av@9jZFhcpC=wfH8^9dh`^0+Uicl1RV^oqeCn zcKCDX+Yut$bkWoYcTY^5!z<4#pGY4@B`f%{W*RJb^?6Phchw-HaWKGvk_(sHzhss| zVGo=uD2#e?t}t^Li{|tUrPNUA>0cSIa56}s0c3N_gb-kG-u*%Pg$3w@YJ^VAo36dG zXOOm;&&cL?^f`hN&t05Yzlgy%gY%fLp`2LCs#9_&T5q|4%7NL(Ajbmb7GV;n4BLF_ zNpo(8k&Ly;dpU$Mbh-vk1EQ=t(>Mx2fb@Fm>^4=8Swbaur~I%64@us);8J?I)ykHW zUxe1?r;v2`>um!43 Date: Fri, 24 Jan 2025 21:23:52 +0900 Subject: [PATCH 2/3] fix: change table of contents and pdf file --- .../02-LangGraph-Naive-RAG.ipynb | 121 ++++++++---------- 1 file changed, 52 insertions(+), 69 deletions(-) diff --git a/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb b/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb index 533bbb74d..38ae49dd0 100644 --- a/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb +++ b/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb @@ -25,11 +25,11 @@ "- [Overview](#overview)\n", "- [Environment Setup](#environment-setup)\n", "- [Procedure](#procedure)\n", - "- [Creating a basic PDF based retrieval chain](#creating-a-basic-pdf-based-retrieval-chain)\n", + "- [Creating a Basic PDF-Based Retrieval Chain](#creating-a-basic-pdf-based-retrieval-chain)\n", "- [Defining State](#defining-state)\n", - "- [Defining Node](#defining-nodes)\n", - "- [Creating the graph](#creating-the-graph)\n", - "- [Excuting the graph](#executing-the-graph)\n", + "- [Defining Nodes](#defining-nodes)\n", + "- [Creating the Graph](#creating-the-graph)\n", + "- [Excuting the Graph](#executing-the-graph)\n", "\n", "### References\n", "\n", @@ -148,6 +148,13 @@ "In `LangGraph` , Retrievers and Chains are created separately. This allows detailed processing for each node." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": 4, @@ -158,7 +165,7 @@ "from rag.pdf import PDFRetrievalChain\n", "\n", "# Load the PDF document\n", - "pdf = PDFRetrievalChain([\"data/Newwhitepaper_Agents2.pdf\"]).create_chain()\n", + "pdf = PDFRetrievalChain([\"data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf\"]).create_chain()\n", "\n", "# Create retriever and chain\n", "pdf_retriever = pdf.retriever\n", @@ -184,16 +191,16 @@ { "data": { "text/plain": [ - "[Document(id='401c509e-7251-4311-82b8-c554295717e0', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 3, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nThis combination of reasoning,\\nlogic, and access to external\\ninformation that are all connected\\nto a Generative AI model invokes\\nthe concept of an agent.\\nIntroduction\\nHumans are fantastic at messy pattern recognition tasks. However, they often rely on tools'),\n", - " Document(id='60d91217-f452-445b-abee-1ae4d9ec219f', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 37, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='frameworks, and continuous improvement mechanisms. Google’s Vertex AI platform\\nsimplifies this process by offering a fully managed environment with all the fundamental\\nelements covered earlier. Using a natural language interface, developers can rapidly'),\n", - " Document(id='cb6c39d2-5c6c-4b14-a74d-e91fbf2a70ec', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 3, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='- like books, Google Search, or a calculator - to supplement their prior knowledge before\\narriving at a conclusion. Just like humans, Generative AI models can be trained to use tools\\nto access real-time information or suggest a real-world action. For example, a model can'),\n", - " Document(id='8aee372d-85f4-4d27-a176-f49bed516922', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 37, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nProduction applications with Vertex\\nAI agents\\nWhile this whitepaper explored the core components of agents, building production-grade\\napplications requires integrating them with additional tools like user interfaces, evaluation'),\n", - " Document(id='7c6e2c4c-72da-4d7b-8d25-516f3adafafb', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 4, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='achieve its ultimate goal. While the notion of agents in AI is quite general and powerful, this\\nwhitepaper focuses on the specific types of agents that Generative AI models are capable of\\nbuilding at the time of publication.'),\n", - " Document(id='e7a0ff06-7dcf-4962-a79a-b6f28c920fd7', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 27, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Implementation and application\\nIn the context of Generative AI agents, Data Stores are typically implemented as a vector\\ndatabase that the developer wants the agent to have access to at runtime. While we won’t\\ncover vector databases in depth here, the key point to understand is that they store data'),\n", - " Document(id='412ed5e4-0454-40a3-9797-ae87174d3229', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 39, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nSummary\\nIn this whitepaper we’ve discussed the foundational building blocks of Generative AI\\nagents, their compositions, and effective ways to implement them in the form of cognitive\\narchitectures. Some key takeaways from this whitepaper include:'),\n", - " Document(id='aed6e11c-81b8-41d3-b05d-554554f19ece', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 6, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='while others may contain chained logic, involve additional machine learning algorithms, or\\nimplement other probabilistic reasoning techniques. We’ll discuss more about the detailed\\nimplementation of the agent orchestration layers in the cognitive architecture section.\\nSeptember 2024 7'),\n", - " Document(id='be854960-6503-4bdd-be0f-deee39d4a795', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 4, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nWhat is an agent?\\nIn its most fundamental form, a Generative AI agent can be defined as an application that\\nattempts to achieve a goal by observing the world and acting upon it using the tools that it\\nhas at its disposal. Agents are autonomous and can act independently of human intervention,'),\n", - " Document(id='d4ad3438-3453-4706-9fbb-0786fcf4ccc8', metadata={'source': 'data/Newwhitepaper_Agents2.pdf', 'file_path': 'data/Newwhitepaper_Agents2.pdf', 'page': 28, 'total_pages': 42, 'CreationDate': \"D:20241113100853-07'00'\", 'Creator': 'Adobe InDesign 20.0 (Macintosh)', 'ModDate': \"D:20241113100858-07'00'\", 'Producer': 'Adobe PDF Library 17.0', 'Trapped': 'False'}, page_content='Agents\\nGeneration (RAG) based applications. These applications seek to extend the breadth and\\ndepth of a model’s knowledge beyond the foundational training data by giving the model\\naccess to data in various formats like:\\n• Website content')]" + "[Document(id='76d10387-a006-4d7c-8bd1-c316831d6094', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 14, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='activities. So far, however, AI applications in healthcare have been potential. Specific healthcare training should be provided to data\\nconfined to administrative tasks (i.e., Natural Language Processing scientists working in hospitals so that they can better understand'),\n", + " Document(id='f4f78deb-c8d9-4c84-a3e4-a91b0477413d', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 14, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='are great, as more use of AI in research and development could\\nHealthcare is arguably the sector where AI could make the lead to a more personalised healthcare based on patients’ data.'),\n", + " Document(id='e393ec31-5738-4454-aab0-bf1f33ec1d18', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 10, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='intermediate / professional users (i.e., healthcare professionals). the safety of employees. The key application of AI is certainly in\\nThis is a matter of privacy and personal data protection, of building predictive maintenance. Yet, the more radical transformation of'),\n", + " Document(id='693acf63-9fbf-4e71-9128-71b230dcd17f', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 15, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='Remote sible, as AI solutions can increasingly divert patients ning healthcare professionals, starting from the simple\\nhealthcare to appropriate solutions for their specific symptoms tasks and diagnostic appointments.\\nand underlying conditions.\\n16'),\n", + " Document(id='764ba481-f984-47e9-b86b-98250eda7ad1', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 14, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='same. The Covid-19 crisis has shown how strained our National\\nHealthcare Systems are, and AI solutions could help meet the cur- AI in the healthcare faces organisational and skill challenges. One'),\n", + " Document(id='c0f68d31-3ebf-45f7-bf6c-cef790cb6f92', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 3, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='advanced robots, autonomous cars, drones or Internet of Things place, a recent EIT Health Report envisages more in healthcare in\\napplications)”. Broad AI definitions cover several technologies, in- the near future, such as remote monitoring, AI-powered alerting'),\n", + " Document(id='8594b8a3-aef5-44ae-93aa-7f1d5afeaaa3', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 21, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='EIT Health and McKinsey & Company, (2020), Transforming healthcare with AI. Impact Scherer, M. (2016). Regulating Artificial Intelligence Systems: Risks, Challenges, Compe-'),\n", + " Document(id='98d019bc-1a7e-4273-8eac-eff09d7bf756', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 15, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='very sensitive. An extensive use to feed AI tools can the use of patient’s data in the hospitals that deploy\\nHealth data raise many concerns. Data ownership is also an issue AI-powered applications. The patients should be aware'),\n", + " Document(id='b63de5ec-3554-488f-a4c0-1975c0c9e39f', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 14, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='to extract information from clinical notes or predictive scheduling healthcare practitioners needs. In addition, at the regulatory le-\\nof the visits) and diagnostic (machine and deep learning applied to vel it is important that new AI regulation is harmonised with other'),\n", + " Document(id='7c4c1675-87ad-47ba-8df1-39e8036cf6c2', metadata={'source': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'file_path': 'data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf', 'page': 14, 'total_pages': 24, 'CreationDate': \"D:20200922223534+02'00'\", 'Creator': 'Adobe InDesign 15.1 (Macintosh)', 'ModDate': \"D:20200922223544+02'00'\", 'Producer': 'Adobe PDF Library 15.0', 'Trapped': 'False'}, page_content='greatest impact in addressing societal challenges. Given rising de- A second challenge is that of finding a common language and un-\\nmands and costs, AI could help doing more and better with the derstanding between data experts and healthcare professionals.')]" ] }, "execution_count": 5, @@ -226,10 +233,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "The application of AI in healthcare has so far been confined primarily to areas such as diagnostic assistance, patient management, and personalized treatment plans. Specific implementations include using AI for pattern recognition in medical imaging, predictive analytics for patient outcomes, and automating administrative tasks to improve efficiency.\n", + "The application of AI in healthcare has so far been confined primarily to administrative tasks, such as Natural Language Processing for extracting information from clinical notes and predictive scheduling. There is potential for more extensive use in research and development, but significant applications remain limited.\n", "\n", "**Source**\n", - "- data/Newwhitepaper_Agents2.pdf (page 4)\n" + "- data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf (page 14)\n" ] } ], @@ -442,63 +449,39 @@ "🔄 Node: \u001b[1;36mretrieve\u001b[0m 🔄\n", "- - - - - - - - - - - - - - - - - - - - - - - - - \n", "\u001b[1;32mcontext\u001b[0m:\n", - "Agents\n", - "This combination of reasoning,\n", - "logic, and access to external\n", - "information that are all connected\n", - "to a Generative AI model invokes\n", - "the concept of an agent.\n", - "Introduction\n", - "Humans are fantastic at messy pattern recognition tasks. However, they often rely on toolsdata/Newwhitepaper_Agents2.pdf4\n", - "frameworks, and continuous improvement mechanisms. Google’s Vertex AI platform\n", - "simplifies this process by offering a fully managed environment with all the fundamental\n", - "elements covered earlier. Using a natural language interface, developers can rapidlydata/Newwhitepaper_Agents2.pdf38\n", - "- like books, Google Search, or a calculator - to supplement their prior knowledge before\n", - "arriving at a conclusion. Just like humans, Generative AI models can be trained to use tools\n", - "to access real-time information or suggest a real-world action. For example, a model candata/Newwhitepaper_Agents2.pdf4\n", - "Agents\n", - "Production applications with Vertex\n", - "AI agents\n", - "While this whitepaper explored the core components of agents, building production-grade\n", - "applications requires integrating them with additional tools like user interfaces, evaluationdata/Newwhitepaper_Agents2.pdf38\n", - "achieve its ultimate goal. While the notion of agents in AI is quite general and powerful, this\n", - "whitepaper focuses on the specific types of agents that Generative AI models are capable of\n", - "building at the time of publication.data/Newwhitepaper_Agents2.pdf5\n", - "Implementation and application\n", - "In the context of Generative AI agents, Data Stores are typically implemented as a vector\n", - "database that the developer wants the agent to have access to at runtime. While we won’t\n", - "cover vector databases in depth here, the key point to understand is that they store datadata/Newwhitepaper_Agents2.pdf28\n", - "Agents\n", - "Summary\n", - "In this whitepaper we’ve discussed the foundational building blocks of Generative AI\n", - "agents, their compositions, and effective ways to implement them in the form of cognitive\n", - "architectures. Some key takeaways from this whitepaper include:data/Newwhitepaper_Agents2.pdf40\n", - "while others may contain chained logic, involve additional machine learning algorithms, or\n", - "implement other probabilistic reasoning techniques. We’ll discuss more about the detailed\n", - "implementation of the agent orchestration layers in the cognitive architecture section.\n", - "September 2024 7data/Newwhitepaper_Agents2.pdf7\n", - "Agents\n", - "What is an agent?\n", - "In its most fundamental form, a Generative AI agent can be defined as an application that\n", - "attempts to achieve a goal by observing the world and acting upon it using the tools that it\n", - "has at its disposal. Agents are autonomous and can act independently of human intervention,data/Newwhitepaper_Agents2.pdf5\n", - "Agents\n", - "Generation (RAG) based applications. These applications seek to extend the breadth and\n", - "depth of a model’s knowledge beyond the foundational training data by giving the model\n", - "access to data in various formats like:\n", - "• Website contentdata/Newwhitepaper_Agents2.pdf29\n", + "activities. So far, however, AI applications in healthcare have been potential. Specific healthcare training should be provided to data\n", + "confined to administrative tasks (i.e., Natural Language Processing scientists working in hospitals so that they can better understanddata/A European Approach to Artificial Intelligence - A Policy Perspective.pdf15\n", + "are great, as more use of AI in research and development could\n", + "Healthcare is arguably the sector where AI could make the lead to a more personalised healthcare based on patients’ data.data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf15\n", + "intermediate / professional users (i.e., healthcare professionals). the safety of employees. The key application of AI is certainly in\n", + "This is a matter of privacy and personal data protection, of building predictive maintenance. Yet, the more radical transformation ofdata/A European Approach to Artificial Intelligence - A Policy Perspective.pdf11\n", + "Remote sible, as AI solutions can increasingly divert patients ning healthcare professionals, starting from the simple\n", + "healthcare to appropriate solutions for their specific symptoms tasks and diagnostic appointments.\n", + "and underlying conditions.\n", + "16data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf16\n", + "same. The Covid-19 crisis has shown how strained our National\n", + "Healthcare Systems are, and AI solutions could help meet the cur- AI in the healthcare faces organisational and skill challenges. Onedata/A European Approach to Artificial Intelligence - A Policy Perspective.pdf15\n", + "advanced robots, autonomous cars, drones or Internet of Things place, a recent EIT Health Report envisages more in healthcare in\n", + "applications)”. Broad AI definitions cover several technologies, in- the near future, such as remote monitoring, AI-powered alertingdata/A European Approach to Artificial Intelligence - A Policy Perspective.pdf4\n", + "EIT Health and McKinsey & Company, (2020), Transforming healthcare with AI. Impact Scherer, M. (2016). Regulating Artificial Intelligence Systems: Risks, Challenges, Compe-data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf22\n", + "very sensitive. An extensive use to feed AI tools can the use of patient’s data in the hospitals that deploy\n", + "Health data raise many concerns. Data ownership is also an issue AI-powered applications. The patients should be awaredata/A European Approach to Artificial Intelligence - A Policy Perspective.pdf16\n", + "to extract information from clinical notes or predictive scheduling healthcare practitioners needs. In addition, at the regulatory le-\n", + "of the visits) and diagnostic (machine and deep learning applied to vel it is important that new AI regulation is harmonised with otherdata/A European Approach to Artificial Intelligence - A Policy Perspective.pdf15\n", + "greatest impact in addressing societal challenges. Given rising de- A second challenge is that of finding a common language and un-\n", + "mands and costs, AI could help doing more and better with the derstanding between data experts and healthcare professionals.data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf15\n", "==================================================\n", "\n", "==================================================\n", "🔄 Node: \u001b[1;36mllm_answer\u001b[0m 🔄\n", "- - - - - - - - - - - - - - - - - - - - - - - - - \n", "\u001b[1;32manswer\u001b[0m:\n", - "The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals. However, the context does not provide specific examples or limitations regarding the application of AI in healthcare.\n", + "The application of AI in healthcare has so far been confined primarily to administrative tasks, such as Natural Language Processing for extracting information from clinical notes and predictive scheduling. \n", "\n", "**Source**\n", - "- data/Newwhitepaper_Agents2.pdf (page 5)\n", + "- data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf (page 15)\n", "('user', 'Where has the application of AI in healthcare been confined to so far?')\n", - "('assistant', 'The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals. However, the context does not provide specific examples or limitations regarding the application of AI in healthcare.\\n\\n**Source**\\n- data/Newwhitepaper_Agents2.pdf (page 5)')\n", + "('assistant', 'The application of AI in healthcare has so far been confined primarily to administrative tasks, such as Natural Language Processing for extracting information from clinical notes and predictive scheduling. \\n\\n**Source**\\n- data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf (page 15)')\n", "==================================================\n" ] } @@ -533,10 +516,10 @@ "==================================================\n", "🔄 Node: \u001b[1;36mllm_answer\u001b[0m 🔄\n", "- - - - - - - - - - - - - - - - - - - - - - - - - \n", - "The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals.\n", + "The application of AI in healthcare has so far been confined primarily to administrative tasks, such as Natural Language Processing for extracting information from clinical notes and predictive scheduling.\n", "\n", "**Source**\n", - "- data/Newwhitepaper_Agents2.pdf (page 5)" + "- data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf (page 15)" ] } ], @@ -558,10 +541,10 @@ "Question: Where has the application of AI in healthcare been confined to so far?\n", "============================================================\n", "Answer:\n", - "The application of AI in healthcare has so far been confined to areas such as pattern recognition tasks, data analysis, and the development of autonomous agents that can act independently to achieve specific goals.\n", + "The application of AI in healthcare has so far been confined primarily to administrative tasks, such as Natural Language Processing for extracting information from clinical notes and predictive scheduling.\n", "\n", "**Source**\n", - "- data/Newwhitepaper_Agents2.pdf (page 5)\n" + "- data/A European Approach to Artificial Intelligence - A Policy Perspective.pdf (page 15)\n" ] } ], From feb82e39d79eaccdf3466af7efe0247015ab429d Mon Sep 17 00:00:00 2001 From: choincnp Date: Sat, 25 Jan 2025 02:25:29 +0900 Subject: [PATCH 3/3] add: linked designer --- 17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb b/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb index 38ae49dd0..16bc946ba 100644 --- a/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb +++ b/17-LangGraph/02-Structures/02-LangGraph-Naive-RAG.ipynb @@ -8,7 +8,7 @@ "# Naive RAG\n", "\n", "- Author: [Youngjun cho](https://github.com/choincnp)\n", - "- Design: \n", + "- Design: [LeeYuChul](https://github.com/LeeYuChul)\n", "- Peer Review: \n", "- This is a part of [LangChain Open Tutorial](https://github.com/LangChain-OpenTutorial/LangChain-OpenTutorial)\n", "\n",