Skip to main content

TensorFlow

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

¥This Embeddings integration runs the embeddings entirely in your browser or Node.js environment, using TensorFlow.js. This means that your data isn't sent to any third party, and you don't need to sign up for any API keys. However, it does require more memory and processing power than the other integrations.

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

¥This example uses the CPU backend, which works in any JS environment. However, you can use any of the backends supported by TensorFlow.js, including GPU and WebAssembly, which will be a lot faster. For Node.js you can use the @tensorflow/tfjs-node package, and for the browser you can use the @tensorflow/tfjs-backend-webgl package. See the TensorFlow.js documentation for more information.

¥Related