@oomkapwn/enquire-mcp 3.0.1 → 3.1.0

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/dist/tools.js CHANGED
@@ -2313,10 +2313,29 @@ export async function semanticSearch(vault, args) {
2313
2313
  }
2314
2314
  return { query: args.query, total_docs: docs.length, method: "tfidf-cosine", matches };
2315
2315
  }
2316
+ /**
2317
+ * v3.1.0 — pick the text that should be embedded for an embeddings-search
2318
+ * call. HyDE-augmented retrieval prefers the agent-supplied
2319
+ * `hypothetical_answer` (Gao et al 2023); falls back to the raw query
2320
+ * when that's absent / empty / whitespace-only.
2321
+ *
2322
+ * Pure helper so we can unit-test the decision in isolation (the real
2323
+ * `embeddingsSearch` function loads the @huggingface/transformers
2324
+ * embedder, which is out of scope for unit tests).
2325
+ */
2326
+ export function pickEmbedTextForHyde(args) {
2327
+ const ha = args.hypothetical_answer?.trim() ?? "";
2328
+ if (ha.length > 0)
2329
+ return { text: ha, usedHyde: true };
2330
+ return { text: args.query, usedHyde: false };
2331
+ }
2316
2332
  export async function embeddingsSearch(vault, args, embedFile, hnsw) {
2317
2333
  await vault.ensureExists();
2318
2334
  if (!args.query.trim())
2319
2335
  throw new Error("query must not be empty");
2336
+ // v3.1.0 — pick the actual text to embed. HyDE prefers the
2337
+ // hypothetical answer when present; otherwise fall back to the query.
2338
+ const { text: embedText, usedHyde } = pickEmbedTextForHyde(args);
2320
2339
  const limit = args.limit ?? 10;
2321
2340
  const minScore = args.min_score ?? 0.3;
2322
2341
  // Lazy-load embed-db + embeddings only when the tool is actually called.
@@ -2346,7 +2365,7 @@ export async function embeddingsSearch(vault, args, embedFile, hnsw) {
2346
2365
  return { query: args.query, method: "embeddings-cosine", model: model.alias, total_chunks: 0, matches: [] };
2347
2366
  }
2348
2367
  const embedder = await loadEmbedder(args.model);
2349
- const [qVec] = await embedder.embed([args.query]);
2368
+ const [qVec] = await embedder.embed([embedText]);
2350
2369
  if (!qVec)
2351
2370
  throw new Error("Embedder returned no vectors for the query");
2352
2371
  // v2.0.0-beta.2 P0 fix: filter excluded paths from the embedding-index
@@ -2388,7 +2407,14 @@ export async function embeddingsSearch(vault, args, embedFile, hnsw) {
2388
2407
  line_end: h.line_end,
2389
2408
  kind: h.kind
2390
2409
  }));
2391
- return { query: args.query, method: "embeddings-cosine", model: model.alias, total_chunks: total, matches };
2410
+ return {
2411
+ query: args.query,
2412
+ method: "embeddings-cosine",
2413
+ model: model.alias,
2414
+ total_chunks: total,
2415
+ matches,
2416
+ ...(usedHyde ? { hyde: true } : {})
2417
+ };
2392
2418
  }
2393
2419
  finally {
2394
2420
  db.close();