From b5d8434a5095c3a80e10a708d327b1c23a878956 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Sat, 3 Dec 2022 13:28:50 -0800 Subject: [PATCH] Harrison/improve chain docs (#251) --- docs/examples/agents.rst | 38 +++++++++++- docs/examples/chains.rst | 60 +++++++++++++++++++ ...ocuments.ipynb => combine_documents.ipynb} | 0 docs/index.rst | 3 + docs/modules/docstore.rst | 6 ++ docs/modules/python.rst | 6 ++ docs/modules/serpapi.rst | 6 ++ 7 files changed, 118 insertions(+), 1 deletion(-) rename docs/examples/chains/{combine documents.ipynb => combine_documents.ipynb} (100%) create mode 100644 docs/modules/docstore.rst create mode 100644 docs/modules/python.rst create mode 100644 docs/modules/serpapi.rst diff --git a/docs/examples/agents.rst b/docs/examples/agents.rst index bf279a49c8..7a6df17c90 100644 --- a/docs/examples/agents.rst +++ b/docs/examples/agents.rst @@ -2,10 +2,46 @@ Agents ====== The examples here are all end-to-end agents for specific applications. +In all examples there is an Agent with a particular set of tools. + +- Tools: A tool can be anything that takes in a string and returns a string. This means that you can use both the primitives AND the chains found in `this `_ documentation. +- Agents: An agent uses an LLMChain to determine which tools to use. For a list of all available agent types, see `here <../explanation/agents.md>`_. + +**MRKL** + +- **Tools used**: Search, SQLDatabaseChain, LLMMathChain +- **Agent used**: `zero-shot-react-description` +- `Paper `_ +- **Note**: This is the most general purpose example, so if you are looking to use an agent with arbitrary tools, please start here. +- `Example Notebook `_ + +**Self-Ask-With-Search** + +- **Tools used**: Search +- **Agent used**: `self-ask-with-search` +- `Paper `_ +- `Example Notebook `_ + +**ReAct** + +- **Tools used**: Wikipedia Docstore +- **Agent used**: `react-docstore` +- `Paper `_ +- `Example Notebook `_ + + + +Additionally, we also provide examples for how to do more customizability: + +**Custom Agent** + +- Purpose: How to create custom agents. +- `Example Notebook `_ + .. toctree:: :maxdepth: 1 :glob: - :caption: Agents + :hidden: agents/* \ No newline at end of file diff --git a/docs/examples/chains.rst b/docs/examples/chains.rst index 905c9911e2..0ab93cb56f 100644 --- a/docs/examples/chains.rst +++ b/docs/examples/chains.rst @@ -2,10 +2,70 @@ Chains ====== The examples here are all end-to-end chains for specific applications. +A chain is made up of links, which can be either primitives or other chains. + +The following primitives exist as options to use for links: + +#. `LLM: <../modules/llms.rst>`_ A language model takes text as input and outputs text. +#. `PromptTemplate: <../modules/prompt.rst>`_ A prompt template takes arbitrary string inputs and returns a final formatted string. +#. `TextSplitter: <../modules/text_splitter.rst>`_ A text splitter takes a longer document and splits it into smaller chunks. +#. `Python REPL: <../modules/python.rst>`_ A Python REPL takes a string representing a Python command to run, runs that command, and then returns anything that was printed during that run. +#. `SQL Database: <../modules/sql_database.rst>`_ A SQL database takes a string representing a SQL command as input and executes that command against the database. If any rows are returned, then those are cast to a string and returned. +#. `Search: <../modules/serpapi.rst>`_ A search object takes a string as input and executes that against a search object, returning any results. +#. `Docstore: <../modules/docstore.rst>`_ A docstore object can be used to lookup a document in a database by exact match. +#. `Vectorstore: <../modules/vectorstore.rst>`_ A vectorstore object uses embeddings stored in a vector database to take in an input string and return documents similar to that string. + +With these primitives in mind, the following chains exist: + +**LLMChain** + +- **Links Used**: PromptTemplate, LLM +- **Notes**: This chain is the simplest chain, and is widely used by almost every other chain. This chain takes arbitrary user input, creates a prompt with it from the PromptTemplate, passes that to the LLM, and then returns the output of the LLM as the final output. +- `Example Notebook `_ + +**LLMMath** + +- **Links Used**: Python REPL, LLMChain +- **Notes**: This chain takes user input (a math question), uses an LLMChain to convert it to python code snippet to run in the Python REPL, and then returns that as the result. +- `Example Notebook `_ + +**PAL** + +- **Links Used**: Python REPL, LLMChain +- **Notes**: This chain takes user input (a reasoning question), uses an LLMChain to convert it to python code snippet to run in the Python REPL, and then returns that as the result. +- `Paper `_ +- `Example Notebook `_ + +**Recursive Summarization** + +- **Links Used**: TextSplitter, LLMChain +- **Notes**: This chain splits a document into chunks, runs a first LLMChain over each chunk to summarize it, and then runs a second LLMChain over those results to get a summary of the summaries. +- `Example Notebook `_ + +**SQLDatabase Chain** + +- **Links Used**: SQLDatabase, LLMChain +- **Notes**: This chain takes user input (a question), uses a first LLM chain to construct a SQL query to run against the SQL database, and then uses another LLMChain to take the results of that query and use it to answer the original question. +- `Example Notebook `_ + + +**Vector Database Question-Answering** + +- **Links Used**: Vectorstore, LLMChain +- **Notes**: This chain takes user input (a question), uses the Vectorstore and semantic search to find relevant documents, and then passes the documents plus to the original question to another LLM to generate a final answer. +- `Example Notebook `_ + +**Question-Answering With Sources** + +- **Links Used**: LLMChain +- **Notes**: This chain takes a question and multiple documents as input. It then runs a first LLMChain over all documents attempting to answer the provided question. It then runs a second LLMChain over the results of the first pass, combining the answers from documents into a single response that is returned. +- `Example Notebook `_ + .. toctree:: :maxdepth: 1 :glob: :caption: Chains + :hidden: chains/* diff --git a/docs/examples/chains/combine documents.ipynb b/docs/examples/chains/combine_documents.ipynb similarity index 100% rename from docs/examples/chains/combine documents.ipynb rename to docs/examples/chains/combine_documents.ipynb diff --git a/docs/index.rst b/docs/index.rst index a2e3ca6eb2..7b2f8ba1c2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -141,6 +141,9 @@ common tasks or cool demos. modules/llms modules/embeddings modules/text_splitter + modules/python.rst + modules/serpapi.rst + modules/docstore.rst modules/vectorstore modules/chains modules/agents diff --git a/docs/modules/docstore.rst b/docs/modules/docstore.rst new file mode 100644 index 0000000000..d34095befc --- /dev/null +++ b/docs/modules/docstore.rst @@ -0,0 +1,6 @@ +:mod:`langchain.docstore` +============================= + +.. automodule:: langchain.docstore + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/modules/python.rst b/docs/modules/python.rst new file mode 100644 index 0000000000..d5b7a17ac6 --- /dev/null +++ b/docs/modules/python.rst @@ -0,0 +1,6 @@ +:mod:`langchain.python` +============================= + +.. automodule:: langchain.python + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/modules/serpapi.rst b/docs/modules/serpapi.rst new file mode 100644 index 0000000000..94580174b6 --- /dev/null +++ b/docs/modules/serpapi.rst @@ -0,0 +1,6 @@ +:mod:`langchain.serpapi` +============================= + +.. automodule:: langchain.serpapi + :members: + :undoc-members: \ No newline at end of file