TransformerEmbeddings
class uses the Transformers.js package to generate embeddings for a given text.
It runs locally and even works directly in the browser, allowing you to create web apps with built-in embeddings.
Setup
You’ll need to install the @huggingface/transformers package as a peer dependency:CompatibilityIf you are using a version of community older than 0.3.21, install the older
@xenova/transformers
package and
import the embeddings from "@langchain/community/embeddings/hf_transformers"
below.npm
npm
Example
Note that if you’re using in a browser context, you’ll likely want to put all inference-related code in a web worker to avoid blocking the main thread. See this guide and the other resources in the Transformers.js docs for an idea of how to set up your project.Related
- Embedding model conceptual guide
- Embedding model how-to guides