Langchain
Table of Contents
1. Key Concepts & Components
1.1. Prompts
LangChain provides tooling to create and work with prompt templates. Prompt templates are predefined recipes for generating prompts for language models.
1.2. Output Parsers
Output parsers are classes that help structure language model responses. They are responsible for taking the output of an LLM and transforming it into a more suitable format.
1.3. Retrievers
Retrievers accept a string query as input and return a list of Documents as output. LangChain provides several advanced retrieval types and also integrates with many third-party retrieval services.
1.4. Document Loaders
A Document is a piece of text and associated metadata. Document loaders provide a “load” method for loading data as documents from a configured source.
1.5. Text Splitters
Text splitters divide a document or text into smaller chunks or segments. LangChain has a number of built-in document transformers that can split, combine, and filter documents.
1.6. Indexes
An index in LangChain is a data structure that organizes and stores data to facilitate quick and efficient searches.
1.7. Embeddings models
The Embeddings class is designed to interface with text embedding models. It provides a standard interface for different embedding model providers, such as OpenAI, Cohere, Hugging Face, etc.
1.8. Vector Stores
A vector store stores embedded data and performs vector search. Embedding and storing embedding vectors is one of the most common ways to store and search over unstructured data.
1.9. Agents
Agents are the decision-making components that decide the plan of action or process.
1.10. Chains
They are sequences of calls, whether to an LLM, a tool, or a data preprocessing step. They integrate various components into a user-friendly interface, including the model, prompt, memory, output parsing, and debugging capabilities.
1.11. Tool
A tool is a specific function that helps the language model gather the necessary information for task completion. Tools can range from Google Searches and database queries to Python REPL and other chains.
1.12. Memory
This feature records past interactions with a language model, providing context for future interactions.
1.13. Callbacks
LangChain provides a callbacks system that allows you to hook into the various stages of your LLM application. This is useful for logging, monitoring, and streaming.
2. LangChain Agents & Tools Overview
2.1. What?
- complete tasks using chains, prompts, memory, and tools
- can perform diverse tasks, including executing steps in a predetermined sequence, interfacing with external systems and more
2.2. Types
2.2.1. Zero-shot ReAct
- uses the ReAct framework to decide tool usage based on the descriptions.
- termed “zero-shot” because it relies only on the tool descriptions without the need for specific usage examples.
2.2.2. Structured Input ReAct
- manages tools that necessitate multiple inputs.
2.2.3. OpenAI Functions Agent
- specifically developed for function calls for fine-tuned models
2.2.4. Self-Ask with Search Agent
- sources factual responses to questions, specializing in the “Intermediate Answer” tool.
- similar to the methodology in the original self-ask with search research.
2.2.5. ReAct Document Store Agent
- combines the “Search” and “Lookup” tools to provide a continuous thought process.
2.2.6. Plan-and-Execute Agents
- formulates a plan consisting of multiple actions, which are then carried out sequentially
- particularly effective for complex or long-running tasks, maintaining a steady focus on long-term goals
- However, one trade-off is the potential for increased latency.