Skip to main content

概念指南

¥Conceptual guide

本指南更广泛地讲解了 LangChain 框架和 AI 应用背后的关键概念。

¥This guide provides explanations of the key concepts behind the LangChain framework and AI applications more broadly.

我们建议你在深入概念指南之前至少了解一下 教程 中的一个。这将提供实际的背景信息,使你更容易理解此处讨论的概念。

¥We recommend that you go through at least one of the Tutorials before diving into the conceptual guide. This will provide practical context that will make it easier to understand the concepts discussed here.

本概念指南不包含分步说明或具体实现示例 - 这些可在 操作指南教程 中找到。有关详细的参考资料,请参阅 API 参考

¥The conceptual guide does not cover step-by-step instructions or specific implementation examples — those are found in the How-to guides and Tutorials. For detailed reference material, please see the API reference.

高级

¥High level

概念

¥Concepts

  • 聊天模型:LLM 通过聊天 API 公开,该 API 处理消息序列作为输入并输出一条消息。

    ¥Chat models: LLMs exposed via a chat API that process sequences of messages as input and output a message.

  • 消息:聊天模型中的通信单元,用于表示模型的输入和输出。

    ¥Messages: The unit of communication in chat models, used to represent model input and output.

  • 聊天历史记录:以消息序列表示的对话,在用户消息和模型响应之间交替。

    ¥Chat history: A conversation represented as a sequence of messages, alternating between user messages and model responses.

  • 工具:一个函数,其关联的模式定义了函数的名称、描述及其接受的参数。

    ¥Tools: A function with an associated schema defining the function's name, description, and the arguments it accepts.

  • 工具调用:一种聊天模型 API,它接受工具模式以及消息作为输入,并将这些工具的调用作为输出消息的一部分返回。

    ¥Tool calling: A type of chat model API that accepts tool schemas, along with messages, as input and returns invocations of those tools as part of the output message.

  • 结构化输出:一种使聊天模型以结构化格式(例如与给定模式匹配的 JSON)进行响应的技术。

    ¥Structured output: A technique to make a chat model respond in a structured format, such as JSON that matches a given schema.

  • 内存:关于对话的信息会被持久化,以便在未来的对话中使用。

    ¥Memory: Information about a conversation that is persisted so that it can be used in future conversations.

  • 多模态:处理不同形式的数据的能力,例如文本、音频、图片和视频。

    ¥Multimodality: The ability to work with data that comes in different forms, such as text, audio, images, and video.

  • Runnable 接口:许多 LangChain 组件和 LangChain 表达式语言都基于此基础抽象。

    ¥Runnable interface: The base abstraction that many LangChain components and the LangChain Expression Language are built on.

  • 流式传输:LangChain 流式 API 用于在结果生成时显示结果。

    ¥Streaming: LangChain streaming APIs for surfacing results as they are generated.

  • LangChain 表达式语言 (LCEL):用于编排 LangChain 组件的语法。最适合简单的应用。

    ¥LangChain Expression Language (LCEL): A syntax for orchestrating LangChain components. Most useful for simpler applications.

  • 文档加载器:将源加载为文档列表。

    ¥Document loaders: Load a source as a list of documents.

  • 检索:信息检索系统可以根据查询从数据源检索结构化或非结构化数据。

    ¥Retrieval: Information retrieval systems can retrieve structured or unstructured data from a datasource in response to a query.

  • 文本分割器:将长文本拆分成可单独索引的较小块,以实现细粒度检索。

    ¥Text splitters: Split long text into smaller chunks that can be individually indexed to enable granular retrieval.

  • 嵌入模型:在向量空间中表示文本或图片等数据的模型。

    ¥Embedding models: Models that represent data such as text or images in a vector space.

  • 向量存储:向量及相关元数据的存储和高效搜索。

    ¥Vector stores: Storage of and efficient search over vectors and associated metadata.

  • 检索器:一个组件,用于响应查询,从知识库返回相关文档。

    ¥Retriever: A component that returns relevant documents from a knowledge base in response to a query.

  • 检索增强生成 (RAG):一种通过将语言模型与外部知识库相结合来增强语言模型的技术。

    ¥Retrieval Augmented Generation (RAG): A technique that enhances language models by combining them with external knowledge bases.

  • 代理:使用 语言模型 选择要执行的操作序列。代理可以通过 tool 与外部资源交互。

    ¥Agents: Use a language model to choose a sequence of actions to take. Agents can interact with external resources via tool.

  • 提示模板:用于分解模型 "prompt" 静态部分(通常是一系列消息)的组件。用于序列化、版本控制和重用这些静态部分。

    ¥Prompt templates: Component for factoring out the static parts of a model "prompt" (usually a sequence of messages). Useful for serializing, versioning, and reusing these static parts.

  • 输出解析器:负责获取模型的输出并将其转换为更适合下游任务的格式。输出解析器主要用于 工具调用结构化输出 正式发布之前。

    ¥Output parsers: Responsible for taking the output of a model and transforming it into a more suitable format for downstream tasks. Output parsers were primarily useful prior to the general availability of tool calling and structured outputs.

  • 快照提示:一种通过在提示中提供一些要执行的任务示例来提高模型性能的技术。

    ¥Few-shot prompting: A technique for improving model performance by providing a few examples of the task to perform in the prompt.

  • 选择器示例:用于根据给定输入从数据集中选择最相关的示例。示例选择器用于在小样本提示中为提示选择示例。

    ¥Example selectors: Used to select the most relevant examples from a dataset based on a given input. Example selectors are used in few-shot prompting to select examples for a prompt.

  • 回调:回调支持在内置组件中执行自定义辅助代码。回调用于从 LangChain 中的 LLM 流式传输输出、跟踪应用的中间步骤等等。

    ¥Callbacks: Callbacks enable the execution of custom auxiliary code in built-in components. Callbacks are used to stream outputs from LLMs in LangChain, trace the intermediate steps of an application, and more.

  • 追踪:记录应用从输入到输出所采取步骤的过程。跟踪对于调试和诊断复杂应用中的问题至关重要。

    ¥Tracing: The process of recording the steps that an application takes to go from input to output. Tracing is essential for debugging and diagnosing issues in complex applications.

  • 评估:评估 AI 应用性能和有效性的过程。这涉及根据一组预定义的标准或基准测试模型的响应,以确保其符合所需的质量标准并实现预期目的。此过程对于构建可靠的应用至关重要。

    ¥Evaluation: The process of assessing the performance and effectiveness of AI applications. This involves testing the model's responses against a set of predefined criteria or benchmarks to ensure it meets the desired quality standards and fulfills the intended purpose. This process is vital for building reliable applications.

词汇表

¥Glossary

  • AIMessageChunk:AI 消息的部分响应。用于流式传输聊天模型的响应。

    ¥AIMessageChunk: A partial response from an AI message. Used when streaming responses from a chat model.

  • AIMessage:表示来自 AI 模型的完整响应。

    ¥AIMessage: Represents a complete response from an AI model.

  • StructuredTool:LangChain 中所有工具的基类。

    ¥StructuredTool: The base class for all tools in LangChain.

  • batch:用于执行一个可运行对象,并将批量输入到可运行对象中。

    ¥batch: Use to execute a runnable with batch inputs a Runnable.

  • bindTools:允许模型与工具交互。

    ¥bindTools: Allows models to interact with tools.

  • 缓存:存储结果以避免重复调用聊天模型。

    ¥Caching: Storing results to avoid redundant calls to a chat model.

  • 上下文窗口:聊天模型可以处理的最大输入大小。

    ¥Context window: The maximum size of input a chat model can process.

  • 对话模式:聊天互动中的常见模式。

    ¥Conversation patterns: Common patterns in chat interactions.

  • 文档:LangChain 的文档表示形式。

    ¥Document: LangChain's representation of a document.

  • 嵌入模型:为各种数据类型生成向量嵌入的模型。

    ¥Embedding models: Models that generate vector embeddings for various data types.

  • HumanMessage:表示来自人类用户的消息。

    ¥HumanMessage: Represents a message from a human user.

  • 输入和输出类型:Runnable 中用于输入和输出的类型。

    ¥input and output types: Types used for input and output in Runnables.

  • 集成包:与 LangChain 集成的第三方软件包。

    ¥Integration packages: Third-party packages that integrate with LangChain.

  • invoke:调用 Runnable 的标准方法。

    ¥invoke: A standard method to invoke a Runnable.

  • JSON 模式:返回 JSON 格式的响应。

    ¥JSON mode: Returning responses in JSON format.

  • @langchain/community:LangChain 的社区驱动组件。

    ¥@langchain/community: Community-driven components for LangChain.

  • @langchain/core:核心 langchain 包。包含基本接口和内存中实现。

    ¥@langchain/core: Core langchain package. Includes base interfaces and in-memory implementations.

  • langchain:一个用于更高级别组件(例如,一些预构建链)的包。

    ¥langchain: A package for higher level components (e.g., some pre-built chains).

  • @langchain/langgraph:LangChain 的强大编排层。用于构建复杂的管道和工作流。

    ¥@langchain/langgraph: Powerful orchestration layer for LangChain. Use to build complex pipelines and workflows.

  • 管理聊天历史记录:维护和管理聊天记录的技术。

    ¥Managing chat history: Techniques to maintain and manage the chat history.

  • OpenAI 格式:OpenAI 用于聊天模型的消息格式。

    ¥OpenAI format: OpenAI's message format for chat models.

  • RunnableConfig 传播:通过 Runnable 传播配置。

    ¥Propagation of RunnableConfig: Propagating configuration through Runnables.

  • RemoveMessage:用于从聊天历史记录中删除消息的抽象,主要用于 LangGraph。

    ¥RemoveMessage: An abstraction used to remove a message from chat history, used primarily in LangGraph.

  • role:表示聊天消息的角色(例如,用户、助手)。

    ¥role: Represents the role (e.g., user, assistant) of a chat message.

  • RunnableConfig:用于将运行时信息传递给可运行对象(例如 runNamerunIdtagsmetadatamaxConcurrencyrecursionLimitconfigurable)。

    ¥RunnableConfig: Use to pass run time information to Runnables (e.g., runName, runId, tags, metadata, maxConcurrency, recursionLimit, configurable).

  • 聊天模型的标准参数:API 密钥、temperaturemaxTokens 等参数

    ¥Standard parameters for chat models: Parameters such as API key, temperature, and maxTokens,

  • stream:用于流式传输 Runnable 或图表的输出。

    ¥stream: Use to stream output from a Runnable or a graph.

  • 令牌化:将数据转换为 token 以及将 token 转换为数据的过程。

    ¥Tokenization: The process of converting data into tokens and vice versa.

  • 分词器:语言模型在底层读取、处理和生成的基本单元。

    ¥Tokens: The basic unit that a language model reads, processes, and generates under the hood.

  • 工具构件:将工件添加到工具的输出中,这些工件不会发送到模型,但可用于下游处理。

    ¥Tool artifacts: Add artifacts to the output of a tool that will not be sent to the model, but will be available for downstream processing.

  • 工具绑定:将工具绑定到模型。

    ¥Tool binding: Binding tools to models.

  • tool:用于在 LangChain 中创建工具的功能。

    ¥tool: Function for creating tools in LangChain.

  • 工具包:可以使用的工具集合一起。

    ¥Toolkits: A collection of tools that can be used together.

  • ToolMessage:表示包含工具执行结果的消息。

    ¥ToolMessage: Represents a message that contains the results of a tool execution.

  • 向量存储:专门用于存储和高效搜索向量嵌入的数据存储。

    ¥Vector stores: Datastores specialized for storing and efficiently searching vector embeddings.

  • withStructuredOutput:一个用于聊天模型的辅助方法,原生支持 工具调用 获取与 Zod、JSON 模式或函数指定的模式匹配的结构化输出。

    ¥withStructuredOutput: A helper method for chat models that natively support tool calling to get structured output matching a given schema specified via Zod, JSON schema or a function.