Grammar
Query documents use a simple line-based format:Query Types
| Type | Method | Description |
|---|---|---|
lex | BM25 | Keyword search with exact matching |
vec | Vector | Semantic similarity search |
hyde | Vector | Hypothetical document embedding |
lex - Lexical Search
Keyword-based search using BM25. Supports special syntax for precision:| Pattern | Meaning | Example |
|---|---|---|
word | Prefix match | perf matches “performance” |
"phrase" | Exact phrase | "rate limiter" |
-word | Exclude term | -sports |
-"phrase" | Exclude phrase | -"test data" |
Lex queries are the only type that supports exclusions (
-term) and exact phrase matching ("phrase").vec - Semantic Search
Natural language queries using vector embeddings:hyde - Hypothetical Document Embedding
Write a hypothetical answer passage (50-100 words) representing what you expect the answer to look like:Multi-Line Query Documents
Combine multiple query types for best results:- Each line searches independently (BM25 or vector)
- Results are fused using RRF (Reciprocal Rank Fusion)
- First query gets 2× weight to preserve exact matches
- Top candidates are reranked by LLM
Expand Queries (Default)
If you don’t specify query types, QMD treats input as an expand query and generateslex, vec, and hyde variants automatically:
- 1 lexical variant
- 1 semantic variant
- (Original query gets 2× weight)
Expansion is the default because it’s simple and works well. Use explicit typed queries when you need precise control.
Query Document Examples
Example 1: Keyword + Semantic
- Exact phrase “CAP theorem” (lex)
- Semantic similarity to consistency/availability concepts (vec)
Example 2: Exclusions + Question
- Performance but NOT optimization (lex exclusion)
- Improving query speed (semantic)
Example 3: All Three Types
- Keyword matching for “authentication token”
- Semantic question about auth system
- Hypothetical answer matching detailed explanations
Validation Rules
Lex Query Validation
Vec/Hyde Query Validation
Query Document Rules
- Each typed line must use
lex:,vec:, orhyde:prefix - Cannot mix
expand:with typed lines - Empty lines are ignored
- Leading/trailing whitespace is trimmed
MCP/HTTP API Format
When using QMD via MCP, you can pass query documents as strings:String Format
Structured Format
When to Use Query Documents
Precise control over search strategy
Precise control over search strategy
When you want to control exactly which query types are used:
Combining keyword and semantic search
Combining keyword and semantic search
When you need both exact matches and conceptual similarity:
Using exclusions with semantic search
Using exclusions with semantic search
When you need to exclude terms while still doing semantic search:
Testing different query strategies
Testing different query strategies
During development or tuning, explicit queries help test what works best:
Fusion and Ranking
Multi-line queries are fused using Reciprocal Rank Fusion (RRF):- First query gets 2× weight to preserve exact matches
- Top-rank bonus: Documents ranking #1 get +0.05, #2-3 get +0.02
- Position-aware blending after reranking:
- Rank 1-3: 75% retrieval, 25% reranker
- Rank 4-10: 60% retrieval, 40% reranker
- Rank 11+: 40% retrieval, 60% reranker
Best Practices
Put lex first
Place
lex: queries first to give exact matches 2× weight:Use lex for exclusions
Only
lex: supports -term syntax:Keep hyde focused
Write 50-100 word passages, not entire documents:
Combine types strategically
Use lex for precision, vec for recall:
Related
- Search Modes - Understanding search, vsearch, and query
- Embeddings - How vec and hyde work
- MCP Server - Using query syntax via MCP
- CLI Reference - Query command documentation