Using NLPCloud Embeddings with LangChain for Multilingual Text Processing
Posted: Feb 18, 2025.
NLPCloud Embeddings is a powerful integration in LangChain that allows you to generate vector representations of text using NLPCloud's advanced embedding models. It's particularly useful for multilingual applications since it supports text processing in more than 50 languages.
What is NLPCloudEmbeddings?
NLPCloudEmbeddings is a LangChain wrapper for NLP Cloud's embedding service. It provides access to models like paraphrase-multilingual-mpnet-base-v2
, which is based on Sentence Transformers and optimized for extracting embeddings across multiple languages. These embeddings can be used for various NLP tasks like semantic search, text similarity, and document clustering.
Reference
Method | Description |
---|---|
embed_documents(texts: List[str]) | Generates embeddings for a list of text documents |
embed_query(text: str) | Generates an embedding for a single query text |
aembed_documents(texts: List[str]) | Asynchronous version of embed_documents |
aembed_query(text: str) | Asynchronous version of embed_query |
Additional parameters:
gpu
: Boolean to specify if GPU should be usedmodel_name
: Name of the embedding model to use
How to use NLPCloudEmbeddings
Initial Setup
First, you'll need to install the required package and set up your API key:
Basic Usage
Here's how to create embeddings for both individual queries and documents:
Async Operations
For better performance in async applications, you can use the async methods:
Custom Model Configuration
You can customize the embedding model configuration:
Error Handling
The class includes built-in environment validation. Here's how to handle potential errors:
NLPCloudEmbeddings is particularly useful when you need to process text in multiple languages or require high-quality embeddings for downstream tasks. The async support makes it suitable for high-performance applications where parallel processing is important.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.