Skip to main content

LangChain v0.3

上次更新:07.08.25

¥Last updated: 07.08.25

有哪些变化

¥What's changed

  • 所有 LangChain 软件包现在都将 @langchain/core 作为对等依赖,而不是直接依赖,以帮助避免 核心版本冲突 周围的类型错误。

    ¥All LangChain packages now have @langchain/core as a peer dependency instead of a direct dependency to help avoid type errors around core version conflicts.

    • 现在你需要明确安装 @langchain/core,而不是依赖其他软件包的内部解析版本。

      ¥You will now need to explicitly install @langchain/core rather than relying on an internally resolved version from other packages.

  • 回调现在默认在后台运行且非阻塞,而不是阻塞。

    ¥Callbacks are now backgrounded and non-blocking by default rather than blocking.

  • langchain 中移除了已弃用的文档加载器和自查询入口点,转而使用 @langchain/community 和集成包中的入口点。

    ¥Removed deprecated document loader and self-query entrypoints from langchain in favor of entrypoints in @langchain/community and integration packages.

  • 从社区中移除了已弃用的 Google PaLM 入口点,转而使用 @langchain/google-vertexai@langchain/google-genai 中的入口点。

    ¥Removed deprecated Google PaLM entrypoints from community in favor of entrypoints in @langchain/google-vertexai and @langchain/google-genai.

  • 不推荐使用 "type" 对象作为 BaseMessageLike 对象,而是使用更类似于 OpenAI 的 MessageWithRole 对象。

    ¥Deprecated using objects with a "type" as a BaseMessageLike in favor of the more OpenAI-like MessageWithRole

有哪些新功能

¥What’s new

在 0.2.x 开发过程中添加了以下功能:

¥The following features have been added during the development of 0.2.x:

如何更新代码

¥How to update your code

如果你使用的是 langchain / @langchain/community / @langchain/core 0.0 或 0.1,我们建议你先升级到 升级到 0.2 版本

¥If you're using langchain / @langchain/community / @langchain/core 0.0 or 0.1, we recommend that you first upgrade to 0.2.

如果你使用的是 @langchain/langgraph,请升级到 @langchain/langgraph>=0.2.3。这将适用于所有基础软件包的 0.2 或 0.3 版本。

¥If you're using @langchain/langgraph, upgrade to @langchain/langgraph>=0.2.3. This will work with either 0.2 or 0.3 versions of all the base packages.

以下是已发布的所有软件包的完整列表,以及我们建议你在 package.json 中升级到的版本约束。任何现在支持 @langchain/core 0.3 的软件包都进行了小版本升级。

¥Here is a complete list of all packages that have been released and what we recommend upgrading your version constraints to in your package.json. Any package that now supports @langchain/core 0.3 had a minor version bump.

基础包

¥Base packages

PackageLatestRecommended package.json constraint
langchain0.3.29>=0.3.58 <0.4.0
@langchain/community0.3.48>=0.3.58 <0.4.0
@langchain/textsplitters0.1.0>=0.2.21 <0.4.0
@langchain/core0.3.62>=0.3.0 <0.4.0

下游软件包

¥Downstream packages

PackageLatestRecommended package.json constraint
@langchain/langgraph0.3.7>=0.3.58 <0.4.0

集成包

¥Integration packages

PackageLatestRecommended package.json constraint
@langchain/anthropic0.3.24>=0.3.58 <0.4.0
@langchain/aws0.1.11>=0.3.58 <0.4.0
@langchain/azure-cosmosdb0.2.8>=0.2.21 <0.4.0
@langchain/azure-dynamic-sessions0.2.0>=0.2.21 <0.4.0
@langchain/baidu-qianfan0.1.0>=0.1.0 <0.4.0
@langchain/cloudflare0.1.0>=0.1.0 <0.4.0
@langchain/cohere0.3.4>=0.3.58 <0.4.0
@langchain/exa0.1.0>=0.1.0 <0.4.0
@langchain/google-genai0.2.14>=0.3.58 <0.4.0
@langchain/google-vertexai0.2.14>=0.3.58 <0.4.0
@langchain/google-vertexai-web0.2.14>=0.3.58 <0.4.0
@langchain/groq0.2.3>=0.3.58 <0.4.0
@langchain/mistralai0.2.1>=0.3.58 <0.4.0
@langchain/mixedbread-ai0.2.0>=0.2.21 <0.4.0
@langchain/mongodb0.1.0>=0.1.0 <0.4.0
@langchain/nomic0.1.0>=0.3.0 <0.4.0
@langchain/ollama0.2.3>=0.3.58 <0.4.0
@langchain/openai0.5.18>=0.3.58 <0.4.0
@langchain/pinecone0.2.0>=0.2.21 <0.4.0
@langchain/qdrant0.1.2>=0.2.21 <0.4.0
@langchain/redis0.1.1>=0.2.21 <0.4.0
@langchain/weaviate0.2.1>=0.2.21 <0.4.0
@langchain/yandex0.1.0>=0.2.21 <0.4.0

更新到软件包的最新版本后,如果尚未安装 @langchain/core,则需要显式安装:

¥Once you've updated to recent versions of the packages, you will need to explicitly install @langchain/core if you haven't already:

npm install @langchain/core

我们还建议你检查锁定文件或运行 合适的包管理器命令,以确保你的软件包管理器仅安装了一个版本的 @langchain/core

¥We also suggest checking your lockfile or running the appropriate package manager command to make sure that your package manager only has one version of @langchain/core installed.

如果你当前在无服务器环境中运行代码(例如,Cloudflare Worker、Edge 函数或 AWS Lambda 函数),并且正在使用 LangSmith 追踪或其他回调,则需要 await 回调函数以确保它们在函数结束前完成。以下是一个简单的示例:

¥If you are currently running your code in a serverless environment (e.g., a Cloudflare Worker, Edge function, or AWS Lambda function) and you are using LangSmith tracing or other callbacks, you will need to await callbacks to ensure they finish before your function ends. Here's a quick example:

import { RunnableLambda } from "@langchain/core/runnables";
import { awaitAllCallbacks } from "@langchain/core/callbacks/promises";

const runnable = RunnableLambda.from(() => "hello!");

const customHandler = {
handleChainEnd: async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
console.log("Call finished");
},
};

const startTime = new Date().getTime();

await runnable.invoke({ number: "2" }, { callbacks: [customHandler] });

console.log(`Elapsed time: ${new Date().getTime() - startTime}ms`);

await awaitAllCallbacks();

console.log(`Final elapsed time: ${new Date().getTime() - startTime}ms`);
Elapsed time: 1ms
Call finished
Final elapsed time: 2164ms

你还可以将 LANGCHAIN_CALLBACKS_BACKGROUND 设置为 "false",以使所有回调阻塞:

¥You can also set LANGCHAIN_CALLBACKS_BACKGROUND to "false" to make all callbacks blocking:

process.env.LANGCHAIN_CALLBACKS_BACKGROUND = "false";

const startTimeBlocking = new Date().getTime();

await runnable.invoke({ number: "2" }, { callbacks: [customHandler] });

console.log(
`Initial elapsed time: ${new Date().getTime() - startTimeBlocking}ms`
);
Call finished
Initial elapsed time: 2002ms