What is LangChain

Notes on what LangChain is


Starting from scratch

What is it?

What if i want some LLM to answer to some queries and then another one for answering others? That's exactly what langchain does. It is an OS orchestration model for development of apps that use LLMs. Basically it is a generic interface for nearly any LLM.

Components

Langchain streams the development of LLM apps through what it calls "abstractions". These abstractions represent common steps and concepts necessary to work with LMs, being able to be chained together to create the apps.

  • LLM module: Nearly every LLM out there is supported. This LLM module is designed to provide with an standard interface for all models. It will take an string as input and return an string as output. Ex: GPT-4, Llama 3
  • Prompt Template Module: Formalizes the creation of prompts without the needto hardcode context and queries. Ex: Do not include technical terms in your answer or specify output format
  • Chains Module: Bind LLMs with other components, creating applications by executing a sequence of functions. Ex: Need to extract weather data to answer a user whether or not Madrid is a dry city, meaning the need for the LLM to access data outside of its training data.
  • Indexes Module(External data sources not included in the LLM training data):
    • Document Loader: Import from data sources
    • Vector Databases: Represent data points by converting them into vector embeddings which are numerical representations in the form of vectors with a fixed number of dimensions. Can store a lot of information with a very efficient means of retrieval.
    • Text splitters: Split text into small semantic meaningful chunks
  • Memory Module: Helps LLMs have context of prior conversations (from entire convo to summarization of those)
  • Agents: Can use a certain language module as a reasoning engine to determine which actions to take. When building a chain for an agent, it is important to include a list of available tools that it should use, user input or any other previously executed steps.
  • Tool/Function Calling: Allows a model to respond to a given prompt by generating output that matches a user-defined schema. These module just defined the argument object, structured, that should be used for calling the tool

Use cases

  • Chatbot
  • Summarization: Break down large documents
  • Question answering
  • Data augmentation: Generate synthetic data
  • Virtual agents: With the right workflows integrated with LLMs, these agents could then take action to complete the needed step. This is called RPA (Robotic Process Automation)

There also exists:

  • LangServe - Chains as REST APIs
  • LangSmith - Monitor, evaluate and debug apps

Hands on - Creating Agent

Links

IBM LanchChain Explanation LangChain JS Repo LangChain