EmbeddingGemma 2 is one model used for search, question answering, fact checking, code retrieval, classification, clustering and sentence similarity. It tells the tasks apart by a short prefix on the text. Implement the formatting from the model card.
format_query(task, text)
"task: {name} | query: {text}" where name is the task phrase for the prompt name: SearchQuery is search result, QuestionAnswering is question answering, FactChecking is fact checking, CodeRetrieval is code retrieval, Classification is classification, Clustering is clustering, SentenceSimilarity is sentence similarity. An unknown task raises KeyError.format_document(text, title=None)
"title: {title} | text: {text}", with the literal none when no title is given.is_symmetric(task)
True for Classification, Clustering and SentenceSimilarity (both sides of a pair are formatted as queries), False for the retrieval-style tasks.format_pair(task, left, right, right_title=None)
(format_query(task, left), format_query(task, right)); for an asymmetric task return (format_query(task, left), format_document(right, right_title)).drop_prefix(formatted, u, p)
formatted is a list of query strings and u a list of numbers in [0, 1) of the same length. For every position with u[i] < p, replace the string by the text after "| query: "; otherwise keep it. Return the new list.str.split("| query: ", 1)[1] recovers the raw text.