Closed Jtewen closed 11 months ago
🤖
Hello,
Thank you for your request. I understand that you would like to add embeddings for Amazon Bedrock to the LangChain framework.
Based on the current structure of the LangChain codebase, the embeddings are handled by the embeddings
module. This module contains an abstract class Embeddings
with two methods: embedDocuments
and embedQuery
. These methods are meant to be overridden by subclasses that provide specific implementations for embedding documents and queries.
In a similar issue, Support for Amazon Bedrock, the support for Amazon Bedrock was added by creating a new subclass of Embeddings
and providing the specific implementation for the embedDocuments
and embedQuery
methods. This issue was closed by a pull request: Add Amazon Bedrock LLM endpoint integration.
To add embeddings for Amazon Bedrock, you would need to follow a similar approach. You would need to create a new subclass of Embeddings
and provide the specific implementation for the embedDocuments
and embedQuery
methods. The embedDocuments
method should take an array of documents as input and return a promise that resolves to an array of vectors for each document. The embedQuery
method should take a single document as input and return a promise that resolves to a vector for the query document.
Here is a basic example of how you could structure your new subclass:
import { Embeddings } from 'langchain/src/embeddings/base';
class AmazonBedrockEmbeddings extends Embeddings {
async embedDocuments(documents: string[]): Promise<number[][]> {
// Your implementation here
}
async embedQuery(document: string): Promise<number[]> {
// Your implementation here
}
// Any other methods or properties specific to Amazon Bedrock
}
Please note that this is a simplified example and your actual implementation may need to include additional methods or properties specific to Amazon Bedrock. Also, if you plan to use caching for your embeddings, you could consider using the CacheBackedEmbeddings
class, which provides a caching mechanism for embeddings.
I hope this helps! If you have any further questions or need more clarification, please let me know.
Best, Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
I'd be happy to take this on. I can start work this week.
Currently only supported in the python version of langchain.