def get_embeddings()

in use-cases/rag-pipeline/backend/src/generate_embeddings.py [0:0]


def get_embeddings(image_uri=None, text=None):
    """
    Fetches embeddings based on the provided input.

    This function can generate text embeddings, image embeddings, or multimodal embeddings
    depending on the input provided.

    Args:
        text: The input text for text embeddings. Defaults to None.
        image_uri: The URI of the image for image embeddings. Defaults to None.

    Returns:
        The embeddings as a JSON object, or None if no valid input is provided.

    Raises:
        requests.exceptions.HTTPError: If there is an error fetching the embeddings from the API.
    """
    if image_uri and text:
        logger.info("Generating MULTIMODAL embeddings...")
        return get_multimodal_embeddings(image_uri, text)
    elif text:
        logger.info("Generating TEXT embeddings...")
        return get_text_embeddings(text)
    elif image_uri:
        logger.info("Generating IMAGE embeddings...")
        return get_image_embeddings(image_uri)
    else:
        logger.error(
            "Missing input. Provide a textual product description and/or image_uri to generate embeddings"
        )
        return None