Skip to content

BaseEmbeddings

This is the base module for all Embeddings model wrappers. Each specific Embedding class should extend this base class.

BaseEmbeddings

Bases: ABC

Base class for all Embeddings models. Each specific Embedding class should extend this class.

Parameters:

Name Type Description Default
model str

The model name used to generate the embeddings.

required
Source code in llmflows/llms/embeddings.py
class BaseEmbeddings(ABC):
    """
    Base class for all Embeddings models. Each specific Embedding class should extend
    this class.

    Args:
        model (str): The model name used to generate the embeddings.
    """

    def __init__(self, model: str):
        self.model = model

    @abstractmethod
    def generate(self, docs: Union[VectorDoc, list[VectorDoc]]):
        """
        Generates embeddings based on a VectorDoc or list of VectorDocs.

        Args:
            message_history: A `MessageHistory` object representing the conversation
                history.

        Returns:
            A string representing the generated text.
        """

    @abstractmethod
    async def generate_async(self, docs: Union[VectorDoc, list[VectorDoc]]):
        """
        Generates embeddings asynchronously based on a VectorDoc or list of VectorDocs.

        Args:
            message_history: A `MessageHistory` object representing the conversation
                history.

        Returns:
            A string representing the generated text.
        """

generate(docs) abstractmethod

Generates embeddings based on a VectorDoc or list of VectorDocs.

Parameters:

Name Type Description Default
message_history

A MessageHistory object representing the conversation history.

required

Returns:

Type Description

A string representing the generated text.

Source code in llmflows/llms/embeddings.py
@abstractmethod
def generate(self, docs: Union[VectorDoc, list[VectorDoc]]):
    """
    Generates embeddings based on a VectorDoc or list of VectorDocs.

    Args:
        message_history: A `MessageHistory` object representing the conversation
            history.

    Returns:
        A string representing the generated text.
    """

generate_async(docs) abstractmethod async

Generates embeddings asynchronously based on a VectorDoc or list of VectorDocs.

Parameters:

Name Type Description Default
message_history

A MessageHistory object representing the conversation history.

required

Returns:

Type Description

A string representing the generated text.

Source code in llmflows/llms/embeddings.py
@abstractmethod
async def generate_async(self, docs: Union[VectorDoc, list[VectorDoc]]):
    """
    Generates embeddings asynchronously based on a VectorDoc or list of VectorDocs.

    Args:
        message_history: A `MessageHistory` object representing the conversation
            history.

    Returns:
        A string representing the generated text.
    """