DeepInfraEmbeddings
class utilizes the DeepInfra API to generate embeddings for given text inputs. This guide will walk you through the setup and usage of the DeepInfraEmbeddings
class, helping you integrate it into your project seamlessly.
Installation
Install the@langchain/community
package as shown below:
npm
Initialization
With this integration, you can use the DeepInfra embeddings model to get embeddings for your text data. Here is the link to the embeddings models. First, you need to sign up on the DeepInfra website and get the API token from here. You can copy names from the model cards and start using them in your code. To use theDeepInfraEmbeddings
class, you need an API token from DeepInfra. You can pass this token directly to the constructor or set it as an environment variable (DEEPINFRA_API_TOKEN
).
Basic Usage
Here’s how to create an instance ofDeepInfraEmbeddings
:
apiToken
is not provided, it will be read from the DEEPINFRA_API_TOKEN
environment variable.
Generating Embeddings
Embedding a Single Query
To generate embeddings for a single text query, use theembedQuery
method:
Embedding Multiple Documents
To generate embeddings for multiple documents, use theembedDocuments
method. This method will handle batching automatically based on the batchSize
parameter:
Customizing Requests
You can customize the base URL the SDK sends requests to by passing aconfiguration
parameter:
Error Handling
If the API token is not provided and cannot be found in the environment variables, an error will be thrown:Example
Here’s a complete example of how to set up and use theDeepInfraEmbeddings
class:
Feedback and Support
For feedback or questions, please contact feedback@deepinfra.com.Related
- Embedding model conceptual guide
- Embedding model how-to guides