AI Agentic Handbook
Embeddings & Encoders

Instruction prefix (query: / passage:)

Mid levelReviewed Oct 2026In 1 interview question

A tiny label such as 'query: ' or 'passage: ' stuck in front of text before embedding it, telling the model which role this text is playing.

In plain English

Some Embedding models expect a short label in front of the text: query: before a user's question, passage: before a document. The label tells the model what job this text is doing, so it can park questions near the passages that answer them.

And if the model was trained with those labels and you leave them off? No error, no warning. You get numbers back — just worse ones.

Analogy

Handing the mail room a parcel marked 'outgoing' or 'incoming'. Same box either way; the label decides which shelf it lands on.

Common pitfall

It is reasonable to expect a missing prefix to throw something. It never does. Vectors shift quietly, and the damage stays hidden inside blended averages until you slice recall by ingestion source.

How it actually works

Instruction-tuned embedders are trained with role or task text prepended, so the prefix is part of the model's input distribution. Conventions as of Oct 2026: E5 and multilingual-e5 use query: / passage: ; nomic-embed-text uses search_query: / search_document: (plus clustering: , classification: ); bge-en-v1.5 adds Represent this sentence for searching relevant passages: to queries only; Qwen3-Embedding and gte-Qwen take a free-text instruction on the query side ('Instruct: Given a legal question, retrieve clauses that answer it\nQuery: …'); Cohere, Voyage and Gemini expose an input_type or task_type parameter instead of a string.

The prefix is therefore part of your index contract: change it and every stored vector is stale, exactly as if you changed the model. Record the exact strings with the model version in the Document registry, apply them in one shared embedding client rather than per pipeline, and treat a prefix change as a Backfill. Task-specific instructions (domain wording on the query side) can add 1–3 points of recall on instruction-following models without touching documents.

What I'd ship on day one

One shared embedding client that owns model id, revision, query prefix and document prefix as a single versioned config; every chunk stores the config hash; ingestion refuses to write if hashes disagree. For instruction-following models, start with a one-line task instruction naming the domain and answer type.

Worked example

Legal contracts search with multilingual-e5-large.

  • Index: passage: Either party may terminate this Agreement upon 90 days' written notice…
  • Query: query: notice period to terminate for convenience

Six months later a second ingestion path for scanned amendments ships without the passage: prefix. Overall recall@10 falls only from 0.88 to 0.84, so nobody notices, but sliced by source it is 0.89 for the original contracts and 0.61 for amendments, which are exactly the documents lawyers search for most.

In the interview

Tell it as a debugging story and name the prefix as an index contract: 'I keep the model id, the revision and both prefix strings in one config object, version it in the registry, and fail ingestion when the config hash on a chunk does not match the index's.' Expect 'can you change the query instruction without re-embedding?' — yes on query-side-only models like bge-en-v1.5 or Qwen3-Embedding, no for E5-style models where the documents carry a prefix too. Knowing which side carries the prefix is the tell.

Model familyQuery sideDocument side
E5 / multilingual-e5query: …passage: …
nomic-embed-text v1.5search_query: …search_document: …
bge-en-v1.5Represent this…: …(none)
Qwen3-EmbeddingInstruct: <task> Query:(none)
Cohere / Voyage APIinput_type=queryinput_type=document
Conventions as of Oct 2026. The strings are part of the index contract.

Numbers worth knowing

Prefix cost
2–20 tokens per inputfixed role strings vs free-text task instruction
Recall loss from a missing document prefix
5–30 points on the affected sliceE5-style models; diluted in blended averages
Gain from a domain task instruction
1–3 points recall@10instruction-following embedders, query side only (measure)

How to decide

WhenDo this
The model card lists prefixes or an input_type parameterApply them on both paths and test for them in CI.
The model takes a query-side instruction onlyTune the instruction per domain freely; documents need no re-embed.
You want to change a document-side prefixTreat it as a new model: new index, Backfill, Index alias swap.

Cost maths

A document-prefix mistake costs a re-embed of the affected slice. 1.2M amendment chunks × 500 tokens = 600M tokens × $0.02/M (text-embedding-3-small) = $12, or a few GPU-hours self-hosted. The real cost is the weeks of degraded answers before detection, which is why the per-source recall slice matters more than the bill.

Operating it

Time to scale up when…
  • More than one ingestion path writes to the same index: centralize the embedding client
  • More than one model or prefix version live at once: add a config-hash check at query time
What to monitor
  • Distinct embedding-config hashes per index: alert if more than 1 (outside a backfill window)
  • Golden-set recall@10 per ingestion source: alert on any source 5+ points below the median

When it goes wrong

What users saw

Lawyers reported that amendments never showed up in contract search, though the base contracts did.

How it was caught

Recall@10 sliced by source showed 0.61 for the OCR amendments pipeline vs 0.89 elsewhere.

Root cause

The amendments pipeline called the model directly and skipped the passage: prefix.

Fix

Moved prefixes into a shared client, stored a config hash per chunk, re-embedded 1.2M chunks, added a CI test that embeds a fixture through every pipeline and compares vectors.

Sources

  1. Text Embeddings by Weakly-Supervised Contrastive Pre-training (E5) — Wang et al., 2022paper
  2. One Embedder, Any Task: Instruction-Finetuned Text Embeddings — Su et al., 2022paper
  3. Nomic Embed: Training a Reproducible Long Context Text Embedder — Nussbaum et al., 2024paper
  4. Embed API reference (input_type) — Cohere, 2025docs

Check yourself

Three questions. Every option is explained once you answer.

1ConceptWhy does the page treat an E5-style document prefix as part of the index contract rather than a tunable setting?
2ScenarioYou run Qwen3-Embedding on a legal corpus and want to try a domain task instruction to gain recall, without a re-embed. What applies?
3CalculationAn amendments pipeline skipped the 'passage: ' prefix on 1.2M chunks of ~500 tokens. Re-embedding with text-embedding-3-small at $0.02/M tokens costs roughly how much?