Skip to content

Chains

load_embedding_model(embedding_model_name, logger=BaseLogger(), config={})

Load the embedding model based on the specified name.

Parameters:

Name Type Description Default
embedding_model_name str

The name of the embedding model.

required
logger BaseLogger

The logger instance. Defaults to BaseLogger().

BaseLogger()
config dict

Additional configuration for loading the model. Defaults to {}.

{}

Returns:

Name Type Description
Tuple

A tuple containing embeddings and dimension.

Source code in apps/client-layer/streamlit-genai/streamlit_genai/chains.py
def load_embedding_model(embedding_model_name: str, logger=BaseLogger(), config={}):
    """
    Load the embedding model based on the specified name.

    Args:
        embedding_model_name (str): The name of the embedding model.
        logger (BaseLogger, optional): The logger instance. Defaults to BaseLogger().
        config (dict, optional): Additional configuration for loading the model. Defaults to {}.

    Returns:
        Tuple: A tuple containing embeddings and dimension.
    """
    if embedding_model_name == "ollama":
        embeddings = OllamaEmbeddings(
            base_url=config["ollama_base_url"], model="llama2"
        )
        dimension = 4096
        logger.info("Embedding: Using Ollama")
    else:
        embeddings = SentenceTransformerEmbeddings(
            model_name="all-MiniLM-L6-v2", cache_folder="/embedding_model"
        )
        dimension = 384
        logger.info("Embedding: Using SentenceTransformer")
    return embeddings, dimension