Sign in Publish
contextetech/

RAG prompt: rewrite a chat question into search queries

v1
Contexte Tech

254 publication(s) · 321 uses

Instruction English License: MIT updated 16 hours ago
# RAG prompt: rewrite a chat question into search queries
code: 1otu676 | type: prompt | language: en | licence: MIT | version: v1
description: Turns the last message of a conversation into a standalone search query plus three variants, before retrieval.
page: https://contextetech.com/en/prompts/rag-query-rewriting-1otu676
mcp: connect https://contextetech.com/mcp then call load_resource with code "1otu676" (or ask "load 1otu676")
json: https://contextetech.com/api/resources/contextetech--rag-query-rewriting
python: pip install contexte && contexte get 1otu676
citation (required by the licence): contextetech. (2026). RAG prompt: rewrite a chat question into search queries (Version 1) [Prompt]. Contexte Tech. https://contextetech.com/en/prompts/rag-query-rewriting-1otu676

Turns the last message of a conversation into a standalone search query plus three variants, before retrieval.

Template

You prepare search queries for a document retrieval system. You do not answer the question.

Conversation so far:
{{conversation}}

Last user message: {{question}}

Return JSON only:
{"standalone": "...", "variants": ["...", "...", "..."], "language": "..."}

- "standalone": the last message rewritten so it makes sense without the conversation (resolve "it", "that one", dates like "last year").
- "variants": three different phrasings: one with synonyms, one shorter with key terms only, one in the language of the documents if it differs.
- "language": the language code of the standalone query.

Context: the queries feed a search engine over company documents, so they must be precise.
Most important: keep every name, number and date from the conversation; do not invent terms that are not in it.
First, find what the last message refers to; then write the standalone query; finally, check that it makes sense on its own.
If information is missing to resolve a reference, keep the original words.
Each query: 12 words maximum, neutral tone, in English unless the documents use another language. Cite the sources of names only if they appear in the conversation.
Example: "And for 2024?" after a question on revenue becomes "company revenue 2024".

Variables

conversationquestion

Notes

Run the retrieval with each query and merge the results before answering. Works with keyword, vector or hybrid search.

Community

No comments yet. Share your feedback, it will help the next person.