in use-cases/rag-pipeline/embedding-models/multimodal-embedding/src/blip2_server.py [0:0]
def get_text_embedding(caption):
"""Generates text embeddings for a given caption.
Args:
caption: The input caption as a string.
Returns:
A torch.Tensor containing the text embeddings.
Raises:
ValueError: If there is an error generating the text embedding.
"""
try:
text_input = txt_processors["eval"](caption)
sample = {"text_input": [text_input]}
features_text = model.extract_features(sample, mode="text")
return features_text.text_embeds
except Exception as e:
raise ValueError(f"Error generating text embedding: {e}")