Spaces:
Runtime error
Runtime error
File size: 904 Bytes
8a58cf3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
"""Langchain Embedding Wrapper Module."""
from typing import List
from langchain.embeddings.base import Embeddings as LCEmbeddings
from gpt_index.embeddings.base import BaseEmbedding
class LangchainEmbedding(BaseEmbedding):
"""External embeddings (taken from Langchain).
Args:
langchain_embedding (langchain.embeddings.Embeddings): Langchain
embeddings class.
"""
def __init__(self, langchain_embedding: LCEmbeddings) -> None:
"""Init params."""
super().__init__()
self._langchain_embedding = langchain_embedding
def _get_query_embedding(self, query: str) -> List[float]:
"""Get query embedding."""
return self._langchain_embedding.embed_query(query)
def _get_text_embedding(self, text: str) -> List[float]:
"""Get text embedding."""
return self._langchain_embedding.embed_documents([text])[0]
|