feat(retrieval): Multi-Query and HyDE fusion retrievers with RRF (#215) - #224
Closed
shivamm-gupta wants to merge 1 commit into
Closed
shivamm-gupta wants to merge 1 commit into
shivamm-gupta wants to merge 1 commit into
Conversation
…odeforstartups#215) - Implement MultiQueryRetriever and HyDERetriever in src/dynavec/retrievers.py - Support Centroid multi-passage HyDE (strategy='average') and multi-search fusion (strategy='fuse') - Support full parameter compatibility with issue codeforstartups#215 (llm_generate_queries, llm_generate_hypothetical, include_original_query) - Support true async LLM callables in both asearch() and search() - Add as_multiquery_retriever and as_hyde_retriever to Dynavec and NamespaceView - Support QueryExpansionRetriever in make_retriever_fn, as_langchain_tool, as_crewai_tool - Export retrievers in dynavec, dynavec.retrieval, and dynavec.retrievers - Add 48 comprehensive unit tests in tests/test_retrievers.py - Add runnable offline example in examples/query_expansion.py - Update README.md and CHANGELOG.md
Collaborator
Author
|
@Kaap10 please check this once |
codeforstartups
pushed a commit
that referenced
this pull request
Sep 19, 2026
… RRF (#224, #215) Adds MultiQueryRetriever (LLM reformulations) and HyDERetriever (hypothetical document embeddings, with 'average' centroid or 'fuse' strategies), fused via reciprocal_rank_fusion, plus client/namespace helpers, an example, and tests. Rebased onto current development and __init__/namespace conflicts resolved by the maintainer. Co-authored-by: Shivam Gupta <72978868+shivamm-gupta@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
|
Landed in |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements
MultiQueryRetrieverandHyDERetrieveras requested in #215 — two first-class query-expansion adapters that address vocabulary mismatch and underspecified queries in RAG applications.This PR provides a comprehensive implementation that addresses gaps and limitations in PR #222, ensuring complete backwards compatibility with maintainer @Kaap10's specification in #215, full multi-passage HyDE support, true async LLM execution, and idiomatic Dynavec ergonomics.
Related issue
Closes #215
Key Advantages over PR #222
generate_queries,generate_hypothetical,include_originalllm_generate_queries,llm_generate_hypothetical,include_original_query(plus shorthand aliases)TypeError.cleaned[0]); only takesCallable[[str], str]Callable[[str], str | Sequence[str]]withstrategy="average"(Centroid HyDE) andstrategy="fuse"asearchwraps syncsearchin a thread; passing anasync deffunction returns an unawaited coroutine that gets silently droppedasearch()and runs safely insearch()ainvoke, Anthropic/OpenAI async clients) use async LLM calls.db.as_multiquery_retriever(),db.as_hyde_retriever(),ns.as_multiquery_retriever(), andns.as_hyde_retriever()as_langchain_tool,namespace()).dynavecanddynavec.retrieversdynavec,dynavec.retrieval(as requested in #215), anddynavec.retrieversfrom dynavec.retrieval import MultiQueryRetrieverworks out of the box.original_weightexposed; reformulations hardcoded to 1.0weightsinsearch(..., weights=...)RRFWeightFitter(#49).Changes
src/dynavec/retrievers.py(new):QueryExpansionRetriever: Shared base class handling client/namespace resolution, concurrent fan-out, submission-order tie-breaking, error fallback/raise policy, and RRF fusion.MultiQueryRetriever: LLM reformulation fan-out, text sanitization and deduplication, original query prioritization, and custom weight support.HyDERetriever: Document-side embedding (embed_documents), single- and multi-passage hypothetical generation with centroid averaging (strategy="average") and multi-search RRF (strategy="fuse").src/dynavec/client.py: Addedas_multiquery_retrieverandas_hyde_retrieverfactory methods.src/dynavec/namespace.py: Addedas_multiquery_retrieverandas_hyde_retrieverfactory methods pinned to the scoped namespace.src/dynavec/retrieval.py: Re-exported retrievers for backwards compatibility with the issue specification.src/dynavec/__init__.py: ExportedMultiQueryRetriever,HyDERetriever, andQueryExpansionRetrieverin__all__.src/dynavec/integrations/tools.py: Extendedmake_retriever_fn,as_langchain_tool, andas_crewai_toolto acceptQueryExpansionRetriever.tests/test_retrievers.py(new): 48 comprehensive unit tests covering deduplication, error fallback, concurrency determinism, async LLMs, multi-passage centroid averaging, and tool integrations.examples/query_expansion.py(new): Runnable offline demonstration (no AWS, no LLM required) illustrating how Multi-Query and HyDE solve vocabulary mismatch.README.md&CHANGELOG.md: Added documentation, code examples, and changelog entry.Testing
uv run --no-sync pytest tests/test_retrievers.py -vuv run --no-sync pytest -q(100% pass)uv run ruff check src tests examples(0 errors)uv run python examples/query_expansion.pyChecklist