Whether HyDE is enabled.
Optional config?: Partial<HydeConfig>Generate multiple hypothetical documents from different perspectives.
Each hypothesis approaches the query from a different angle, improving recall by covering more of the semantic space. Uses chain-of-thought prompting to ensure diverse, high-quality hypotheses.
The system prompt asks the LLM to generate N diverse hypotheses:
The user query to generate hypotheses for.
Optional count: numberNumber of hypotheses to generate. Default: config.hypothesisCount (3).
Generated hypotheses and timing.
If the LLM call fails.
const { hypotheses, latencyMs } = await retriever.generateMultipleHypotheses(
'How does BM25 scoring work?',
3,
);
// hypotheses[0]: Technical explanation with formulas
// hypotheses[1]: Practical example with code
// hypotheses[2]: High-level conceptual overview
Multi-hypothesis retrieval: generates N diverse hypotheses, searches with each, and merges results by deduplication (keeping the highest score per document).
This dramatically improves recall compared to single-hypothesis HyDE because one bad hypothesis doesn't ruin everything — other hypotheses can still find relevant documents from different angles.
Pipeline:
Retrieval options.
The user query.
Vector store to search.
Collection to search in.
Optional queryAdditional query options.
Optional hypothesisOverride hypothesis count for this call.
Deduplicated results from all hypotheses.
const result = await retriever.retrieveMulti({
query: 'How does BM25 work?',
vectorStore: myStore,
collectionName: 'knowledge-base',
hypothesisCount: 3,
});
console.log(`Found ${result.queryResult.documents.length} unique docs from ${result.hypothesisCount} hypotheses`);
Embed the hypothesis and search the vector store. Uses adaptive thresholding: starts at initialThreshold, steps down until results are found or minThreshold is reached.
Optional queryOptional hypothesis?: stringPre-generated hypothesis (skip generation if provided).
Convenience: retrieve and format as augmented context string.
Optional queryOptional separator?: string
HyDE retriever: generates a hypothetical answer, embeds it, and searches the vector store with adaptive thresholding.