LangChain MLflow AI Gateway Embeddings: Connect to MLflow Embedding Models
Posted: Nov 14, 2024.
The MlflowAIGatewayEmbeddings class in LangChain allows you to generate embeddings using models deployed through MLflow AI Gateway. This integration enables you to leverage MLflow's model serving capabilities while maintaining a consistent interface for embedding generation in your LangChain applications.
What is MlflowAIGatewayEmbeddings?
MlflowAIGatewayEmbeddings is a class that implements LangChain's Embeddings interface to connect with embedding models served through MLflow AI Gateway. It provides methods to generate embeddings for both individual queries and collections of documents through MLflow's serving infrastructure.
Reference
Here are the key components of the MlflowAIGatewayEmbeddings class:
Parameter/Method | Description |
---|---|
gateway_uri | The URI where your MLflow AI Gateway API is hosted |
route | The specific route/endpoint for the embeddings model on the MLflow AI Gateway |
embed_documents() | Generates embeddings for a list of documents |
embed_query() | Generates an embedding for a single text query |
aembed_documents() | Async version of embed_documents |
aembed_query() | Async version of embed_query |
How to Use MlflowAIGatewayEmbeddings
Basic Setup
First, make sure you have the required package installed:
Then, you can initialize the embeddings class:
Generating Embeddings for Single Texts
To generate embeddings for a single piece of text:
Generating Embeddings for Multiple Documents
For batch processing of multiple texts:
Using Async Methods
If you're working in an async environment, you can use the async versions of the methods:
Integration with Other LangChain Components
MlflowAIGatewayEmbeddings can be used with other LangChain components that require embeddings, such as vector stores:
By using MlflowAIGatewayEmbeddings, you can seamlessly integrate MLflow-served embedding models into your LangChain applications while taking advantage of MLflow's model serving capabilities and management features.
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.