{"id":16703,"date":"2026-07-09T00:00:00","date_gmt":"2026-07-09T07:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/ise\/?p=16703"},"modified":"2026-07-09T05:41:09","modified_gmt":"2026-07-09T12:41:09","slug":"from_noisy_queries_to_precise_frames","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/ise\/from_noisy_queries_to_precise_frames\/","title":{"rendered":"From Noisy Queries to Precise Frames: Query Decomposition for Media Asset Search"},"content":{"rendered":"<h2>Introduction: The Problem<\/h2>\n<p>Media and entertainment teams work with massive asset catalogs for films and TV series. Each asset often includes structured metadata such as episode ID, scene ID, and shot ID, along with the visual content itself. Teams want a unified search experience that understands both metadata constraints and natural language intent.<\/p>\n<p>The problem appears when users provide both types of information in one query, for example:<\/p>\n<pre><code>Two soldiers facing off across a battlefield in episode 20, scene 5, shot 2<\/code><\/pre>\n<p>If we embed this raw query directly for semantic retrieval, two issues appear:<\/p>\n<ol>\n<li>Metadata tokens dilute visual intent in the embedding representation.<\/li>\n<li>Retrieval can return visually similar assets from the wrong episode, scene, or shot.<\/li>\n<\/ol>\n<p>This gap is common in real workflows. Editors, archivists, and production teams often know part of the context, but they still describe the visual moment in natural language. Query decomposition solves this by splitting one noisy query into two useful parts: structured filters and semantic intent.<\/p>\n<h2>The Journey: Our Approach and Solution<\/h2>\n<p>In production, this works as a query pre-processing layer between user input and retrieval: the parser first identifies grounded metadata signals such as episode, scene, and shot, then removes those tokens to generate a clean sub-query that captures only the visual intent. The metadata fields are converted into strict filter clauses to narrow the candidate pool, while the sub-query is embedded for semantic ranking within that filtered set. This two-path retrieval flow prevents context drift, reduces false positives from adjacent scenes, and still preserves semantic flexibility when users describe actions, objects, or mood in free-form language.<\/p>\n<h3>Approach<\/h3>\n<p>Our approach decomposes each user query into:<\/p>\n<ol>\n<li>Structured filters: episode, scene, shot (and optionally characters)<\/li>\n<li>A clean sub-query: natural language description with metadata removed<\/li>\n<\/ol>\n<p>We then run hybrid retrieval:<\/p>\n<ol>\n<li>Apply filters as pre-conditions in metadata search.<\/li>\n<li>Use the sub-query for semantic or vector retrieval.<\/li>\n<li>Rank merged candidates with a hybrid strategy.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2026\/07\/overall-flow.webp\" alt=\"Overall query decomposition flow\" \/><\/p>\n<p>At a high level, the decomposition pipeline follows three steps:<\/p>\n<ol>\n<li>Parse query text with any one of the approaches, i.e. Regex or LLM or fine-tuned Entity extraction.<\/li>\n<li>Extract explicit metadata fields.<\/li>\n<li>Rewrite the residual visual intent as a sub-query.<\/li>\n<\/ol>\n<p>This design improves precision through filtering and improves recall through semantic matching.<\/p>\n<h3>Data available<\/h3>\n<p>For this use case, we evaluated approximately 500 user queries with mixed structure:<\/p>\n<ol>\n<li>Queries with full contextual metadata (episode, scene, and shot)<\/li>\n<li>Queries with partial contextual metadata<\/li>\n<li>Queries with no explicit contextual metadata<\/li>\n<\/ol>\n<h3>Ground-truth template<\/h3>\n<p>Domain experts labeled the 500 query set using this template:<\/p>\n<table>\n<thead>\n<tr>\n<th>Query<\/th>\n<th>Shot-id<\/th>\n<th>Scene-id<\/th>\n<th>Episode-id<\/th>\n<th>Sub-query<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>User input query<\/td>\n<td>Extracted shot value<\/td>\n<td>Extracted scene value<\/td>\n<td>Extracted episode value<\/td>\n<td>Metadata-free semantic query<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Sample Queries<\/h3>\n<table>\n<thead>\n<tr>\n<th>Query<\/th>\n<th>Episode ID<\/th>\n<th>Scene ID<\/th>\n<th>Shot ID<\/th>\n<th>Sub-query<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Two astronauts repairing a satellite in episode 4 scene 3 shot 11<\/td>\n<td>4<\/td>\n<td>3<\/td>\n<td>11<\/td>\n<td>Two astronauts repairing a satellite<\/td>\n<\/tr>\n<tr>\n<td>A chef plating dessert in scene 9 shot 2<\/td>\n<td>N\/A<\/td>\n<td>9<\/td>\n<td>2<\/td>\n<td>A chef plating dessert<\/td>\n<\/tr>\n<tr>\n<td>Crowd celebrating at a city marathon finish line<\/td>\n<td>N\/A<\/td>\n<td>N\/A<\/td>\n<td>N\/A<\/td>\n<td>Crowd celebrating at a city marathon finish line<\/td>\n<\/tr>\n<tr>\n<td>Detective opening an old letter in episode 2<\/td>\n<td>2<\/td>\n<td>N\/A<\/td>\n<td>N\/A<\/td>\n<td>Detective opening an old letter<\/td>\n<\/tr>\n<tr>\n<td>Family watching fireworks by a river at night<\/td>\n<td>N\/A<\/td>\n<td>N\/A<\/td>\n<td>N\/A<\/td>\n<td>Family watching fireworks by a river at night<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Experiments &amp; Evaluation<\/h2>\n<h3><code>Regex<\/code> vs <code>LLM<\/code> vs <code>Fine-Tuned Entity Extraction<\/code><\/h3>\n<p>Each extraction approach comes with different trade-offs depending on your query patterns, budget, and maintainability needs:<\/p>\n<table>\n<thead>\n<tr>\n<th>Criterion<\/th>\n<th>Regex<\/th>\n<th>LLM (GPT-4.1-mini \/ GPT-4.1)<\/th>\n<th>Fine-tuned Entity Extraction<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Latency<\/td>\n<td>Zero &#8211; no network call<\/td>\n<td>4\u20135 seconds per query<\/td>\n<td>Near-zero after deployment<\/td>\n<\/tr>\n<tr>\n<td>Cost<\/td>\n<td>Free<\/td>\n<td>Per-token API cost<\/td>\n<td>One-time training + hosting cost<\/td>\n<\/tr>\n<tr>\n<td>Sub-query rewriting<\/td>\n<td>Manual \/ rule-based<\/td>\n<td>Natural and fluent<\/td>\n<td>Manual \/ rule-based &#8211; entity extraction only<\/td>\n<\/tr>\n<tr>\n<td>Typo &amp; variation tolerance<\/td>\n<td>Low &#8211; brittle on irregular input<\/td>\n<td>High &#8211; generalises across phrasing<\/td>\n<td>Medium &#8211; bounded by training distribution<\/td>\n<\/tr>\n<tr>\n<td>Extensibility to new fields<\/td>\n<td>Requires new rules per field<\/td>\n<td>Prompt update only<\/td>\n<td>Requires re-training or fine-tuning<\/td>\n<\/tr>\n<tr>\n<td>Operational complexity<\/td>\n<td>Very low<\/td>\n<td>Low (API)<\/td>\n<td>High &#8211; model lifecycle, infra, versioning<\/td>\n<\/tr>\n<tr>\n<td>Best suited for<\/td>\n<td>Consistent, well-structured input<\/td>\n<td>Mixed or ambiguous input<\/td>\n<td>High-volume production with domain shift<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Experiment Setup and Variants<\/h3>\n<p>We tested four decomposition modes:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/ise\/wp-content\/uploads\/sites\/55\/2026\/07\/experiments.webp\" alt=\"Experiment setup and variants\" \/><\/p>\n<h3>Evaluation<\/h3>\n<p>We evaluated decomposition quality and retrieval impact using three metric groups:<\/p>\n<ol>\n<li>Filter extraction accuracy: exact match for episode, scene, and shot<\/li>\n<li>Sub-query quality: ROUGE-L and BLEU against labeled rewrites<\/li>\n<li>Retrieval effectiveness: Recall@K (K=5)<\/li>\n<\/ol>\n<h2>The Destination: Outcomes and Learnings<\/h2>\n<h3>Decomposition Quality<\/h3>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Episode match<\/th>\n<th>Scene match<\/th>\n<th>Shot match<\/th>\n<th>ROUGE-L<\/th>\n<th>BLEU<\/th>\n<th>Latency<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>GPT-4.1 (zero-shot)<\/td>\n<td>100%<\/td>\n<td>99.7%<\/td>\n<td>100%<\/td>\n<td>1.00<\/td>\n<td>0.86<\/td>\n<td>5s<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1-mini (zero-shot)<\/td>\n<td>100%<\/td>\n<td>99.7%<\/td>\n<td>100%<\/td>\n<td>1.00<\/td>\n<td>0.85<\/td>\n<td>4s<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1 (few-shot)<\/td>\n<td>100%<\/td>\n<td>100%<\/td>\n<td>100%<\/td>\n<td>1.00<\/td>\n<td>0.86<\/td>\n<td>5s<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1-mini (few-shot)<\/td>\n<td>100%<\/td>\n<td>100%<\/td>\n<td>100%<\/td>\n<td>1.00<\/td>\n<td>0.85<\/td>\n<td>4s<\/td>\n<\/tr>\n<tr>\n<td>Regex<\/td>\n<td>100%<\/td>\n<td>100%<\/td>\n<td>100%<\/td>\n<td>0.97<\/td>\n<td>0.79<\/td>\n<td>0s<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Token Consumption<\/h3>\n<table>\n<thead>\n<tr>\n<th>Variant<\/th>\n<th>Avg input tokens<\/th>\n<th>Avg output tokens<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Regex<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>zero-shot<\/td>\n<td>700<\/td>\n<td>35<\/td>\n<\/tr>\n<tr>\n<td>few-shot<\/td>\n<td>1053<\/td>\n<td>35<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Retrieval Effectiveness (Recall@K, K=5)<\/h3>\n<ol>\n<li>Query-only baseline: about 27%<\/li>\n<li>Sub-query only: about 31.8% to 32.2%<\/li>\n<li>Filters + sub-query: best overall, up to 49.4%<\/li>\n<\/ol>\n<p><strong>Detailed highlights:<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Query only<\/th>\n<th>Sub-query only<\/th>\n<th>Filters + sub-query<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Regex<\/td>\n<td>27%<\/td>\n<td>32.2%<\/td>\n<td>49.4%<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1-mini (zero-shot)<\/td>\n<td>27%<\/td>\n<td>32.2%<\/td>\n<td>46.2%<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1-mini (few-shot)<\/td>\n<td>27%<\/td>\n<td>31.8%<\/td>\n<td>49%<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1 (zero-shot)<\/td>\n<td>27%<\/td>\n<td>31.8%<\/td>\n<td>43.6%<\/td>\n<\/tr>\n<tr>\n<td>GPT-4.1 (few-shot)<\/td>\n<td>27%<\/td>\n<td>31.8%<\/td>\n<td>49%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Key observations<\/h3>\n<ol>\n<li>Few-shot closed the Scene ID gap seen in zero-shot.<\/li>\n<li>Regex matched or exceeded LLM quality for structural extraction.<\/li>\n<li>Filters plus semantic sub-query produced the strongest retrieval outcome.<\/li>\n<\/ol>\n<h3>Why and When to Use an LLM<\/h3>\n<p>Regex is the best choice when queries are structured and format patterns are stable.<\/p>\n<p>LLMs become valuable when you need:<\/p>\n<ol>\n<li>Robust sub-query rewriting for semantic search quality<\/li>\n<li>Tolerance for typos and natural phrasing variations<\/li>\n<li>Extensibility to future fields such as character names or location entities<\/li>\n<\/ol>\n<p>A practical strategy is to use Regex first, then invoke an LLM fallback (say, GPT-4.1-mini) for edge cases that fail rule coverage.<\/p>\n<h3>Edge-Case Comparison: Where LLM Wins and Where Regex Leads<\/h3>\n<p>The examples below show why a hybrid strategy works best in production. LLM-based decomposition excelled at preserving natural phrasing and correctly separating metadata from intent in ambiguous patterns, while Regex remained strongest on speed, determinism, and zero-cost extraction for stable formats.<\/p>\n<table>\n<thead>\n<tr>\n<th>Query<\/th>\n<th>Ideal output<\/th>\n<th>Regex output<\/th>\n<th>LLM output<\/th>\n<th>What this shows<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Scene 3 A frontal pose of warriors with a hill background<\/td>\n<td>&#8211; scene: 3\n&#8211; sub-query: A frontal pose of warriors with a hill background<\/td>\n<td>&#8211; scene: 3A\n&#8211; sub-query: frontal pose of warriors with a hill background<\/td>\n<td>&#8211; scene: 3\n&#8211; sub-query: A frontal pose of warriors with a hill background<\/td>\n<td>LLM handled boundary ambiguity better by keeping <code>3<\/code> as scene and preserving the complete semantic phrase.<\/td>\n<\/tr>\n<tr>\n<td>Frontal Profile of Spiderman and Superman in scene 10A<\/td>\n<td>&#8211; scene: 10A\n&#8211; sub-query: Frontal Profile of Spiderman and Superman<\/td>\n<td>&#8211; scene: 10A\n&#8211; sub-query: Frontal Profile of Spiderman and Superman in<\/td>\n<td>&#8211; scene: 10A\n&#8211; sub-query: Frontal Profile of Spiderman and Superman<\/td>\n<td>LLM produced cleaner rewrite quality by removing trailing connector tokens after metadata extraction.<\/td>\n<\/tr>\n<tr>\n<td>A wide shot of cyclists crossing a bridge in scnee 12<\/td>\n<td>&#8211; scene: 12\n&#8211; sub-query: A wide shot of cyclists crossing a bridge<\/td>\n<td>&#8211; scene: N\/A\n&#8211; sub-query: A wide shot of cyclists crossing a bridge in scnee 12<\/td>\n<td>&#8211; scene: 12\n&#8211; sub-query: A wide shot of cyclists crossing a bridge<\/td>\n<td>LLM tolerated the typo in <code>scene<\/code> and still extracted the correct filter, while Regex missed the malformed token pattern.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<thead>\n<tr>\n<th>Regex strengths<\/th>\n<th>LLM strengths<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Deterministic behavior for known templates<\/td>\n<td>Better handling of ambiguous token boundaries<\/td>\n<\/tr>\n<tr>\n<td>Zero latency and zero token cost<\/td>\n<td>More fluent sub-query rewriting<\/td>\n<\/tr>\n<tr>\n<td>Easier debugging for rule failures<\/td>\n<td>Better resilience to natural phrasing variation<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Conclusion<\/h2>\n<p>Query decomposition is not an optional optimization for media asset retrieval. It is a foundational step when user queries mix contextual metadata with free-form visual descriptions.<\/p>\n<p>Our evaluation shows that separating metadata filters from semantic intent nearly doubles retrieval performance versus raw semantic search alone, moving the Recall@K (K=5) from 27% to around 49%.<\/p>\n<p>For this use case, Regex is the preferred default because it delivers perfect structural extraction with zero latency and zero token cost. When coverage needs to expand to more ambiguous input styles, GPT-4.1-mini with prompt v2 provides the best cost-to-quality fallback.<\/p>\n<h2>Thanks<\/h2>\n<p>A special thanks to <a href=\"https:\/\/www.linkedin.com\/in\/krammai\">Mark D&#8217;Souza<\/a>, <a href=\"https:\/\/www.linkedin.com\/in\/prabaldeb\">Prabal Deb<\/a>, <a href=\"https:\/\/www.linkedin.com\/in\/preethi-natarajan-\">Preethi Natarajan<\/a>, <a href=\"https:\/\/www.linkedin.com\/in\/bhimjyani\">Priya Bhimjyani<\/a> for their valuable input.<\/p>\n<blockquote><p>The featured image was generated using Copilot. Terms can be found <a href=\"https:\/\/www.microsoft.com\/en-in\/microsoft-copilot\/for-individuals\/termsofuse\">here<\/a>.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>How query decomposition separates metadata filters from visual intent to significantly improve media asset retrieval quality.<\/p>\n","protected":false},"author":193956,"featured_media":16704,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,1,17,19],"tags":[3400],"class_list":["post-16703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cognitive-services","category-cse","category-frameworks","category-machine-learning","tag-ise"],"acf":[],"blog_post_summary":"<p>How query decomposition separates metadata filters from visual intent to significantly improve media asset retrieval quality.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/16703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/users\/193956"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/comments?post=16703"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/16703\/revisions"}],"predecessor-version":[{"id":16705,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/16703\/revisions\/16705"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media\/16704"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media?parent=16703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/categories?post=16703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/tags?post=16703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}