From addc79d29d36008d2de5ee37c31d5275712289a1 Mon Sep 17 00:00:00 2001 From: Lance Martin Date: Wed, 7 Feb 2024 16:07:33 -0800 Subject: [PATCH] Clean up docstrings --- examples/rag/langgraph_crag.ipynb | 54 +++++++++++------------ examples/rag/langgraph_crag_mistral.ipynb | 41 ++++++++--------- examples/rag/langgraph_self_rag.ipynb | 39 ++++++++-------- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/examples/rag/langgraph_crag.ipynb b/examples/rag/langgraph_crag.ipynb index 8dc7750c9..f8a6e2d0e 100644 --- a/examples/rag/langgraph_crag.ipynb +++ b/examples/rag/langgraph_crag.ipynb @@ -132,12 +132,10 @@ "\n", "class GraphState(TypedDict):\n", " \"\"\"\n", - " Represents the state of an agent in the conversation.\n", + " Represents the state of our graph.\n", "\n", " Attributes:\n", - " keys: A dictionary where each key is a string and the value is expected to be a list or another structure\n", - " that supports addition with `operator.add`. This could be used, for instance, to accumulate messages\n", - " or other pieces of data throughout the graph.\n", + " keys: A dictionary where each key is a string.\n", " \"\"\"\n", "\n", " keys: Dict[str, any]" @@ -198,10 +196,10 @@ " Retrieve documents\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, documents, that contains documents.\n", + " state (dict): New key added to state, documents, that contains retrieved documents\n", " \"\"\"\n", " print(\"---RETRIEVE---\")\n", " state_dict = state[\"keys\"]\n", @@ -215,10 +213,10 @@ " Generate answer\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, generation, that contains generation.\n", + " state (dict): New key added to state, generation, that contains LLM generation\n", " \"\"\"\n", " print(\"---GENERATE---\")\n", " state_dict = state[\"keys\"]\n", @@ -250,10 +248,10 @@ " Determines whether the retrieved documents are relevant to the question.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, filtered_documents, that contains relevant documents.\n", + " state (dict): Updates documents key with relevant documents\n", " \"\"\"\n", "\n", " print(\"---CHECK RELEVANCE---\")\n", @@ -323,10 +321,10 @@ " Transform the query to produce a better question.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New value saved to question.\n", + " state (dict): Updates question key with a re-phrased question\n", " \"\"\"\n", "\n", " print(\"---TRANSFORM QUERY---\")\n", @@ -358,13 +356,13 @@ "\n", "def web_search(state):\n", " \"\"\"\n", - " Web search using Tavily.\n", + " Web search based on the re-phrased question using Tavily API.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " state (dict): Web results appended to documents.\n", + " state (dict): Updates documents key with appended web results\n", " \"\"\"\n", "\n", " print(\"---WEB SEARCH---\")\n", @@ -386,13 +384,13 @@ "\n", "def decide_to_generate(state):\n", " \"\"\"\n", - " Determines whether to generate an answer, or re-generate a question.\n", + " Determines whether to generate an answer or re-generate a question for web search.\n", "\n", " Args:\n", " state (dict): The current state of the agent, including all keys.\n", "\n", " Returns:\n", - " dict: New key added to state, filtered_documents, that contains relevant documents.\n", + " str: Next node to call\n", " \"\"\"\n", "\n", " print(\"---DECIDE TO GENERATE---\")\n", @@ -412,6 +410,14 @@ " return \"generate\"" ] }, + { + "cell_type": "markdown", + "id": "fa076e90-7132-4fcf-8507-db5990314c4f", + "metadata": {}, + "source": [ + "## Build Graph" + ] + }, { "cell_type": "code", "execution_count": null, @@ -490,18 +496,12 @@ "id": "a7e44593-1959-4abf-8405-5e23aa9398f5", "metadata": {}, "source": [ - "Traces -\n", + "LangSmith Traces - \n", " \n", - "[Trace](https://smith.langchain.com/public/7e0b9569-abfe-4337-b34b-842b1f93df63/r) and [Trace](https://smith.langchain.com/public/b40c5813-7caf-4cc8-b279-ee66060b2040/r)" + "* https://smith.langchain.com/public/7e0b9569-abfe-4337-b34b-842b1f93df63/r\n", + "\n", + "* https://smith.langchain.com/public/b40c5813-7caf-4cc8-b279-ee66060b2040/r" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "69eddb3e-57f4-4eea-8e40-4822fc50c729", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/examples/rag/langgraph_crag_mistral.ipynb b/examples/rag/langgraph_crag_mistral.ipynb index ecb821596..c3464a19a 100644 --- a/examples/rag/langgraph_crag_mistral.ipynb +++ b/examples/rag/langgraph_crag_mistral.ipynb @@ -37,7 +37,7 @@ "\n", "Here we show how to implement self-reflective RAG using `Mistral` and `LangGraph`.\n", "\n", - "In particular, we'll focus on the approach from one paper Corrective RAG (CRAG) [here](https://arxiv.org/pdf/2401.15884.pdf).\n", + "In particular, we'll focus on the approach from one paper focused on Corrective RAG (CRAG) [here](https://arxiv.org/pdf/2401.15884.pdf).\n", "\n", "![Screenshot 2024-02-07 at 1.21.51 PM.png](attachment:9db7f9db-55aa-48cb-95d5-bcde3f937589.png)\n", "\n", @@ -127,9 +127,10 @@ "\n", "Let's implement self-reflective RAG with some ideas from the CRAG (Corrective RAG) [paper](https://arxiv.org/pdf/2401.15884.pdf):\n", "\n", - "* Grade documents for relevance relative to the question\n", - "* If any are irrelevant, then we will supplement the context with web search\n", - "* For web search, we will re-phrase the question and use Tavily\n", + "* Grade documents for relevance relative to the question.\n", + "* If any are irrelevant, then we will supplement the context used for generation with web search.\n", + "* For web search, we will re-phrase the question and use Tavily API.\n", + "* We will then pass retrieved documents and web results to an LLM for final answer generation.\n", "\n", "Here is a schematic of our graph in more detail:\n", "\n", @@ -144,7 +145,7 @@ "\n", "### State\n", "\n", - "Every node in our graph will modify `state`, which is dict that contains values (question, documents, etc) relevant to RAG." + "Every node in our graph will modify `state`, which is dict that contains values (`question`, `documents`, etc) relevant to RAG." ] }, { @@ -215,10 +216,10 @@ " Retrieve documents\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, documents, that contains documents.\n", + " state (dict): New key added to state, documents, that contains retrieved documents\n", " \"\"\"\n", " print(\"---RETRIEVE---\")\n", " state_dict = state[\"keys\"]\n", @@ -233,10 +234,10 @@ " Generate answer\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, generation, that contains generation.\n", + " state (dict): New key added to state, generation, that contains generation\n", " \"\"\"\n", " print(\"---GENERATE---\")\n", " state_dict = state[\"keys\"]\n", @@ -274,10 +275,10 @@ " Determines whether the retrieved documents are relevant to the question.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, filtered_documents, that contains relevant documents.\n", + " state (dict): Updates documents key with relevant documents\n", " \"\"\"\n", "\n", " print(\"---CHECK RELEVANCE---\")\n", @@ -356,10 +357,10 @@ " Transform the query to produce a better question.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New value saved to question.\n", + " state (dict): Updates question key with a re-phrased question\n", " \"\"\"\n", "\n", " print(\"---TRANSFORM QUERY---\")\n", @@ -400,10 +401,10 @@ "\n", "def web_search(state):\n", " \"\"\"\n", - " Web search using Tavily.\n", + " Web search based on the re-phrased question using Tavily API.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", " state (dict): Web results appended to documents.\n", @@ -429,13 +430,13 @@ "\n", "def decide_to_generate(state):\n", " \"\"\"\n", - " Determines whether to generate an answer, or re-generate a question.\n", + " Determines whether to generate an answer or re-generate a question for web search.\n", "\n", " Args:\n", " state (dict): The current state of the agent, including all keys.\n", "\n", " Returns:\n", - " dict: New key added to state, filtered_documents, that contains relevant documents.\n", + " str: Next node to call\n", " \"\"\"\n", "\n", " print(\"---DECIDE TO GENERATE---\")\n", @@ -460,7 +461,7 @@ "id": "6096626d-dfa5-48e0-8a24-3747b298bc67", "metadata": {}, "source": [ - "## Lay out our graph" + "## Build Graph" ] }, { @@ -507,7 +508,7 @@ "id": "ac0a868a-f0f9-4aa9-b955-a78da2359af8", "metadata": {}, "source": [ - "## Run it\n", + "## Run\n", "\n", "`Mistral API -` " ] @@ -571,7 +572,7 @@ "id": "0931b76a-3ea8-4f2f-9d27-242d48ec3fe3", "metadata": {}, "source": [ - "## Trace\n", + "## LangSmith Traces\n", "\n", "`Mistral API -` \n", "\n", diff --git a/examples/rag/langgraph_self_rag.ipynb b/examples/rag/langgraph_self_rag.ipynb index 50f7dbef1..bb9f3ac70 100644 --- a/examples/rag/langgraph_self_rag.ipynb +++ b/examples/rag/langgraph_self_rag.ipynb @@ -141,12 +141,10 @@ "\n", "class GraphState(TypedDict):\n", " \"\"\"\n", - " Represents the state of an agent in the conversation.\n", + " Represents the state of our graph.\n", "\n", " Attributes:\n", - " keys: A dictionary where each key is a string and the value is expected to be a list or another structure\n", - " that supports addition with `operator.add`. This could be used, for instance, to accumulate messages\n", - " or other pieces of data throughout the graph.\n", + " keys: A dictionary where each key is a string.\n", " \"\"\"\n", "\n", " keys: Dict[str, any]" @@ -205,10 +203,10 @@ " Retrieve documents\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, documents, that contains documents.\n", + " state (dict): New key added to state, documents, that contains retrieved documents\n", " \"\"\"\n", " print(\"---RETRIEVE---\")\n", " state_dict = state[\"keys\"]\n", @@ -222,10 +220,10 @@ " Generate answer\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, generation, that contains generation.\n", + " state (dict): New key added to state, generation, that contains LLM generation\n", " \"\"\"\n", " print(\"---GENERATE---\")\n", " state_dict = state[\"keys\"]\n", @@ -257,10 +255,10 @@ " Determines whether the retrieved documents are relevant to the question.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New key added to state, filtered_documents, that contains relevant documents.\n", + " state (dict): Updates documents key with relevant documents\n", " \"\"\"\n", "\n", " print(\"---CHECK RELEVANCE---\")\n", @@ -322,10 +320,10 @@ " Transform the query to produce a better question.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " dict: New value saved to question.\n", + " state (dict): Updates question key with a re-phrased question\n", " \"\"\"\n", "\n", " print(\"---TRANSFORM QUERY---\")\n", @@ -357,13 +355,13 @@ "\n", "def prepare_for_final_grade(state):\n", " \"\"\"\n", - " Stage for final grade, passthrough state.\n", + " Passthrough state for final grade.\n", "\n", " Args:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", "\n", " Returns:\n", - " state (dict): The current state of the agent, including all keys.\n", + " state (dict): The current graph state\n", " \"\"\"\n", "\n", " print(\"---FINAL GRADE---\")\n", @@ -388,7 +386,7 @@ " state (dict): The current state of the agent, including all keys.\n", "\n", " Returns:\n", - " dict: New key added to state, filtered_documents, that contains relevant documents.\n", + " str: Next node to call\n", " \"\"\"\n", "\n", " print(\"---DECIDE TO GENERATE---\")\n", @@ -415,7 +413,7 @@ " state (dict): The current state of the agent, including all keys.\n", "\n", " Returns:\n", - " str: Binary decision score.\n", + " str: Binary decision\n", " \"\"\"\n", "\n", " print(\"---GRADE GENERATION vs DOCUMENTS---\")\n", @@ -479,7 +477,7 @@ " state (dict): The current state of the agent, including all keys.\n", "\n", " Returns:\n", - " str: Binary decision score.\n", + " str: Binary decision\n", " \"\"\"\n", "\n", " print(\"---GRADE GENERATION vs QUESTION---\")\n", @@ -540,7 +538,7 @@ "id": "61cd5797-1782-4d78-a277-8196d13f3e1b", "metadata": {}, "source": [ - "## Graph" + "## Build Graph" ] }, { @@ -634,9 +632,10 @@ "id": "548f1c5b-4108-4aae-8abb-ec171b511b92", "metadata": {}, "source": [ - "Trace - \n", + "LangSmith Traces - \n", " \n", "* https://smith.langchain.com/public/55d6180f-aab8-42bc-8799-dadce6247d9b/r\n", + "\n", "* https://smith.langchain.com/public/f85ebc95-81d9-47fc-91c6-b54e5b78f359/r" ] }