import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer model_id = "flintglass/PrismRerank-0.6B"tok = AutoTokenizer.from_pretrained(model_id, padding_side="left")model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto").eval() yes_id = tok.convert_tokens_to_ids("yes")no_id = tok.convert_tokens_to_ids("no") PREFIX = '<|im_start|>system\nJudge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be "yes" or "no".<|im_end|>\n<|im_start|>user\n'SUFFIX = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"INST = "Given a web search query, retrieve relevant passages that answer the query" query = "How does Matryoshka Representation Learning reduce vector database memory?"docs = [ "Matryoshka Representation Learning trains embeddings so leading prefixes (e.g., 128d or 256d) preserve retrieval quality, shrinking vector index RAM by 4x-8x.", "The Russian nesting doll was first carved in 1890 by Vasily Zvyozdochkin.",] texts = [f"{PREFIX}<Instruct>: {INST}\n<Query>: {query}\n<Document>: {d}{SUFFIX}" for d in docs]enc = tok(texts, padding=True, truncation=True, max_length=8192, return_tensors="pt").to(model.device)with torch.inference_mode(): logits = model(**enc).logits[:, -1, :]scores = torch.sigmoid(logits[:, yes_id] - logits[:, no_id]).float().cpu().tolist()for s, d in sorted(zip(scores, docs), reverse=True): print(f"{s:.4f} | {d}")