Search execution from query to result
A search can find the nearest vectors and still return no usable results. The failure may come from filtering, stale document representations, or candidates that never reached the final ranking. We'll follow an invoice question through authorization, retrieval, filtering, and ranking to locate those failures.
Our user asks, “How do I download last month's invoice?” They belong to tenant A and can read only English, published articles. The task is to return two useful articles without letting another tenant's text reach the user or a downstream model.
Construct a compatible query
The application first checks the user's identity and derives the allowed tenant and access scope. A caller-supplied tenant string is not proof of membership.
Next, encode the question using the embedding model and query format compatible with the stored document vectors. Record the model version and relevant preprocessing choices during ingestion, so that compatibility is something you can check.
A query prefix can matter for an asymmetric retrieval model, where questions and documents play different roles. Equal vector dimensions alone are not enough.
The embedding call also has its own latency and failure path. If it fails, there is no query vector for the vector index to search. A keyword fallback may be useful, but it should be an intentional product behaviour.
Retrieve eligible candidates
Suppose an unfiltered candidate search produces these invented results in score order:
| Candidate | Tenant | Language | Published? |
|---|---|---|---|
| A1 | A | English | Yes |
| B1 | B | English | Yes |
| A2 | A | Spanish | Yes |
| A3 | A | English | No |
| A4 | A | English | Yes |
If you retrieve only the first three and then apply filters, just A1 remains. Asking for two final results does not guarantee receiving two eligible candidates.
What changes if you fetch five? In this fixture, A4 becomes available and you can return two. In a real corpus, fetching five is not a general guarantee. Filter selectivity and candidate distribution vary.
A candidate budget and a final result count have different jobs. Filtering can consume the shortlist before ranking begins.
Filtering has several implementations
A pre-filter restricts the eligible set before or during vector search. An engine might use an index on metadata, restrict partitions, or incorporate the predicate into its search process.
A post-filter removes ineligible candidates after a retrieval stage. This can be straightforward, but a selective filter may leave too few results. Some engines keep searching until enough matches are found or a budget is exhausted.
There isn't one universal ordering for every database. Check what its filter actually does with the chosen index. The important contract is that unauthorized content cannot enter the result payload or the generation context.
Keep authorization enforcement separate from ranking convenience. Even if retrieval uses a metadata filter, validate permissions at the appropriate data-access boundary before exposing document text.
Spend more attention on a small set
Before a text-based reranker runs, fetch the candidate text through the authorized data-access path. Recheck access and discard deleted or outdated records at that boundary, so unauthorized text never reaches the reranker.
An embedding search represents the question and article separately. A reranker can inspect the question and candidate text together, assigning a score that is more sensitive to their specific relationship.
That joint processing is usually more expensive per pair. A common arrangement retrieves a larger candidate set cheaply, then reranks only those candidates to choose the final few.
For example, “Change your billing address” and “Download an invoice” may both be close to the query's billing topic. A reranker can use the full question to distinguish the requested action.
Can a reranker fix an absent invoice article? No. It only sees the candidates supplied to it. This is why candidate recall remains important even with a strong reranker.
Rescoring compressed vectors with full-precision vectors is another refinement step. It repairs numeric approximations. A text-based reranker addresses a different problem: judging relevance with a richer comparison.
Return enough evidence to debug
After ranking, assemble the final response from the permitted, current records: stable IDs, titles, snippets, and links. If the article changed after its embedding was computed, the stale representation can mislead retrieval even though the displayed text is current.
Internally, trace the request stages with timings and counts: embedding succeeded, candidate count, eligible count, reranked count, and returned count. Avoid logging private content by default just to get those measurements.
These counts tell a useful story. Zero candidates suggests a retrieval or query problem. Many candidates but one eligible result suggests filtering or candidate budget. Several eligible results with poor final order suggests scoring or relevance.
Repair the stage that failed
Try this diagnosis: exact filtered search returns the correct article at rank 1; ANN finds it in the top 30; your application retrieves only ten before reranking. Which change would you test first?
Increase the first-stage candidate budget or improve ANN exploration, then measure the extra cost. Changing the final language model would not address the missing article.
For your own search feature, draw the same request with a count beside each transition. Label each arrow with what crosses it, such as a query vector, candidate IDs, or permitted text. Then mark the stage that could explain an empty result.
Lesson notes
Trace an invoice search through query encoding, access filters, candidate retrieval, and reranking. Use counts at each stage to diagnose missing results.
Key ideas
- Query embedding → candidate retrieval → scoring → filter → rank
- Pre-filter vs post-filter trade-offs
- Re-ranking as the quality rescue layer