Using Jina Embeddings in LangChain for Text and Image Embeddings
Posted: Feb 21, 2025.
Jina AI embeddings provide a powerful way to convert text and images into vector representations that can be used for semantic search and other machine learning tasks. This guide shows you how to use JinaEmbeddings in LangChain.
What is JinaEmbeddings?
JinaEmbeddings is a LangChain integration that allows you to generate embeddings using Jina AI's embedding models. It supports both text and image embeddings, making it versatile for multimodal applications. The default model is 'jina-embeddings-v2-base-en', which is optimized for English text.
Reference
Method | Description |
---|---|
embed_documents(texts) | Converts a list of texts into their vector embeddings |
embed_query(text) | Converts a single text into its vector embedding |
embed_images(uris) | Converts a list of image URIs into their vector embeddings |
aembed_documents(texts) | Async version of embed_documents |
aembed_query(text) | Async version of embed_query |
How to Use JinaEmbeddings
Initial Setup
First, you'll need to get a Jina AI API token and install the necessary package:
Generating Text Embeddings
You can generate embeddings for single or multiple texts:
Working with Image Embeddings
JinaEmbeddings also supports image embeddings using URLs:
Async Operations
For better performance in async applications, you can use the async methods:
Integration with Vector Stores
JinaEmbeddings can be easily integrated with vector stores for similarity search:
This setup allows you to create powerful semantic search applications using Jina AI's state-of-the-art embedding models. The embeddings can be used for various downstream tasks like document retrieval, clustering, or as input features for machine learning models.
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.