跳到主要内容
此嵌入集成完全在您的浏览器或 Node.js 环境中运行嵌入,使用 TensorFlow.js。这意味着您的数据不会发送给任何第三方,并且您无需注册任何 API 密钥。但是,它比其他集成需要更多的内存和处理能力。
npm
npm install @langchain/community @langchain/core @tensorflow/tfjs-core@3.6.0 @tensorflow/tfjs-converter@3.6.0 @tensorflow-models/universal-sentence-encoder@1.3.3 @tensorflow/tfjs-backend-cpu
import "@tensorflow/tfjs-backend-cpu";
import { TensorFlowEmbeddings } from "@langchain/community/embeddings/tensorflow";

const embeddings = new TensorFlowEmbeddings();
此示例使用 CPU 后端,它适用于任何 JS 环境。但是,您可以使用 TensorFlow.js 支持的任何后端,包括 GPU 和 WebAssembly,它们会快得多。对于 Node.js,您可以使用 @tensorflow/tfjs-node 包,对于浏览器,您可以使用 @tensorflow/tfjs-backend-webgl 包。有关更多信息,请参阅 TensorFlow.js 文档
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.