Instructions to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="krogoldAI/QueryRefiner-0.5B-v0.1-SFT") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("krogoldAI/QueryRefiner-0.5B-v0.1-SFT") model = AutoModelForCausalLM.from_pretrained("krogoldAI/QueryRefiner-0.5B-v0.1-SFT", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "krogoldAI/QueryRefiner-0.5B-v0.1-SFT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krogoldAI/QueryRefiner-0.5B-v0.1-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/krogoldAI/QueryRefiner-0.5B-v0.1-SFT
- SGLang
How to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "krogoldAI/QueryRefiner-0.5B-v0.1-SFT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krogoldAI/QueryRefiner-0.5B-v0.1-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "krogoldAI/QueryRefiner-0.5B-v0.1-SFT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krogoldAI/QueryRefiner-0.5B-v0.1-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT with Docker Model Runner:
docker model run hf.co/krogoldAI/QueryRefiner-0.5B-v0.1-SFT
File size: 23,125 Bytes
243fb73 fe49aa0 b98c504 fe49aa0 76ec1ba 243fb73 fff158e 243fb73 52fc69a 8cdbf1e 73b70fd 243fb73 304cfd0 98bbd83 650c607 243fb73 f370b7b 97418f5 60b76d7 7850463 60b76d7 7850463 60b76d7 7850463 60b76d7 7850463 60b76d7 0aa68f8 7850463 0aa68f8 60b76d7 7850463 60b76d7 60f9e71 7850463 5ffee93 7850463 5ffee93 7850463 5ffee93 7850463 5ffee93 7850463 5ffee93 7850463 5ffee93 7850463 60f9e71 a35d52d 7850463 a35d52d 7850463 a35d52d 7850463 a35d52d 7850463 a35d52d 7850463 a35d52d 0a0924c 60b76d7 73b70fd 243fb73 9fb6e6c 243fb73 73b70fd 243fb73 73b70fd 243fb73 1d68c82 9fb6e6c bb68da4 9fb6e6c 243fb73 73b70fd 243fb73 73b70fd 243fb73 babedc5 243fb73 a91850a 73b70fd 243fb73 b2ea036 243fb73 f020f55 243fb73 810290b 460006b 73b70fd 243fb73 304cfd0 243fb73 73b70fd 243fb73 73b70fd 243fb73 30bf6a5 73b70fd 243fb73 981b7e5 73b70fd 243fb73 73b70fd 243fb73 73b70fd 30bf6a5 73b70fd 243fb73 73b70fd 243fb73 794d193 73b70fd 243fb73 73b70fd 243fb73 b1235a9 650c607 b1235a9 650c607 b1235a9 310f17c b1235a9 8100c94 b1235a9 650c607 b1235a9 a91019d b1235a9 61090c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | ---
library_name: transformers
datasets:
- krogoldAI/rag-query-analysis
language:
- en
base_model:
- Qwen/Qwen2.5-0.5B-Instruct
license: apache-2.0
---
# QueryRefiner-0.5B-v0.1-SFT

<!-- RAG Query Analyzer 0.5B v0.1 -->
## Model Description
QueryRefiner-0.5B-v0.1-SFT is a specialized query analysis and rephrasing model fine-tuned from [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) for Retrieval-Augmented Generation (RAG) systems. The model has been trained to analyze user queries through a structured, ontology-inspired reasoning framework that produces XML outputs with domain classification, intent detection, conceptual analysis, and optimized query reformulations designed to improve document retrieval precision.
This model is part of a two-model series addressing a critical challenge in RAG systems: converting ambiguous, vague, or suboptimally-phrased user queries into retrieval-friendly formats through systematic decomposition and analysis. By employing a structured reasoning approach that explicitly identifies domains, intents, concepts, and relationships, the model produces higher-quality rephrasings informed by comprehensive query understanding. <!-- Rather than directly answering questions, the model performs query understanding and transformation, making it an ideal preprocessing component for information retrieval pipelines. -->
**Note:** This model is currently in an experimental, beta stage. It represents an initial release focused on establishing baseline capabilities. Future iterations may address current limitations, expand domain coverage, or incorporate additional output features based on real-world deployment feedback.
## Examples
<details>
<summary><i>Unroll to see Example #1</i></summary>
User query:
>How can artificial intelligence be utilized to improve emergency response systems in urban environments?
Model output:
```xml
<query_analysis>
<domain ambiguous="false">
<candidate confidence="1.0">Technology</candidate>
</domain>
<intent ambiguous="false">
<candidate confidence="1.0">Improving emergency response systems</candidate>
</intent>
<concepts>
<explicit>artificial intelligence, emergency response systems, urban environments</explicit>
<implicit>smart city, predictive analytics, data-driven decision making</implicit>
</concepts>
<relations>
<relation subject="artificial intelligence" predicate="utilized to" object="improve emergency response systems"/>
<relation subject="emergency response systems" predicate="in" object="urban environments"/>
</relations>
<insufficient_context>false</insufficient_context>
<rephrased>true</rephrased>
<rephrased_query>how artificial intelligence can be used to enhance emergency response capabilities in urban areas</rephrased_query>
</query_analysis>
```
</details>
<details>
<summary><i>Unroll to see Example #2</i></summary>
User query:
>How have its fiscal policies regarding these things impacted its overall financial stability and future outlook, particularly concerning external market fluctuations?
Model output:
```xml
<query_analysis>
<domain ambiguous="true">
<candidate confidence="0.6">Economics</candidate>
<candidate confidence="0.4">Finance</candidate>
</domain>
<intent ambiguous="true">
<candidate confidence="0.7">Analysis</candidate>
<candidate confidence="0.3">Comparison</candidate>
</intent>
<concepts>
<explicit>fiscal policies, external market fluctuations, financial stability, future outlook</explicit>
<implicit>[ENTITY], economic factors</implicit>
</concepts>
<relations>
<relation subject="[ENTITY]" predicate="has" object="fiscal policies"/>
<relation subject="[ENTITY]" predicate="impacts" object="financial stability"/>
<relation subject="[ENTITY]" predicate="impacts" object="future outlook"/>
<relation subject="[ENTITY]" predicate="causes" object="external market fluctuations"/>
</relations>
<insufficient_context>false</insufficient_context>
<rephrased>true</rephrased>
<rephrased_query>impact of [ENTITY]'s fiscal policies on financial stability and future outlook, particularly due to external market volatility</rephrased_query>
</query_analysis>
```
</details>
<details>
<summary><i>Unroll to see Example #3</i></summary>
User query:
>How does she describe her emotional journey and the complexities of her interactions with him in that book?
Model output:
```xml
<query_analysis>
<domain ambiguous="true">
<candidate confidence="0.5">Literature</candidate>
<candidate confidence="0.5">Psychology</candidate>
</domain>
<intent ambiguous="true">
<candidate confidence="0.6">Analysis</candidate>
<candidate confidence="0.4">Description</candidate>
</intent>
<concepts>
<explicit>emotional journey, complex interactions</explicit>
<implicit>[PERSON], [BOOK]</implicit>
</concepts>
<relations>
<relation subject="[PERSON]" predicate="describes" object="complex emotions"/>
<relation subject="[PERSON]" predicate="interacts with" object="him"/>
</relations>
<insufficient_context>true</insufficient_context>
<rephrased>true</rephrased>
<rephrased_query>How does [PERSON] describe their emotional journey and the intricacies of their interactions with [PERSON] in the book?</rephrased_query>
</query_analysis>
```
</details>
## Intended Use
The model is designed to serve as a query analysis layer in RAG systems, where it processes user inputs before they are sent to retrieval components. It can handle queries with varying degrees of ambiguity and identify when queries lack sufficient context for effective retrieval. The structured XML output enables downstream systems to make informed decisions about how to handle each query based on confidence scores, ambiguity flags, and the rephrased version.
Typical deployment scenarios include conversational search systems, question-answering platforms, document retrieval services, and any application where understanding user intent and optimizing queries for semantic search is critical. The model's compact 0.5B parameter size makes it suitable for deployment in resource-constrained environments or as part of larger multi-component systems where latency is a concern.
## Training Data
The model was trained on the [krogoldAI/rag-query-analysis](https://huggingface.co/datasets/krogoldAI/rag-query-analysis) dataset, which contains 7,305 high-quality query-analysis pairs. This dataset contains queries carefully curated from three sources:
- [rag-datasets/rag-mini-wikipedia](https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia)
- [razbit96/Ambiguity-Handling-in-User-Queries](https://huggingface.co/datasets/razbit96/Ambiguity-Handling-in-User-Queries)
- [glaiveai/RAG-v1](https://huggingface.co/datasets/glaiveai/RAG-v1).
Approximately 20% of the training examples include queries with systematically introduced ambiguity at varying levels to ensure the model can handle realistic user inputs across the ambiguity spectrum.
The training data underwent rigorous quality assurance through a dual evaluation framework. Each example was validated for strict XML schema conformance and semantically evaluated using an LLM-as-a-judge protocol with six quality dimensions. Only examples achieving both perfect structural validity and high semantic quality scores were included in the final dataset, ensuring the model was trained exclusively on gold-standard examples.
## Training Procedure
The model underwent full fine-tuning (not parameter-efficient methods like LoRA) of all parameters in [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct). Training was conducted over three epochs with a per-device batch size of 4 and gradient accumulation over 4 steps, yielding an effective batch size of 16. The learning rate was set to 2e-5 with a weight decay of 0.01 to prevent overfitting. Training was performed on an NVIDIA A100 SXM GPU.
The training code can be found [here](Code/Fine-tuning.py).
## Model Capabilities
The model employs a systematic, ontology-inspired analysis framework that decomposes queries into structured XML representations. This analytical approach (which identifies domains, intents, concepts, relations, and ambiguities) aims to enhance the quality of the rephrased query output. For every query, it provides domain classification and intent detection with confidence scores that sum to `1.0`, properly handling both unambiguous cases (single candidate with confidence `1.0`) and ambiguous cases (multiple candidates with distributed confidence). The model can optionally extract explicit and implicit concepts, identify relations between entities using subject-predicate-object triples, and normalize ambiguous terms when disambiguation would improve retrieval.
The rephrasing capability focuses on retrieval optimization rather than query answering. The model transforms queries by using specific terminology likely to appear in relevant documents, expanding acronyms when contextually appropriate, adding disambiguating context, and making implicit references explicit through placeholder notation such as `[PERSON]` or `[COMPANY]`. Importantly, the model has learned to preserve already-optimal queries unchanged, recognizing when rephrasing would not improve retrieval effectiveness.
This structured analytical framework ensures that rephrasings are informed by comprehensive query understanding rather than surface-level transformations, leading to more semantically precise retrieval-optimized queries.
The default output schema is the following:
```xml
<query_analysis>
<domain ambiguous="true|false">
<candidate confidence="X.X">...</candidate>
</domain>
<intent ambiguous="true|false">
<candidate confidence="X.X">...</candidate>
</intent>
<!-- Optional sections -->
<concepts>
<explicit>...</explicit>
<implicit>...</implicit>
</concepts>
<relations>
<relation subject="..." predicate="..." object="..."/>
</relations>
<normalized_terms>
<term original="..." normalized="..."/>
</normalized_terms>
<!-- End optional sections -->
<insufficient_context>true|false</insufficient_context>
<rephrased>true|false</rephrased>
<rephrased_query>...</rephrased_query>
</query_analysis>
```
## Limitations and Considerations
As a 0.5B parameter model, QueryRefiner-0.5B-v0.1-SFT prioritizes efficiency and deployability over the capabilities of larger language models. While it performs well on the types of queries represented in its training distribution, performance may degrade on highly specialized domains, multilingual queries, or query types significantly different from the training examples. The model focuses exclusively on English-language queries and has been optimized for the specific XML output format defined in its training.
The model's ambiguity detection and confidence scoring reflect patterns learned from the training data, which includes both natural and synthetically augmented ambiguous queries. While the training process incorporated diverse ambiguity levels, edge cases or novel forms of ambiguity may not be handled with the same reliability as more common patterns. Users should consider the model's confidence scores as informative signals rather than calibrated probabilities.
## Usage Example
First, make sure you have the latest version of `transformers`:
```shell
pip install git+https://github.com/huggingface/transformers.git
```
Define the system prompt (since it was used as such during training, for optimal results we recommend not changing it).
<details>
<summary><i>Unroll to see the system prompt</i></summary>
```python
SYSTEM_PROMPT = """You are a query analysis and rephraser for a Retrieval-Augmented Generation (RAG) system.
Your sole task is to **analyze user queries** and output a structured XML document.
You must **not answer the query itself**, only analyze and rephrase it.
## RAG Query Optimization
Effective rephrasing should optimize for document retrieval by:
- Using **specific terminology** and domain vocabulary likely to appear in relevant documents
- **Expanding acronyms** when they add context (but not when the acronym itself is the subject)
- **Adding disambiguating context** without over-constraining the search
- **Making implicit references explicit** using placeholders for missing entities (e.g., [PERSON], [COMPANY])
- **Preserving user intent** while improving retrieval precision
Examples: "How do I reset my password?" → "password reset procedure authentication"
"What's their revenue?" → "What's [COMPANY]'s revenue?"
## Analysis Process
Follow this systematic approach to decompose each query:
1. **Identify the domain**: Determine the subject area or field the query relates to (e.g., banking, healthcare, technology, legal). Consider both explicit domain indicators and contextual clues.
2. **Determine the intent**: Classify what the user is trying to accomplish (e.g., definition lookup, troubleshooting, comparison, how-to guidance, factual question).
3. **Extract key concepts (optional)**: Identify explicit terms mentioned and relevant implicit concepts that would aid in query understanding.
4. **Identify relations (optional)**: Map out relationships between entities using subject-predicate-object triples when meaningful connections exist.
5. **Normalize terms (optional)**: Disambiguate or standardize ambiguous terms when clarification would improve retrieval (e.g., "Apple" → "Apple Inc." vs "apple fruit").
6. **Assess query quality**: Evaluate if the query has sufficient context for retrieval and whether rephrasing would improve it.
7. **Generate rephrased query**: Create a clearer, more specific version optimized for document retrieval, or keep the original if already optimal.
## Technical Rules
1. **Never answer the user's question.** Only analyze and rephrase.
2. Always produce valid XML strictly following the schema below.
3. `<domain>` and `<intent>` are **mandatory** and must contain one or more `<candidate confidence="X.X">...</candidate>` entries:
- Confidence scores must always sum to 1.0
- If unambiguous: **exactly one candidate** with `confidence="1.0"` and `ambiguous="false"`
- If ambiguous: multiple candidates with `ambiguous="true"` and confidence distributed proportionally to plausibility:
- Use uniform distribution only when candidates are genuinely equally likely
- Otherwise, weight confidence toward the more probable interpretation
- Examples:
- "What is Mercury's rotation period?" → Astronomy 0.5, Chemistry 0.5 (equally plausible)
- "Jaguar speed in the wild" → Zoology 0.8, Automotive 0.2 (context favors animal)
4. Confidence values must always have one decimal place (e.g., `0.5`, `1.0`).
5. Only `<concepts>`, `<relations>`, and `<normalized_terms>` are optional. **All other elements are mandatory.**
6. `<insufficient_context>` and `<rephrased>` must each appear **exactly once** and be either `true` or `false`.
7. `<rephrased_query>` must always appear, even if identical to the input.
8. **Output only valid XML.** Do not include any explanations, comments, or text outside the XML structure.
9. All elements must appear in the order specified in the schema:
`<domain> → <intent> → <concepts> → <relations> → <normalized_terms> → <insufficient_context> → <rephrased> → <rephrased_query>`.
## Output Schema
```xml
<query_analysis>
<domain ambiguous="true|false">
<candidate confidence="X.X">...</candidate>
</domain>
<intent ambiguous="true|false">
<candidate confidence="X.X">...</candidate>
</intent>
<!-- Optional sections -->
<concepts>
<explicit>...</explicit>
<implicit>...</implicit>
</concepts>
<relations>
<relation subject="..." predicate="..." object="..."/>
</relations>
<normalized_terms>
<term original="..." normalized="..."/>
</normalized_terms>
<!-- End optional sections -->
<insufficient_context>true|false</insufficient_context>
<rephrased>true|false</rephrased>
<rephrased_query>...</rephrased_query>
</query_analysis>
```"""
```
</details>
Then, use the code below to get started with the model.
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "krogoldAI/QueryRefiner-0.5B-v0.1-SFT"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
user_query = "How do I reset my password?"
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_query}
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, temperature=0.7, max_new_tokens=512)
analysis = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(analysis)
```
## Evaluation and Performance
### Structural Validation
To assess the model's ability to produce correctly formatted outputs, we evaluated structural conformance across 1,000 examples from the test split of [krogoldAI/rag-ambiguous-queries](https://huggingface.co/datasets/krogoldAI/rag-ambiguous-queries), comparing both QueryRefiner-0.5B-v0.1 models against their base model [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct). The evaluation measured adherence to the required XML schema, including tag presence, well-formedness, element ordering, and confidence score formatting.
#### Table 1 - Structural validity metrics (% of outputs meeting each requirement)
|Metric|Qwen2.5-0.5B-Instruct|QueryRefiner-0.5B-v0.1-SFT|QueryRefiner-0.5B-v0.1-GRPO|
|----:|:-------------------:|:--------------------:|:--------------------:|
|Tag structure|10.8%|99.9%|99.9%|
|XML validity|41.0%|99.8%|99.9%|
|Order|2.0%|99.9%|99.9%|
|Confidence|3.1%|99.9%|99.9%|
|Perfectly structured output|0.0%|99.8%|99.9%|
Here, *tag structure* verifies that all required XML tags are present, *XML validity* ensures the output is well-formed and parseable, *order* confirms that required tags appear in the correct sequence, and *confidence* validates that confidence values are properly formatted and sum to `1.0`.
### Semantic Validation
Beyond structural correctness, we evaluated the semantic quality of the model's outputs using an LLM-as-a-judge protocol with GPT5 on 1,000 examples from the test split of [krogoldAI/rag-ambiguous-queries](https://huggingface.co/datasets/krogoldAI/rag-ambiguous-queries). Each output was assessed across six dimensions aligned with the model's core objectives.
#### Table 2 - Semantic scores
|Metric|QueryRefiner-0.5B-v0.1-SFT|QueryRefiner-0.5B-v0.1-GRPO|
|----:|:--------------------:|:--------------------:|
|Domain accuracy|**98.97 ± 8.43%**|98.95 ± 8.46%|
|Intent accuracy|98.20 ± 8.84%|**98.75 ± 8.05%**|
|Ambiguity assessment|99.04 ± 6.84%|**99.40 ± 5.79%**|
|Rephrasing quality|88.23 ± 18.20%|**90.33 ± 17.61%**|
|Intent preservation|95.09 ± 15.74%|**96.02 ± 14.72%**|
|Follows guidelines|97.07 ± 13.78%|**97.40 ± 12.20%**|
|Overall semantic score|96.10 ± 9.74%|**96.81 ± 9.18%**|
All values are reported as mean ± standard deviation (%), computed over test examples. The base model produced too few valid XML samples for meaningful semantic evaluation.
<details>
<summary><i>Unroll to see the system prompt used for the "judge" LLM</i></summary>
```py
JUDGE_PROMPT = """You are evaluating query analyses for a RAG system.
### System Requirements
The analyzer was instructed to optimize queries for document retrieval by:
- Using **specific terminology** and domain vocabulary likely to appear in relevant documents
- **Expanding acronyms** when they add context (but not when the acronym itself is the subject)
- **Adding disambiguating context** without over-constraining the search
- **Making implicit references explicit** using placeholders for missing entities (e.g., [PERSON], [COMPANY])
- **Preserving user intent** while improving retrieval precision
- **Keeping the original query unchanged** if it's already well-optimized for retrieval
### Input
Original: "{original}"
Domain: {domain}
Intent: {intent}
Rephrased: "{rephrased}"
Note: The [ambiguous] tag indicates the analyzer determined the query has multiple plausible interpretations for that dimension, with confidence distributed across candidates.
### Evaluation Criteria (1-5 scale)
1. Domain Accuracy (1=wrong, 3=acceptable, 5=perfect)
- Are the domain candidates correct?
- Are confidence scores reasonable?
2. Intent Accuracy (1=wrong, 3=acceptable, 5=perfect)
- Are the intent candidates correct?
- Are confidence scores reasonable?
3. Ambiguity Assessment (1=wrong, 3=acceptable, 5=perfect)
- Is the ambiguity determination appropriate for this query?
- If ambiguous: Is the confidence distribution justified?
- If clearly unambiguous but marked ambiguous (or vice versa), score ≤2.
4. Rephrasing Quality
1 = Poor (significantly degraded the query, or completely failed to address clear issues)
2 = Suboptimal (minor degradation, or missed an obvious improvement opportunity)
3 = Neutral (minor changes with mixed effects)
4 = Good improvement, but could be better
5 = Optimal outcome (either improved a suboptimal query, or correctly preserved an already-optimal one)
(Note: Do not penalize rephrasing for being minimal if the original was already optimal.)
5. Intent Preservation (1=lost, 3=mostly preserved, 5=fully preserved)
- Focus on meaning fidelity, not retrieval optimization.
6. Follows Guidelines (1=violates, 3=mostly follows, 5=perfectly follows)
- Check adherence to the RAG optimization principles above.
### Output Format
{{
"domain_accuracy": <1-5>,
"intent_accuracy": <1-5>,
"ambiguity_assessment": <1-5>,
"rephrasing_quality": <1-5>,
"intent_preservation": <1-5>,
"follows_guidelines": <1-5>,
"critical_issue": "<brief description or null>",
"usable": <true/false> // true if suitable for RAG use, even if not perfect
}}
Output only valid JSON. Do not include any explanations, comments, or text outside the JSON structure.
"""
```
</details>
### Performance Considerations
Performance characteristics will vary based on query type, domain, and ambiguity level. The model is expected to perform strongest on queries similar to those in the training distribution and may require additional fine-tuning or prompt engineering for specialized applications or domains underrepresented in the training data.
## Acknowledgments
This model builds upon [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) by the Qwen team at Alibaba Cloud. The training data incorporates queries from [rag-datasets/rag-mini-wikipedia](https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia), [razbit96/Ambiguity-Handling-in-User-Queries](https://huggingface.co/datasets/razbit96/Ambiguity-Handling-in-User-Queries), and [glaiveai/RAG-v1](https://huggingface.co/datasets/glaiveai/RAG-v1). |