JinaEmbeddings
class utilizes the Jina API to generate embeddings for given text inputs. This guide will walk you through the setup and usage of the JinaEmbeddings
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 Jina 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 Jina website and get the API token from here. You can copy model names from the dropdown in the api playground. To use theJinaEmbeddings
class, you need an API token from Jina. You can pass this token directly to the constructor or set it as an environment variable (JINA_API_KEY
).
Basic Usage
Here’s how to create an instance ofJinaEmbeddings
:
apiKey
is not provided, it will be read from the JINA_API_KEY
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.
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 theJinaEmbeddings
class:
Feedback and Support
For feedback or questions, please contact support@jina.ai.Related
- Embedding model conceptual guide
- Embedding model how-to guides