Skip to content

vllm.entrypoints.pooling.scoring.utils

Functions:

_ensure_str(content)

Extract a single string prompt from parsed conversation content.

_truncate_text_to_tokens(text, tokenizer, max_tokens)

Return truncated text and its validated content-token count.

Uses offset_mapping to slice the original text at the exact character boundary, avoiding lossy encode→decode round-trips that can shift the token count due to BPE merge boundary changes. MistralTokenizer has no offset_mapping, so its boundary comes from the decoded token prefix; the token count of the sliced text is re-checked either way.

compress_token_type_ids(token_type_ids)

Return the half-open range containing token type 1.

Right padding uses the tokenizer's padding token type, which is commonly zero. Therefore, a padded query-document pair can contain zeros followed by ones followed by trailing zeros.

compute_maxsim_score(q_emb, d_emb)

Compute ColBERT MaxSim score.

Parameters:

  • q_emb

    (Tensor) –

    Query token embeddings [query_len, dim]

  • d_emb

    (Tensor) –

    Document token embeddings [doc_len, dim]

Returns:

  • Tensor –

    MaxSim score (sum over query tokens of max similarity to any doc token)

get_num_special_tokens_for_pair(tokenizer)

Get number of special tokens added for a text pair encoding.

parse_score_data_single(data, role, model_config)

Parse one ScoreData into a text prompt and its own multi-modal data.

Unlike parse_score_messages, each call creates an independent MultiModalItemTracker so multi-modal items are kept separate. This is the correct behaviour for late-interaction scoring, where query and document are encoded independently.

parse_score_messages(data_1, data_2, model_config, content_format='string')

Parse a scoring pair, retaining content blocks for OpenAI-format templates.

score_data_to_prompts(data_list, role, model_config)

Convert a list of ScoreData into PromptType objects.

For plain text inputs, returns the string directly. For multimodal inputs (list of content parts), parses them into a TextPrompt with attached multi_modal_data / multi_modal_uuids.

This is used by late-interaction scoring where each query/document is encoded independently.

truncate_score_content(content, tokenizer, max_tokens)

Limit text tokens across content blocks without dropping media blocks.

truncate_text_to_tokens(text, tokenizer, max_tokens)

Truncate text to a maximum number of content tokens.