DEV Community

Cover image for LangChain Components
Nitisha
Nitisha

Posted on

LangChain Components

What are LangChain Components?

LangChain Components are the individual building blocks provided by LangChain that work together to create AI-powered applications. Each component performs a specific task, such as generating responses, managing memory, retrieving information, using tools, or processing documents.

1.Models**:Core interfaces through which U interact with AI models.
This component standardizes the interface to communicate with different LLM's using their API's.

2.Prompts: Input provided to LLM are called prompts.
This component provides a way to manage and optimize the input given to LLMs to get the best possible output.

Types of Prompts

  1. Dynamic and Reusable: Templates that let you swap variables (like names or data) without rewriting the core instruction.
  2. Role-based : Assigning a specific persona to the AI (e.g., "You are an expert coder") to guide the style of its response. 3.** Few-Shot Prompting** : Providing a few examples of input and output to help the AI understand the pattern you want it to follow.

3.Chains:Used to build pipelines.

Parallel Chains: Run multiple models or processes at the same time to gather information, which is then combined into a single output.

Conditional Chains: Use logic to determine the next step in the process. For example, an AI agent can analyze feedback and decide between different paths (like sending a "Thank You" or an "Email" based on the result).

4.Indexes: Connect your application to external knowledge such as PDFs, websites, or databases.

  • Doc Loader: Imports your data from various sources.
  • Text Splitter: Breaks large documents into smaller, manageable pieces.
  • Vector Store: Saves those pieces in a way the AI can easily search.
  • Retrievers: The mechanism used to fetch the relevant data when a question is asked.

5.Memory: "LLM API calls are "stateless."
This means the model does not remember past conversations made via API.
With the LangChain Memory component, it can store conversations, allowing the AI to keep track of context over time.

6.Agents: Agents use LLMs to decide which actions to take and in what order.It is like chatbot with superpower.
Instead of just responding, an Agent acts as a controller that uses tools (like search engines or calculators) to complete a task.

Types of Agents

  • Action Agents: They execute a task, observe the result, and repeat until finished.
  • Plan-and-Execute Agents: They create a step-by-step plan for complex problems before performing each action.
  • ReAct Agents: They use a loop of "Reasoning" and "Acting" to think through a task, pick a tool, and adjust based on observations.

Check the previous blog on LangChain Introduction.

Top comments (0)