feat: add Google embedding support & update setup (#550) bump:patch
This commit is contained in:
committed by
GitHub
parent
159f4da7c9
commit
b016a84b97
@@ -4,6 +4,7 @@ from .fastembed import FastEmbedEmbeddings
|
||||
from .langchain_based import (
|
||||
LCAzureOpenAIEmbeddings,
|
||||
LCCohereEmbeddings,
|
||||
LCGoogleEmbeddings,
|
||||
LCHuggingFaceEmbeddings,
|
||||
LCOpenAIEmbeddings,
|
||||
)
|
||||
@@ -18,6 +19,7 @@ __all__ = [
|
||||
"LCAzureOpenAIEmbeddings",
|
||||
"LCCohereEmbeddings",
|
||||
"LCHuggingFaceEmbeddings",
|
||||
"LCGoogleEmbeddings",
|
||||
"OpenAIEmbeddings",
|
||||
"AzureOpenAIEmbeddings",
|
||||
"FastEmbedEmbeddings",
|
||||
|
@@ -219,3 +219,38 @@ class LCHuggingFaceEmbeddings(LCEmbeddingMixin, BaseEmbeddings):
|
||||
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
||||
|
||||
return HuggingFaceBgeEmbeddings
|
||||
|
||||
|
||||
class LCGoogleEmbeddings(LCEmbeddingMixin, BaseEmbeddings):
|
||||
"""Wrapper around Langchain's Google GenAI embedding, focusing on key parameters"""
|
||||
|
||||
google_api_key: str = Param(
|
||||
help="API key (https://aistudio.google.com/app/apikey)",
|
||||
default=None,
|
||||
required=True,
|
||||
)
|
||||
model: str = Param(
|
||||
help="Model name to use (https://ai.google.dev/gemini-api/docs/models/gemini#text-embedding-and-embedding)", # noqa
|
||||
default="models/text-embedding-004",
|
||||
required=True,
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
model: str = "models/text-embedding-004",
|
||||
google_api_key: Optional[str] = None,
|
||||
**params,
|
||||
):
|
||||
super().__init__(
|
||||
model=model,
|
||||
google_api_key=google_api_key,
|
||||
**params,
|
||||
)
|
||||
|
||||
def _get_lc_class(self):
|
||||
try:
|
||||
from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
||||
except ImportError:
|
||||
raise ImportError("Please install langchain-google-genai")
|
||||
|
||||
return GoogleGenerativeAIEmbeddings
|
||||
|
Reference in New Issue
Block a user