hyde-hypothetical-document-embeddings
Skill8 starsChanged 7 months agoMITView on GitHub
Use LLM-generated hypothetical documents to bridge the query-document gap and improve retrieval relevance.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- hierarchical-chunkingSkill
- semantic-chunkingSkill
- chunkingSkill
- sliding-window-chunkingSkill
- rag-for-code-documentationSkill
- rag-for-multimodal-contentSkill
- data-type-handlingSkill
- index-versioning-and-reindexingSkill
- production-rag-deploymentSkill
- deploymentSkill
- generation-evaluation-metricsSkill
- rag-evaluation-frameworksSkill
- retrieval-evaluation-metricsSkill
- evaluation-metricsSkill
- optimize-retrieval-latencySkill
- performance-optimizationSkill
- agentic-rag-routingSkill
- multi-agent-rag-orchestrationSkill
- rag-agentsSkill
- adaptive-retrievalSkill
- context-enrichment-windowSkill
- crag-corrective-ragSkill
- explainable-retrievalSkill
- graph-ragSkill
- hybrid-search-bm25-denseSkill
- hype-hypothetical-prompt-embeddingsSkill
- multi-pass-retrieval-with-rerankingSkill
- query-transformation-strategiesSkill
- raptor-hierarchical-retrievalSkill
- self-ragSkill
- retrieval-strategiesSkill
- choosing-vector-db-by-datatypeSkill
- qdrant-for-production-ragSkill
- qdrant-setup-ragSkill
- vector-databasesSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Use an LLM to generate a detailed document answering the user's query.
- Distinctive: line 48
Use the generated document as the query for similarity search instead of the original query.
- Distinctive: line 70
When query-document style mismatch causes poor retrieval
- Distinctive: line 72
When using semantic search with vector embeddings
- Distinctive: line 73
When traditional query expansion with synonyms doesn't suffice
- Distinctive: line 76
When queries and documents already have similar styles (e.g., FAQ systems)
- Distinctive: line 78
When using keyword-based retrieval (BM25) that doesn't benefit from style alignment
- Distinctive: line 79
When the cost of LLM generation outweighs relevance improvements
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
HyDE (Hypothetical Document Embeddings) is a query expansion technique that generates a hypothetical document answering the user's query, then uses this synthetic document as the query for vector search. This bridges the semantic gap between short queries and longer, more detailed document representations.
Problem Statement
Traditional RAG systems face a fundamental mismatch:
- Query Style: User queries are short, informal, and question-oriented
- Document Style: Indexed documents are long, formal, and answer-oriented
- Embedding Space Gap: These different styles occupy different regions in embedding space
- Direct Matching Failure: Query-document direct similarity often produces poor matches
Key Concepts
- Hypothetical Document: An LLM-generated synthetic document that answers the query
- Query-Document Style Gap: The difference between query and document writing styles
- Embedding Similarity: Matching generated answer to actual answers in the corpus
- Answer-Answer Matching: Transforming the problem from query-document to answer-answer matching
- Document-Aware Generation: Hypothetical documents sized to match typical chunk lengths
Implementation Guide
Step 1: Implement Hypothetical Document Generation
Use an LLM to generate a detailed document answering the user's query.
Why: The generated hypothetical document shares characteristics (length, style, content structure) with actual documents in your corpus, enabling better similarity matching in embedding space.
Direct the LLM to create a comprehensive answer that matches the typical length and style of documents in your collection.
Step 2: Configure Document-Aware Generation
Match the hypothetical document size to your average chunk size.
Why: Documents of similar length will have more comparable embedding representations. Mismatched lengths can create distance artifacts unrelated to semantic meaning.
Target a specific character count or token count that matches your chunking strategy (typically 400-1000 characters).
Step 3: Perform Vector Search with Hypothetical Document
Use the generated document as the query for similarity search instead of the original query.
Why: The hypothetical document is in the same style and semantic space as your indexed documents, allowing the vector database to find semantically similar content more effectively.
Replace the original query with the generated hypothetical document when performing vector similarity search.
Step 4: Implement Result Filtering
Filter retrieved documents for actual relevance to the original query.
Why: While HyDE improves retrieval, some results may be semantically similar but factually irrelevant. Relevance filtering ensures quality.
Evaluate retrieved documents against the original query (not the hypothetical one) to filter out irrelevant matches.
Step 5: Build Complete HyDE Pipeline
Combine generation, retrieval, and filtering into a cohesive system.
Why: A complete pipeline with timing and explanation allows optimization, debugging, and production deployment.
For implementation patterns, see the HyDE paper, LlamaIndex HyDE Query Transform, and LangChain HyDE reference.
When to Use This Skill
- Building RAG systems where queries are short and documents are long
- When query-document style mismatch causes poor retrieval
- For domains where questions and answers have different linguistic patterns
- When using semantic search with vector embeddings
- When traditional query expansion with synonyms doesn't suffice
When NOT to Use This Skill
- When queries and documents already have similar styles (e.g., FAQ systems)
- For extremely latency-sensitive applications (adds LLM call per query)
- When using keyword-based retrieval (BM25) that doesn't benefit from style alignment
- When the cost of LLM generation outweighs relevance improvements
- For very small document collections where direct matching works well
Related Skills
- HyPE - Precomputed alternative
- Query Transformation Strategies - Other expansion methods
- Multi-Pass Retrieval with Reranking - Post-retrieval refinement
Metrics & Success Criteria
- Retrieval Relevance: NDCG@10 improvement > 15% over baseline
- Style Alignment: Hypothetical documents match corpus style characteristics
- Latency: End-to-end latency < 1s for typical queries
- Cost: LLM generation cost balanced against relevance gains
- Answer Quality: Final answers show improved factual accuracy
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

