@wei840222/qmd 2026.8.24 → 2026.8.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ### Added
6
+
7
+ - **Disable HyDE Expansion Control**: Added `--no-hyde` CLI option for `qmd query` and `qmd vsearch`, `includeHyde` parameter to SDK (`store.search`, `store.expandQuery`) and MCP `query` tool, allowing users to disable generating hypothetical document embeddings during query expansion.
8
+
5
9
  ## [2026.8.23-1] - 2026-08-23
6
10
 
7
11
  ### Added
package/README.md CHANGED
@@ -982,6 +982,7 @@ and `deep-search` (→ `query`).
982
982
  --index <name> # Use named index
983
983
  --intent "<text>" # Legacy CLI alias for rerank context (e.g. "web page load times")
984
984
  --no-rerank # Skip LLM reranking (RRF scores only; faster on CPU)
985
+ --no-hyde # Disable HyDE in query expansion (only lex and vec expansions)
985
986
  -C, --candidate-limit <n> # Max candidates to rerank (default: 40)
986
987
  --full-path # Emit on-disk filesystem paths instead of qmd:// URIs
987
988
  # (a result whose file has moved or been deleted since
@@ -1,4 +1,4 @@
1
1
  {
2
- "commit": "1e728bc",
3
- "builtAt": "2026-08-23T06:13:30.733Z"
2
+ "commit": "7cbc570",
3
+ "builtAt": "2026-08-28T11:16:06.495Z"
4
4
  }
package/dist/cli/qmd.js CHANGED
@@ -2674,6 +2674,7 @@ async function vectorSearch(query, opts, _model = DEFAULT_EMBED_MODEL) {
2674
2674
  limit: opts.all ? 500 : (opts.limit || 10),
2675
2675
  minScore: opts.minScore || 0.3,
2676
2676
  expansionContext: opts.intent,
2677
+ includeHyde: opts.includeHyde,
2677
2678
  hooks: {
2678
2679
  onExpand: (original, expanded) => {
2679
2680
  logExpansionTree(original, expanded);
@@ -2766,6 +2767,7 @@ async function querySearch(query, opts, _embedModel = DEFAULT_EMBED_MODEL, _rera
2766
2767
  explain: !!opts.explain,
2767
2768
  rerankContext: intent,
2768
2769
  expansion: opts.expansion,
2770
+ includeHyde: opts.includeHyde,
2769
2771
  chunkStrategy: opts.chunkStrategy,
2770
2772
  hooks: {
2771
2773
  onExpansionDecision: (decision) => {
@@ -2884,6 +2886,7 @@ function parseCLI() {
2884
2886
  // Query options
2885
2887
  "candidate-limit": { type: "string", short: "C" },
2886
2888
  "no-rerank": { type: "boolean", default: false },
2889
+ "no-hyde": { type: "boolean", default: false },
2887
2890
  expand: { type: "boolean", default: false },
2888
2891
  "no-gpu": { type: "boolean", default: false },
2889
2892
  intent: { type: "string" },
@@ -2960,6 +2963,7 @@ function parseCLI() {
2960
2963
  lineNumbers: !!values["line-numbers"],
2961
2964
  candidateLimit: values["candidate-limit"] ? parseInt(String(values["candidate-limit"]), 10) : undefined,
2962
2965
  skipRerank: !!values["no-rerank"],
2966
+ includeHyde: !values["no-hyde"],
2963
2967
  explain: !!values.explain,
2964
2968
  intent: values.intent,
2965
2969
  expansion: values.expand ? "force" : "auto",
@@ -3459,6 +3463,7 @@ function showHelp() {
3459
3463
  console.log(" --chunk-strategy <auto|regex> - Chunking mode (default: regex; auto uses AST for code files)");
3460
3464
  console.log(" --timeout <minutes> - Embed session cap in minutes (0 = no limit; default 30)");
3461
3465
  console.log(" --expand - Force query expansion (auto is the default; lex: skips)");
3466
+ console.log(" --no-hyde - Disable HyDE (hypothetical document) in query expansion");
3462
3467
  console.log("");
3463
3468
  console.log("Embedding providers & disclosure:");
3464
3469
  console.log(" - Local embedding is the default. OpenAI requires explicit provider configuration and OPENAI_API_KEY.");
@@ -12,6 +12,7 @@ export declare class HybridLLM implements LLM {
12
12
  expandQuery(query: string, options?: {
13
13
  context?: string;
14
14
  includeLexical?: boolean;
15
+ includeHyde?: boolean;
15
16
  }): Promise<Queryable[]>;
16
17
  rerank(query: string, documents: RerankDocument[], options?: RerankOptions): Promise<RerankResult>;
17
18
  dispose(): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -75,6 +75,8 @@ export interface SearchOptions {
75
75
  explain?: boolean;
76
76
  /** Query expansion policy (default: auto) */
77
77
  expansion?: ExpansionMode;
78
+ /** Whether to include HyDE (hypothetical document) in query expansion (default: true) */
79
+ includeHyde?: boolean;
78
80
  /** Optional progress/decision hooks for search orchestration */
79
81
  hooks?: SearchHooks;
80
82
  /** Chunk strategy: "auto" (default, uses AST for code files) or "regex" (legacy) */
@@ -100,6 +102,10 @@ export interface VectorSearchOptions {
100
102
  export interface ExpandQueryOptions {
101
103
  /** Additional context used only while generating query expansions. */
102
104
  expansionContext?: string;
105
+ /** Whether to include lexical (BM25) sub-queries (default: true) */
106
+ includeLexical?: boolean;
107
+ /** Whether to include HyDE (hypothetical document) sub-queries (default: true) */
108
+ includeHyde?: boolean;
103
109
  }
104
110
  /**
105
111
  * Options for creating a QMD store.
package/dist/index.js CHANGED
@@ -231,6 +231,7 @@ export async function createStore(options) {
231
231
  expansionContext: opts.expansionContext,
232
232
  rerankContext: opts.rerankContext,
233
233
  expansion: opts.expansion,
234
+ includeHyde: opts.includeHyde,
234
235
  hooks: opts.hooks,
235
236
  candidateLimit: opts.candidateLimit,
236
237
  skipRerank,
@@ -242,7 +243,10 @@ export async function createStore(options) {
242
243
  const provider = internal.embeddingProvider;
243
244
  return internal.searchVec(q, provider?.model ?? internal.llm?.embedModelName ?? DEFAULT_EMBED_MODEL_URI, opts?.limit, opts?.collection);
244
245
  },
245
- expandQuery: async (q, opts) => internal.expandQuery(q, undefined, opts?.expansionContext),
246
+ expandQuery: async (q, opts) => internal.expandQuery(q, undefined, opts?.expansionContext, {
247
+ includeLexical: opts?.includeLexical,
248
+ includeHyde: opts?.includeHyde,
249
+ }),
246
250
  get: async (pathOrDocid, opts) => internal.findDocument(pathOrDocid, opts),
247
251
  getDocumentBody: async (pathOrDocid, opts) => {
248
252
  const result = internal.findDocument(pathOrDocid, { includeBody: false });
package/dist/llm.d.ts CHANGED
@@ -137,6 +137,7 @@ export interface ILLMSession {
137
137
  expandQuery(query: string, options?: {
138
138
  context?: string;
139
139
  includeLexical?: boolean;
140
+ includeHyde?: boolean;
140
141
  }): Promise<Queryable[]>;
141
142
  rerank(query: string, documents: RerankDocument[], options?: RerankOptions): Promise<RerankResult>;
142
143
  /** Whether this session is still valid (not released or aborted) */
@@ -236,6 +237,7 @@ export interface LLM {
236
237
  expandQuery(query: string, options?: {
237
238
  context?: string;
238
239
  includeLexical?: boolean;
240
+ includeHyde?: boolean;
239
241
  }): Promise<Queryable[]>;
240
242
  /**
241
243
  * Rerank documents by relevance to a query
@@ -465,6 +467,7 @@ export declare class LlamaCpp implements LLM {
465
467
  expandQuery(query: string, options?: {
466
468
  context?: string;
467
469
  includeLexical?: boolean;
470
+ includeHyde?: boolean;
468
471
  }): Promise<Queryable[]>;
469
472
  private static readonly RERANK_TEMPLATE_OVERHEAD;
470
473
  private static readonly RERANK_TARGET_DOCS_PER_CONTEXT;
package/dist/llm.js CHANGED
@@ -1245,6 +1245,7 @@ export class LlamaCpp {
1245
1245
  const llama = await this.ensureLlama();
1246
1246
  await this.ensureGenerateModel();
1247
1247
  const includeLexical = options.includeLexical ?? true;
1248
+ const includeHyde = options.includeHyde ?? true;
1248
1249
  const context = options.context;
1249
1250
  // Keep the caller-provided expansion context separate from the query. It
1250
1251
  // may clarify ambiguous terms, but it is untrusted data rather than an
@@ -1259,11 +1260,18 @@ export class LlamaCpp {
1259
1260
  let genContext;
1260
1261
  let sequence;
1261
1262
  try {
1263
+ const allowedTypes = [];
1264
+ if (includeLexical)
1265
+ allowedTypes.push('"lex"');
1266
+ allowedTypes.push('"vec"');
1267
+ if (includeHyde)
1268
+ allowedTypes.push('"hyde"');
1269
+ const typeRule = allowedTypes.join(' | ');
1262
1270
  const grammar = await llama.createGrammar({
1263
1271
  grammar: `
1264
1272
  root ::= line+
1265
1273
  line ::= type ": " content "\\n"
1266
- type ::= "lex" | "vec" | "hyde"
1274
+ type ::= ${typeRule}
1267
1275
  content ::= [^\\n]+
1268
1276
  `
1269
1277
  });
@@ -1304,21 +1312,27 @@ export class LlamaCpp {
1304
1312
  const type = line.slice(0, colonIdx).trim();
1305
1313
  if (type !== 'lex' && type !== 'vec' && type !== 'hyde')
1306
1314
  return null;
1315
+ if (type === 'lex' && !includeLexical)
1316
+ return null;
1317
+ if (type === 'hyde' && !includeHyde)
1318
+ return null;
1307
1319
  const text = line.slice(colonIdx + 1).trim();
1308
1320
  if (!hasQueryTerm(text))
1309
1321
  return null;
1310
1322
  return { type: type, text };
1311
1323
  }).filter((q) => q !== null);
1312
- // Filter out lex entries if not requested
1313
- const filtered = includeLexical ? queryables : queryables.filter(q => q.type !== 'lex');
1324
+ // Filter out unwanted types if any slipped through
1325
+ const filtered = queryables
1326
+ .filter(q => (includeLexical || q.type !== 'lex'))
1327
+ .filter(q => (includeHyde || q.type !== 'hyde'));
1314
1328
  if (filtered.length > 0)
1315
1329
  return filtered;
1316
1330
  const fallback = [
1317
- { type: 'hyde', text: `Information about ${query}` },
1318
- { type: 'lex', text: query },
1331
+ ...(includeHyde ? [{ type: 'hyde', text: `Information about ${query}` }] : []),
1332
+ ...(includeLexical ? [{ type: 'lex', text: query }] : []),
1319
1333
  { type: 'vec', text: query },
1320
1334
  ];
1321
- return includeLexical ? fallback : fallback.filter(q => q.type !== 'lex');
1335
+ return fallback;
1322
1336
  }
1323
1337
  catch (error) {
1324
1338
  console.error("Structured query expansion failed:", error);
@@ -255,8 +255,9 @@ Context-aware lex (C++ performance, not sports):
255
255
  rerankContext: z.string().optional().describe("Additional context used only to rerank results and select snippets/chunks."),
256
256
  rerank: z.boolean().optional().default(true).describe("Rerank results using LLM (default: true). Set to false for faster results on CPU-only machines."),
257
257
  explain: z.boolean().optional().default(false).describe("Include retrieval traces and the shared query-expansion decision or typed expansion error"),
258
+ includeHyde: z.boolean().optional().default(true).describe("Whether to include HyDE (hypothetical document) in query expansion (default: true)"),
258
259
  }),
259
- }, track(async ({ query, searches, expansion, limit, minScore, candidateLimit, collections, expansionContext, rerankContext, rerank, explain }) => {
260
+ }, track(async ({ query, searches, expansion, includeHyde, limit, minScore, candidateLimit, collections, expansionContext, rerankContext, rerank, explain }) => {
260
261
  // Require exactly one of `query` (plain text with an expansion policy) or `searches` (typed sub-queries).
261
262
  if (!query && (!searches || searches.length === 0)) {
262
263
  return {
@@ -292,6 +293,7 @@ Context-aware lex (C++ performance, not sports):
292
293
  rerankContext,
293
294
  explain,
294
295
  expansion: query ? expansion : undefined,
296
+ includeHyde,
295
297
  hooks: explain && query ? {
296
298
  onExpansionDecision: decision => { expansionDecision = decision; },
297
299
  onExpansionError: event => { expansionError = event; },
@@ -38,6 +38,7 @@ export declare class RemoteLLM implements LLM {
38
38
  expandQuery(query: string, options?: {
39
39
  context?: string;
40
40
  includeLexical?: boolean;
41
+ includeHyde?: boolean;
41
42
  timeZone?: string;
42
43
  }): Promise<Queryable[]>;
43
44
  rerank(query: string, documents: RerankDocument[], options?: RerankOptions | string | (RerankOptions & {
@@ -127,18 +127,29 @@ export class RemoteLLM {
127
127
  throw new Error("Remote expansion is not configured or circuit is broken.");
128
128
  }
129
129
  const includeLexical = options?.includeLexical !== false;
130
+ const includeHyde = options?.includeHyde !== false;
130
131
  const lexicalOutput = includeLexical ? "lex: keyword-focused search phrase\n" : "";
131
132
  const lexicalRule = includeLexical
132
133
  ? "- lex: preserve precise terms and add only useful synonyms or related keywords; do not write a complete question.\n"
133
134
  : "";
134
135
  const lexicalExample = includeLexical ? "lex: database connection pool timeout exhaustion\n" : "";
136
+ const hydeOutput = includeHyde ? "hyde: concise hypothetical answer-style passage\n" : "";
137
+ const hydeRule = includeHyde
138
+ ? "- hyde: write a concise hypothetical passage describing plausible answer content, describing general concepts without inventing specific fake facts.\n"
139
+ : "";
140
+ const hydeExample = includeHyde ? "hyde: Database connection pool timeout troubleshooting may examine pool limits, active connections, query latency, and connection handling.\n" : "";
141
+ const requestedBackends = [
142
+ includeLexical ? "lex" : null,
143
+ "vec",
144
+ includeHyde ? "hyde" : null,
145
+ ].filter(Boolean).join(", ");
135
146
  const systemPrompt = `<role>
136
147
  You are a specialized assistant for hybrid document-search query expansion.
137
148
  You expand search queries to enhance retrieval recall with analytical precision while preserving user intent and constraints.
138
149
  </role>
139
150
 
140
151
  <instructions>
141
- 1. Proactively generate one high-quality variation for each requested backend (lex, vec, hyde) whenever the query has clear intent.
152
+ 1. Proactively generate one high-quality variation for each requested backend (${requestedBackends}) whenever the query has clear intent.
142
153
  2. Preserve query constraints and avoid inventing unmentioned facts.
143
154
  3. Return only the requested prefix lines.
144
155
  </instructions>
@@ -150,15 +161,13 @@ You expand search queries to enhance retrieval recall with analytical precision
150
161
  - Keep the query's primary language and script, while preserving exact identifiers, product names, API names, abbreviations, and established domain terms from the query or context.
151
162
  ${lexicalRule}- vec: state the search intent as a clear natural-language phrase or question.
152
163
  - For space-separated or keyword-list queries, synthesize the scattered terms into a coherent, natural-language phrase or question for vec.
153
- - hyde: write a concise hypothetical passage describing plausible answer content, describing general concepts without inventing specific fake facts.
154
- - For very short or identifier-only queries, retain exact terms without inventing unprovided constraints.
164
+ ${hydeRule}- For very short or identifier-only queries, retain exact terms without inventing unprovided constraints.
155
165
  </constraints>
156
166
 
157
167
  <output_format>
158
168
  Output only prefix lines. Do not include preambles, explanations, markdown, or code fences.
159
169
  ${lexicalOutput}vec: natural-language semantic search phrase or question
160
- hyde: concise hypothetical answer-style passage
161
- Generate at most one line of each listed type.
170
+ ${hydeOutput}Generate at most one line of each listed type.
162
171
  </output_format>
163
172
 
164
173
  <example>
@@ -173,8 +182,7 @@ database pool timeout
173
182
  </task>
174
183
 
175
184
  ${lexicalExample}vec: Why is the database connection pool timing out under load?
176
- hyde: Database connection pool timeout troubleshooting may examine pool limits, active connections, query latency, and connection handling.
177
- </example>`;
185
+ ${hydeExample}</example>`;
178
186
  const currentTime = getFormattedLocalTime(new Date(), options?.timeZone ?? this.timeZone);
179
187
  const additionalContext = options?.context
180
188
  ? `Additional context:\n${escapePromptXml(options.context)}`
@@ -224,7 +232,11 @@ Return only the prefix lines specified in the output format.
224
232
  const match = /^(lex|vec|hyde)\s*:\s*(.+)$/i.exec(line.trim());
225
233
  if (match && match[1] && match[2]) {
226
234
  const type = match[1].toLowerCase();
227
- if ((type !== "lex" || options?.includeLexical !== false) && !seenTypes.has(type)) {
235
+ if (type === "lex" && !includeLexical)
236
+ continue;
237
+ if (type === "hyde" && !includeHyde)
238
+ continue;
239
+ if (!seenTypes.has(type)) {
228
240
  seenTypes.add(type);
229
241
  results.push({ type, text: match[2].trim() });
230
242
  }
package/dist/store.d.ts CHANGED
@@ -132,6 +132,8 @@ export type ExpandedQuery = {
132
132
  };
133
133
  export type QueryExpansionOptions = {
134
134
  requireResult?: boolean;
135
+ includeLexical?: boolean;
136
+ includeHyde?: boolean;
135
137
  };
136
138
  export declare function homedir(): string;
137
139
  /**
@@ -313,7 +315,7 @@ export type Store = {
313
315
  searchVec: (query: string, model: string, limit?: number, collectionFilter?: CollectionFilter, session?: ILLMSession, precomputedEmbedding?: number[]) => Promise<SearchResult[]>;
314
316
  expandQuery: (query: string, model?: string, expansionContext?: string, options?: QueryExpansionOptions) => Promise<ExpandedQuery[]>;
315
317
  /** Drop the cached expansion for a query so the next call regenerates. */
316
- invalidateExpansionCache: (query: string, expansionContext?: string) => void;
318
+ invalidateExpansionCache: (query: string, expansionContext?: string, options?: QueryExpansionOptions) => void;
317
319
  rerank: (query: string, documents: {
318
320
  file: string;
319
321
  text: string;
@@ -634,6 +636,8 @@ export type CacheKeyBody = {
634
636
  chunk?: string;
635
637
  file?: string;
636
638
  expansionContext?: string;
639
+ noHyde?: boolean;
640
+ noLex?: boolean;
637
641
  };
638
642
  export declare function getCacheKey(url: string, body: CacheKeyBody): string;
639
643
  export declare function getCachedResult(db: Database, cacheKey: string): string | null;
@@ -968,7 +972,10 @@ export declare function expandQuery(query: string, model: string | undefined, db
968
972
  * expansion's sub-queries all came back empty — left in place, the dud entry
969
973
  * would replay the same misses on every warm repeat of the query.
970
974
  */
971
- export declare function deleteExpansionCacheEntry(db: Database, query: string, model?: string, expansionContext?: string): void;
975
+ export declare function deleteExpansionCacheEntry(db: Database, query: string, model?: string, expansionContext?: string, options?: {
976
+ includeLexical?: boolean;
977
+ includeHyde?: boolean;
978
+ }): void;
972
979
  export declare function rerank(query: string, documents: {
973
980
  file: string;
974
981
  text: string;
@@ -1106,6 +1113,7 @@ export interface HybridQueryOptions {
1106
1113
  /** Additional context used for reranking and snippet/chunk selection. */
1107
1114
  rerankContext?: string;
1108
1115
  expansion?: ExpansionMode;
1116
+ includeHyde?: boolean;
1109
1117
  skipRerank?: boolean;
1110
1118
  chunkStrategy?: ChunkStrategy;
1111
1119
  hooks?: SearchHooks;
@@ -1159,6 +1167,8 @@ export interface VectorSearchOptions {
1159
1167
  minScore?: number;
1160
1168
  /** Additional context used only while generating query expansions. */
1161
1169
  expansionContext?: string;
1170
+ /** Whether to include HyDE (hypothetical document) in query expansion (default: true) */
1171
+ includeHyde?: boolean;
1162
1172
  hooks?: Pick<SearchHooks, 'onExpand'>;
1163
1173
  }
1164
1174
  export interface VectorSearchResult {
package/dist/store.js CHANGED
@@ -2690,7 +2690,7 @@ export function createStore(dbPath, options = {}) {
2690
2690
  searchVec: (query, model, limit, collectionFilter, session, precomputedEmbedding) => searchVec(db, query, model, limit, collectionFilter, session, precomputedEmbedding, store.embeddingProvider, store.authorizeRemoteRequest, store.llm),
2691
2691
  // Query expansion & reranking
2692
2692
  expandQuery: (query, model, expansionContext, options) => expandQuery(query, model ?? store.localLlm?.generateModelName ?? store.llm?.generateModelName ?? DEFAULT_QUERY_MODEL, db, expansionContext, store.llm, options),
2693
- invalidateExpansionCache: (query, expansionContext) => deleteExpansionCacheEntry(db, query, store.localLlm?.generateModelName ?? store.llm?.generateModelName ?? DEFAULT_QUERY_MODEL, expansionContext),
2693
+ invalidateExpansionCache: (query, expansionContext, options) => deleteExpansionCacheEntry(db, query, store.localLlm?.generateModelName ?? store.llm?.generateModelName ?? DEFAULT_QUERY_MODEL, expansionContext, options),
2694
2694
  rerank: (query, documents, model, rerankContext) => {
2695
2695
  const llm = getLlm(store);
2696
2696
  return rerank(query, documents, model ?? store.localLlm?.rerankModelName ?? llm?.rerankModelName ?? DEFAULT_RERANK_MODEL, db, rerankContext, store.llm ?? llm);
@@ -4670,8 +4670,16 @@ export function insertEmbedding(db, hash, seq, pos, embedding, model, embeddedAt
4670
4670
  // Query expansion
4671
4671
  // =============================================================================
4672
4672
  export async function expandQuery(query, model = DEFAULT_QUERY_MODEL, db, expansionContext, llmOverride, options) {
4673
+ const includeLexical = options?.includeLexical ?? true;
4674
+ const includeHyde = options?.includeHyde ?? true;
4673
4675
  // Check cache first — stored as JSON preserving types
4674
- const cacheKey = getCacheKey("expandQuery", { query, model, ...(expansionContext && { expansionContext }) });
4676
+ const cacheKey = getCacheKey("expandQuery", {
4677
+ query,
4678
+ model,
4679
+ ...(expansionContext && { expansionContext }),
4680
+ ...(!includeHyde && { noHyde: true }),
4681
+ ...(!includeLexical && { noLex: true }),
4682
+ });
4675
4683
  const cached = getCachedResult(db, cacheKey);
4676
4684
  if (cached) {
4677
4685
  try {
@@ -4693,7 +4701,11 @@ export async function expandQuery(query, model = DEFAULT_QUERY_MODEL, db, expans
4693
4701
  }
4694
4702
  const llm = llmOverride ?? getDefaultLlamaCpp();
4695
4703
  // Note: LlamaCpp uses hardcoded model, model parameter is ignored
4696
- const results = await llm.expandQuery(query, { context: expansionContext });
4704
+ const results = await llm.expandQuery(query, {
4705
+ context: expansionContext,
4706
+ includeLexical,
4707
+ includeHyde,
4708
+ });
4697
4709
  // Map Queryable[] → ExpandedQuery[] (same shape, decoupled from llm.ts internals).
4698
4710
  // Filter out entries that duplicate the original query text.
4699
4711
  const expanded = results
@@ -4712,8 +4724,14 @@ export async function expandQuery(query, model = DEFAULT_QUERY_MODEL, db, expans
4712
4724
  * expansion's sub-queries all came back empty — left in place, the dud entry
4713
4725
  * would replay the same misses on every warm repeat of the query.
4714
4726
  */
4715
- export function deleteExpansionCacheEntry(db, query, model = DEFAULT_QUERY_MODEL, expansionContext) {
4716
- const cacheKey = getCacheKey("expandQuery", { query, model, ...(expansionContext && { expansionContext }) });
4727
+ export function deleteExpansionCacheEntry(db, query, model = DEFAULT_QUERY_MODEL, expansionContext, options) {
4728
+ const cacheKey = getCacheKey("expandQuery", {
4729
+ query,
4730
+ model,
4731
+ ...(expansionContext && { expansionContext }),
4732
+ ...(options?.includeHyde === false && { noHyde: true }),
4733
+ ...(options?.includeLexical === false && { noLex: true }),
4734
+ });
4717
4735
  db.prepare(`DELETE FROM llm_cache WHERE hash = ?`).run(cacheKey);
4718
4736
  }
4719
4737
  // =============================================================================
@@ -5491,6 +5509,7 @@ export async function hybridQuery(store, query, options) {
5491
5509
  if (hasStrongSignal)
5492
5510
  hooks?.onStrongSignal?.(topScore);
5493
5511
  // Step 2: Expand query (or skip if strong signal)
5512
+ const includeHyde = options?.includeHyde ?? true;
5494
5513
  if (expansionDecision.action === "expand")
5495
5514
  hooks?.onExpandStart?.();
5496
5515
  const expandStart = Date.now();
@@ -5500,6 +5519,7 @@ export async function hybridQuery(store, query, options) {
5500
5519
  ? []
5501
5520
  : await store.expandQuery(query, undefined, expansionContext, {
5502
5521
  requireResult: expansionDecision.reason === "explicit-force",
5522
+ includeHyde,
5503
5523
  });
5504
5524
  }
5505
5525
  catch (error) {
@@ -5590,7 +5610,7 @@ export async function hybridQuery(store, query, options) {
5590
5610
  const runnable = expanded.filter(q => q.type === "lex" || hasVectors);
5591
5611
  const expansionContributed = rankedListMeta.some(m => m.queryType !== "original");
5592
5612
  if (runnable.length > 0 && !expansionContributed) {
5593
- store.invalidateExpansionCache(query, expansionContext);
5613
+ store.invalidateExpansionCache(query, expansionContext, { includeHyde });
5594
5614
  }
5595
5615
  }
5596
5616
  // Step 4: RRF fusion — original-query FTS and vector lists get 2x weight;
@@ -5767,11 +5787,14 @@ export async function vectorSearchQuery(store, query, options) {
5767
5787
  const minScore = options?.minScore ?? 0.3;
5768
5788
  const collection = options?.collection;
5769
5789
  const expansionContext = options?.expansionContext;
5790
+ const includeHyde = options?.includeHyde ?? true;
5770
5791
  if (!hasSearchableVectorIndex(store))
5771
5792
  return [];
5772
5793
  // Expand query — filter to vec/hyde only (lex queries target FTS, not vector)
5773
5794
  const expandStart = Date.now();
5774
- const allExpanded = await store.expandQuery(query, undefined, expansionContext);
5795
+ const allExpanded = await store.expandQuery(query, undefined, expansionContext, {
5796
+ includeHyde,
5797
+ });
5775
5798
  const vecExpanded = allExpanded.filter(q => q.type !== 'lex');
5776
5799
  options?.hooks?.onExpand?.(query, vecExpanded, Date.now() - expandStart);
5777
5800
  const embedModel = store.embeddingProvider?.model ?? getLlm(store).embedModelName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wei840222/qmd",
3
- "version": "2026.8.24",
3
+ "version": "2026.8.28",
4
4
  "packageManager": "pnpm@11.15.1",
5
5
  "description": "Query Markup Documents - On-device hybrid search for markdown files with BM25, vector search, and LLM reranking",
6
6
  "type": "module",
@@ -230,6 +230,8 @@ Query types:
230
230
  - `vec` — vector semantic search. Best for natural-language concepts.
231
231
  - `hyde` — vector search using a hypothetical answer/document passage.
232
232
 
233
+ When invoking `query` with a plain `query` string instead of explicit `searches`, you can set `includeHyde: false` (to omit HyDE passage generation) and `expansion: "auto" | "force" | "skip"`.
234
+
233
235
  ## Query craft
234
236
 
235
237
  Good QMD searches mix three things:
@@ -30,6 +30,7 @@ newline = "\n" ;
30
30
 
31
31
  A query is either a single policy query or a multi-line query document:
32
32
  - **`auto` (Default)**: CJK queries and strong lexical matches automatically bypass model expansion. Other plain queries expand into `lex`, `vec`, and `hyde` variants.
33
+ - **`--no-hyde`**: Disables HyDE (hypothetical document) in query expansion, generating only `lex` and `vec` variants (faster, avoids hallucinated passage drift).
33
34
  - **`expand:` / `--expand` (`force`)**: Explicitly forces expansion even if bypass heuristics apply.
34
35
  - **`lex:` (`skip`)**: Explicitly disables expansion and performs direct BM25 search.
35
36
 
@@ -37,6 +38,9 @@ A query is either a single policy query or a multi-line query document:
37
38
  # Automatic policy:
38
39
  qmd query "how does authentication work"
39
40
 
41
+ # Disable HyDE during expansion:
42
+ qmd query --no-hyde "how does authentication work"
43
+
40
44
  # Force expansion:
41
45
  qmd query "expand: how does authentication work"
42
46
  # or: qmd query --expand "資料庫同步"
@@ -81,6 +85,8 @@ A 50–100 word hypothetical answer passage representing what the target documen
81
85
  hyde: The rate limiter uses a sliding window counter algorithm with a 60-second window. When a client exceeds 100 requests per minute, subsequent requests return 429 Too Many Requests.
82
86
  ```
83
87
 
88
+ When relying on query expansion, HyDE generation can be excluded using `--no-hyde` (CLI) or `"includeHyde": false` (MCP/SDK).
89
+
84
90
  ## Multi-Line Structured Queries
85
91
 
86
92
  Combine multiple sub-query types for optimal retrieval. The first sub-query receives **2x weight** during Reciprocal Rank Fusion:
@@ -150,8 +156,9 @@ When calling the `qmd` MCP server's `query` tool, provide a structured `searches
150
156
 
151
157
  ```json
152
158
  {
153
- "query": "CAP theorem consistency",
159
+ "query": "authentication flow",
154
160
  "expansion": "auto",
161
+ "includeHyde": false,
155
162
  "explain": true,
156
163
  "collections": ["docs"]
157
164
  }