跳到主要内容

TensorFlow

此 Embeddings 集成完全在您的浏览器或 Node.js 环境中运行嵌入,使用 TensorFlow.js。这意味着您的数据不会发送给任何第三方,并且您无需注册任何 API 密钥。但是,它确实比其他集成需要更多的内存和处理能力。

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 文档


此页是否对您有帮助?


您也可以留下详细的反馈 在 GitHub 上.