LangChain.dart

repository·main·Indexed 20 days ago

https://github.com/davidmigloz/langchain_dart

A Dart implementation of the LangChain framework for building context-aware and reasoning-capable applications. It provides a modular system of components and off-the-shelf chains to connect language models to prompt instructions, few-shot examples, and grounding content. The ecosystem includes integrations for providers such as OpenAI, Anthropic, Cohere, Amazon, and vector stores like Chroma, ObjectBox, and Vertex AI Matching Engine.

Tokens
110.4K
Snippets
309
Records
411
Agent score
71%

What's inside LangChain.dart

  1. What is LangChain.dart Core?

    main

    LangChain.dart Core is the foundational package of the LangChain.dart ecosystem. It provides the core abstractions used by all other LangChain.dart packages and includes the LangChain Expression Language (LCEL) for composing components.

    Key features include:

    • Modular Abstractions: Standardized interfaces for language models, document loaders, embedding models, vector stores, retrievers, and more.
    • LangChain Expression Language (LCEL): A declarative language used to compose components (known as Runnables) into sequences or Directed Acyclic Graphs (DAGs), facilitating common LLM application patterns.

    Developers should depend on this package if they intend to build new frameworks on top of LangChain.dart or need to ensure interoperability with the existing ecosystem.

  2. Overview of LangChain.dart Modules

    main

    LangChain.dart is organized into several core modules that provide standard, extendable interfaces for building LLM applications. The modules are categorized by their complexity and function:

    • Model I/O: The foundation for interfacing with various language models.
    • Retrieval: Tools to interface with and fetch application-specific data.
    • Chains: Mechanisms to construct sequences of calls (often using LCEL).
    • Agents: Advanced logic that allows chains to decide which tools to use based on high-level directives.
    • Memory: Systems to persist application state and conversation history between different runs of a chain.
    • Callbacks: Utilities to log and stream intermediate steps of any chain execution.
  3. What is LangChain.dart

    main

    LangChain.dart is a Dart port of the Python LangChain framework. It is a framework designed for developing applications powered by language models, focusing on two core capabilities:

    1. Context-awareness: Connecting language models to sources of context such as prompt instructions, few-shot examples, or grounding content.
    2. Reasoning: Enabling models to reason about how to answer questions or what actions to take based on provided context.

    The framework is built on two main pillars:

    • Components: Modular, composable tools and integrations for working with language models.
    • Off-the-shelf chains: Pre-built assemblages of components for high-level tasks.

    LangChain.dart uses a modular design where the core langchain package provides the primary API, and specific integrations (model providers, databases, etc.) are provided via separate packages.

  4. Available integrations in LangChain.dart Community

    main

    The community package includes several categories of components. Note that many popular third-party integrations (like OpenAI or Google) have their own dedicated packages (e.g., langchain_openai, langchain_google).

    Document Loaders

    • TextLoader: For plain text files.
    • CsvLoader: For CSV or TSV files.
    • JsonLoader: For JSON files.
    • WebBaseLoader: For web pages.
    • DirectoryLoader: For directories of files.

    Tools

    • CalculatorTool: To calculate math expressions.
    • TavilySearchResultsTool: Returns a list of results for a query using the Tavily search engine.
    • TavilyAnswerTool: Returns an answer for a query using the Tavily search engine.

    Vector Stores

    • ObjectBoxVectorStore: An on-device vector database using ObjectBox.
  5. Use Google LLMs, Chat Models, and Embeddings with LangChain.dart

    main

    The langchain_google package provides integrations for Google's AI services within the LangChain.dart ecosystem. It supports two primary service providers:

    1. Google AI for Developers (Gemini)

    Use these classes for interacting with the Gemini API via Google AI for Developers:

    • ChatGoogleGenerativeAI: For chat-based interactions.
    • GoogleGenerativeAIEmbeddings: For generating text embeddings.

    2. Google Cloud Platform (Vertex AI)

    Use these classes for enterprise-grade integration with GCP Vertex AI:

    • VertexAI: Wrapper for Vertex AI text models (PaLM API).
    • ChatVertexAI: Wrapper for Vertex AI text chat models.
    • VertexAIEmbeddings: Wrapper for Vertex AI text embedding models.
    • VertexAIMatchingEngine: A vector store implementation using GCP Vertex AI Matching Engine and Cloud Storage.

    Note: If you are looking for Vertex AI for Firebase support, use the langchain_firebase package instead.

  6. Construct prompts for language models

    main

    In LangChain.dart, prompts are used to guide language model responses by providing context and instructions. You can manage prompts using two primary mechanisms:

    1. Prompt Templates: Used to parameterize model inputs, allowing you to create reusable prompt structures with placeholders that are filled at runtime.
    2. Example Selectors: Used to dynamically select and include relevant examples (few-shot examples) in your prompts to improve model performance based on the input.