<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by arash sangari on Medium]]></title>
        <description><![CDATA[Stories by arash sangari on Medium]]></description>
        <link>https://medium.com/@arashaneh?source=rss-ea7fc8fffcb6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6xv9Lc45i9e5tNsM.</url>
            <title>Stories by arash sangari on Medium</title>
            <link>https://medium.com/@arashaneh?source=rss-ea7fc8fffcb6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:37:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arashaneh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Steering Retrieval Toward Intent — Without Retraining Your Embedding Model]]></title>
            <link>https://medium.com/@arashaneh/steering-retrieval-toward-intent-without-retraining-your-embedding-model-1da27a78e7e3?source=rss-ea7fc8fffcb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1da27a78e7e3</guid>
            <category><![CDATA[intent-steering]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[vector-embeddings]]></category>
            <dc:creator><![CDATA[arash sangari]]></dc:creator>
            <pubDate>Fri, 29 May 2026 05:28:37 GMT</pubDate>
            <atom:updated>2026-05-29T05:50:40.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>A practical look at query-side bilinear steering, whether “linear” is a fair assumption, and what the numbers actually say</h3><p>Most RAG and agentic-retrieval systems treat the embedding model as a fixed oracle: you encode your corpus once, drop the vectors in a store, and search by cosine similarity. That works beautifully until you need the <em>same</em> corpus to answer to <em>different</em> goals.</p><p>Here’s the situation that got me thinking. Imagine a support-ticket corpus. Sometimes I want “messages about billing.” Other times I want “messages where the customer intends to cancel,” regardless of topic. Sometimes I want to organize by emotional tone. The corpus is identical; only the <strong>lens</strong> changes. A generic embedder bakes one fixed notion of similarity — usually dominated by topic and surface wording — into every vector, and that notion doesn’t bend to my intent.</p><p>The obvious fixes are expensive or invasive:</p><ul><li><strong>Re-encode per intent</strong> with an instruction-aware model. Now every new lens means another full pass over the corpus and another index. That’s O(instructions × documents) forward passes — fine for a benchmark, painful for a vector DB with millions of rows.</li><li><strong>Fine-tune or swap the embedding model.</strong> Heavy, and you lose the convenience of a single frozen index.</li><li><strong>Rewrite the query with an LLM</strong> (HyDE-style). Effective, but it adds an LLM call to every query and only ever touches the query side.</li></ul><p>So I asked a narrower question: <strong>can I steer retrieval toward a specific intent or domain without retraining the model, without re-encoding the corpus, and ideally without an LLM in the hot path — just by transforming the query against an index I already have?</strong></p><p>This post walks through where that leads: a tiny learned transform you apply to the query, whether the linearity it assumes is justified, the literature it sits on, and a small experiment (with real numbers and honest limitations) on a public dataset.</p><h3>The idea: push the transform onto the query</h3><p>Start from the bilinear similarity form. Instead of plain cosine, score a query–document pair as:</p><pre>score(q, d) = qᵀ S d</pre><p>where S is a learned matrix that encodes &quot;what matters under this intent.&quot; If you parameterize S as a small perturbation of the identity,</p><pre>S = I + U Vᵀ,     U, V ∈ ℝ^{n×r},   r ≪ n</pre><p>then the score splits cleanly into base similarity plus an intent-specific interaction:</p><pre>qᵀ S d  =  q·d  +  (Uᵀq)·(Vᵀd)<br>           └base┘   └ intent ┘</pre><p>S = I recovers ordinary search, so the low-rank piece UVᵀ <em>is</em> the intent. An under-trained or low-confidence intent degrades gracefully back toward plain retrieval.</p><p>The crucial property is that this folds onto the query. Because qᵀSd = (Sᵀq)ᵀd, you can precompute</p><pre>q̃ = Sᵀ q = q + V (Uᵀ q)</pre><p>— one cheap matrix–vector product — and then run <strong>ordinary inner-product (MIPS) search against the untouched index</strong>. The corpus vectors never move. Switching intent means swapping a different (U, V) and re-folding the query. One frozen index, many lenses, each lens a kilobyte-sized matrix.</p><p>If you’ve done metric learning, this will look familiar: it’s a low-rank Mahalanobis metric, and “carry the metric vs. transform both sides” is a standard equivalence. The twist here is doing it <em>asymmetrically and query-side</em>, conditioned on a natural-language intent, on top of frozen modern embeddings.</p><p>A subtle but important point: applying S to the corpus (the way a re-encoding method would) and folding S onto the query are mathematically equivalent for inner-product ranking — but only when S is <strong>linear</strong>. The moment you make the transform nonlinear (an MLP), that equivalence breaks and you&#39;re back to either transforming documents or reranking a candidate set. Which raises the real question.</p><h3>Is linearity the right assumption?</h3><p>This is the load-bearing assumption, so it deserves scrutiny rather than faith. The good news is there’s a substantial body of evidence that high-level, human-meaningful concepts live in <strong>linear</strong> structure inside embedding spaces.</p><ul><li><strong>The linear representation hypothesis.</strong> The idea that concepts are encoded as directions in representation space goes back to word2vec analogies and has been formalized recently — Park, Choe &amp; Veitch (ICML 2024) connect linear representation to <em>both</em> linear probing and steering and demonstrate it on LLaMA-2; follow-up work argues the next-token objective plus gradient descent actively <em>promote</em> linear representations. Your frozen embedder is trained the same way.</li><li><strong>You can manipulate concepts with linear operations.</strong> This is the strongest operational evidence. Concept-erasure methods remove an attribute (gender, part-of-speech, profession) by <em>linear projection</em> — INLP (Ravfogel et al. 2020), the closed-form LEACE (Belrose et al. 2023), and R-LACE, which found a <em>single-dimensional</em> subspace whose removal neutralized gender. The logic cuts both ways: if a concept lives in a linearly-removable subspace, it lives in a linearly-<em>amplifiable</em> one too. A bilinear S is the amplifying mirror image of erasure.</li></ul><p>The honest counter-evidence: the <em>strong</em> form of the hypothesis doesn’t hold universally. Some features are irreducibly multi-dimensional (time-like concepts form circular manifolds), and capacity-constrained models can use nonlinear encodings. “Linearly decodable” is also a weaker condition than “one global linear reweighting cleanly reorganizes the space for top-k retrieval.” So the right stance is empirical: linearity is a <em>strong, well-supported default</em> for attribute- and intent-level structure, and the question of whether it’s <em>enough for your data</em> is something to measure, not assume — which is exactly what the experiment below does, by pitting the linear map against a nonlinear MLP.</p><h3>Where this sits in the literature</h3><p>A few threads converge here, and it’s worth knowing which is which.</p><p><strong>Query rewriting (LLM in the loop).</strong> HyDE — “Precise Zero-Shot Dense Retrieval without Relevance Labels” (Gao et al., 2023) — has an LLM write a hypothetical answer document, embeds <em>that</em>, and searches document–document space. Intent enters through the generation prompt. Powerful and training-free, but it’s a per-query LLM call and only reshapes the query.</p><p><strong>Instruction-aware embedders (re-encode the world).</strong> INSTRUCTOR, E5-Mistral, GritLM, and especially <strong>Promptriever</strong> (2024) — the first retriever you can prompt with free-form natural-language instructions, trained with “instruction negatives” (pairs relevant in isolation but not under the instruction). These work well but imply encoding text with the instruction attached, i.e. re-encoding per instruction.</p><p><strong>Efficient instruction-following by transforming pre-computed embeddings.</strong> <strong>GSTransform</strong> — “Don’t Reinvent the Wheel” (2025) — is the closest cousin. Its premise is the one I started from: generic embeddings already contain instruction-relevant information but don’t prioritize it, so instead of re-encoding it learns a transformation over the <em>cached</em> embeddings, reporting 6–300× speedups over re-encoding methods. Notably, its released encoder is a single linear layer — which is what told me the query-side fold should be possible at all. GSTransform transforms the store; the variant in this post transforms the query.</p><p><strong>Bilinear retrieval and metric learning (the foundation).</strong> The “apply a learned matrix and keep your index” trick is old. Supervised Semantic Indexing (Bai, Weston et al., 2009) learns qᵀWd for text retrieval with a low-rank W and models query and document separately so the matrix folds onto the query. OASIS (Chechik et al., 2009) learns an unconstrained bilinear image similarity. A query-dependent bilinear paper (Kuang et al., 2013) states the move explicitly: query adaptation by applying a standard index to a <em>transformed surrogate of the query</em>. The whole approach here is really &quot;re-derive intent-conditioned retrieval as a query-side bilinear similarity on frozen LLM embeddings.&quot;</p><p>The gap I couldn’t find filled: a <em>per-intent, instruction-derived</em> bilinear matrix, learned cheaply, applied <strong>query-side</strong> against a single frozen index, with the linearity assumption actually tested. So I built a small one.</p><h3>The experiment</h3><h3>Dataset: CLINC150</h3><p>I used <strong>CLINC150</strong> (clinc/clinc_oos on Hugging Face, CC-BY-3.0). It&#39;s a task-oriented dialog dataset of short user utterances, and its key feature for this purpose is that every utterance carries <strong>two labels on the same text</strong>: a fine <strong>intent</strong> (150 classes) and a coarse <strong>domain</strong> (10 classes, e.g. banking, credit_cards, travel, work). That gives two organizing axes over an identical corpus — exactly the &quot;same text, different lens&quot; setup — plus natural hard negatives (same domain, different intent). It&#39;s tiny (~15k/3k/5k), permissively licensed, and the banking/credit-card domains are realistic.</p><p>Its limitations matter and shape the results. Utterances are short and on-the-nose, so a <em>good</em> encoder basically already maps each one to its intent — there’s little to fix. And the two axes are <strong>nested</strong> (each intent belongs to exactly one domain) rather than orthogonal, so it’s not the ideal “topic × sentiment” conflict. Both caveats turn out to be visible in the numbers, which is itself instructive.</p><h3>Method</h3><p>For each axis I learn S = I + UVᵀ (rank 32) with an in-batch InfoNCE objective (same-label pairs as positives, every other in-batch item as a negative) plus a small ‖U‖² + ‖V‖² penalty pulling S toward identity. I apply it query-side and search a frozen index. The code asserts q̃·d == qᵀSd exactly, so the fold is provably equivalent to the bilinear score.</p><p>The decisive variable is the <strong>base encoder</strong>, tested two ways:</p><ul><li>bert-base-uncased, mean-pooled — a <strong>generic</strong> encoder not tuned for similarity, so the target axis has real headroom.</li><li>all-MiniLM-L6-v2 — a <strong>similarity-tuned</strong> encoder that already nearly solves the task.</li></ul><p>And to test the linearity assumption directly, I compare the linear bilinear map against a small <strong>nonlinear MLP</strong> reranker trained on the same signal. You can find a demo code here: <a href="https://github.com/arashaneh/Intent_steering_demo">https://github.com/arashaneh/Intent_steering_demo</a></p><h3>Results</h3><p>All numbers: corpus = 5,000 frozen vectors, 1,000 test queries, rank 32, single seed, one CPU. (Reproduction scripts and JSON outputs are in the repo.)</p><h3>1. Does a linear query-side steer help?</h3><p>bilinear FOLD = learned S applied to the query, full-corpus MIPS, no re-indexing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NWmOum_KSp6may7L-kFtQA.png" /></figure><p>The headline: the linear steer helps <strong>exactly when the base encoder under-weights the axis</strong> (generic BERT) and hurts when there’s no headroom (tuned MiniLM, already near ceiling). That’s the central claim made concrete — and a useful caution: don’t steer a space that already prioritizes the axis you care about; a global map can only add noise there.</p><h3>2. Fold vs. rerank</h3><p>Same S, two deployment paths, on generic BERT:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twCHrjOSXkomxYqI1KVN_w.png" /></figure><p>Reranking the base top-100 beats the full-corpus fold. An aggressive fold can pull spurious far-away items into the top-k (the geometry of an ANN index built for the <em>original</em> metric doesn’t perfectly match the steered one). Reranking a base candidate set sidesteps that. Practical rule: either keep S gentle (stronger identity penalty) or over-retrieve before folding.</p><h3>3. Is linear enough? (linear vs. nonlinear)</h3><p>Both as rerankers of base top-100, nDCG@10:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sVZCIToGrUduWze3smrDQ.png" /></figure><p>On the generic encoder — the regime where steering actually helps — <strong>linear ≈ nonlinear</strong>. The intent structure is linearly accessible, vindicating the assumption right where it matters. The MLP only pulls ahead on the <em>tuned</em> encoder, where whatever structure remains in an already-optimized space is less linearly separable (or the linear map is simply over-fitting and wants more regularization).</p><h3>4. Where the gains live: hard negatives</h3><p>For each query, positive = nearest base item with the <em>same</em> label, hard negative = nearest base item with a <em>different</em> label. Accuracy = how often the method scores the positive above the confusable negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kU_YaDbrm6Jz-LTEZ4lLWw.png" /></figure><p>This is the cleanest signal. The steer’s value concentrates precisely on the <strong>hard, confusable intent pairs of the generic encoder</strong> (+7.7 points) — the cases the base encoder gets wrong because topic dominates its geometry. Everywhere the base already nails the axis, the steer is neutral-to-harmful.</p><h3>What it means, and how to use it</h3><p>The findings line up into a simple decision rule:</p><ol><li><strong>A linear, query-side bilinear steer measurably improves intent/domain retrieval — when, and only when, the base encoder under-prioritizes that axis.</strong> If you’re on a strong, similarity-tuned embedder that already separates your target axis, steering buys you little and can cost you. If you’re on a generic or general-purpose encoder (or your axis is something the encoder wasn’t optimized for — intent, stance, urgency, tone), there’s real headroom.</li><li><strong>In that regime, linear is enough.</strong> You don’t need a nonlinear reranker to capture intent; a rank-r matrix does it, and that matrix folds onto the query for free.</li><li><strong>The gains localize on the confusable cases</strong> — which is exactly where a retrieval system fails users.</li></ol><p>For a <strong>domain- or intent-specific RAG</strong> system, the pattern is:</p><ul><li>Offline, once: embed the corpus with your frozen model into a single index.</li><li>Offline, per intent/domain: mine same-label / different-label pairs (labels can come from an LLM annotating a small sample, the GSTransform-style step), train S = I + UVᵀ in seconds, store the two n×r factors.</li><li>Online: at query time, detect or route the intent (a classifier, a router, or the user’s explicit mode), fold the matching S onto the query, and search the same index. No re-encoding, no second index, negligible added latency.</li></ul><p>Two deployment variants, both validated above: apply the fold and do straight MIPS (cheapest, keep S gentle), or retrieve a base candidate set and rerank it with S (safest, sidesteps ANN-geometry mismatch).</p><p>For <strong>agentic retrieval</strong>, this is even more natural. Give the agent a small library of intent matrices and let it pick the lens as a tool call: “search the knowledge base <em>through the cancellation-intent lens</em>” becomes “apply S_cancel to the query, then retrieve.&quot; Because each lens is a tiny matrix over one shared index, an agent can compose, swap, or blend lenses cheaply mid-task — something you simply can&#39;t do if each intent requires its own re-encoded corpus.</p><h3>Limitations and next steps</h3><p>These are small-scale, single-seed, short-utterance results meant to demonstrate and measure the mechanism, not to claim SOTA. The most important caveats:</p><ul><li>CLINC’s two axes are <strong>nested, not orthogonal</strong>, so the dramatic “same query, totally different results” demo is muted. The natural next experiment is a <strong>topic × sentiment</strong> corpus (e.g. product reviews), where the axes genuinely conflict and a generic encoder is topic-dominated — the case where steering should shine.</li><li>A single global linear S can <strong>over-steer</strong> a space that already prioritizes the axis. Validation-based early stopping or a stronger identity prior would turn the harmful tuned-encoder cases into neutral ones.</li><li>Add <strong>multi-seed error bars</strong>, swap brute-force scoring for a <strong>real ANN index</strong>, and stress-test the fold-vs-rerank tradeoff at scale.</li></ul><p>The headline I’d actually stake, though, is the one the numbers support cleanly: <strong>you can bend a frozen embedding index toward a specific intent with nothing more than a small matrix on the query — and for intent-level structure, that matrix can be linear.</strong></p><p><em>Code, scripts, and the raw result JSONs are available in </em><a href="https://github.com/arashaneh/Intent_steering_demo">https://github.com/arashaneh/Intent_steering_demo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1da27a78e7e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>