QA
Intermediate LevelAI, LLMs, Embeddings & MCP

What is HyDE (Hypothetical Document Embeddings) and Multi-Query Expansion in RAG?

❓ Interview Prompt: Explain query transformation techniques: HyDE hypothetical answer generation and multi-query decomposition.

User queries are often short, vague, or structurally dissimilar to target document chunks. Query Transformation techniques rewrite incoming prompts before vector search:

1. HyDE (Hypothetical Document Embeddings):

Instructs an LLM to generate a hypothetical ideal answer to the user query. The hypothetical answer is embedded instead of the query! Because document-to-document similarity outperforms query-to-document similarity, retrieval precision improves dramatically.

2. Multi-Query Expansion:

Uses an LLM to generate 3 to 5 alternative paraphrased versions of the original query, executing parallel vector searches and merging results.

Code Implementation Example

typescript
async function hydeRetrieval(userQuery: string): Promise<DocumentChunk[]> {
  // 1. Generate hypothetical answer document
  const hypoPrompt = 'Write a detailed hypothetical technical answer to this question: "' + userQuery + '"';
  const hypotheticalDoc = await llmClient.generate(hypoPrompt);

  // 2. Embed hypothetical document instead of raw query!
  const hypoVector = await embedText(hypotheticalDoc);

  // 3. Search vector store using hypothetical document vector
  return await vectorStore.query({ vector: hypoVector, topK: 5 });
}
💡HyDE retrieval generating and embedding a hypothetical answer document.
🎯 Interview Key Takeaway

HyDE generates a hypothetical answer and embeds it, improving vector search by comparing document-to-document embeddings.

#HyDE#Query Rewriting#RAG#Embeddings#Intermediate
Back to all AI, LLMs, Embeddings & MCP Questions→

More AI, LLMs, Embeddings & MCP Interview Questions

Beginner LevelAI, LLMs, Embeddings & MCP

What are Vector Embeddings and Cosine Similarity in AI Semantic Search?

Beginner LevelAI, LLMs, Embeddings & MCP

What is the Model Context Protocol (MCP) and how does it connect LLMs to external tools?

Beginner LevelAI, LLMs, Embeddings & MCP

What is Retrieval-Augmented Generation (RAG) and how does it prevent LLM hallucinations?