feat(retrieval): add configurable per-source weights for hybrid retrieval#115
Open
knightxiaoxi wants to merge 1 commit into
Open
feat(retrieval): add configurable per-source weights for hybrid retrieval#115knightxiaoxi wants to merge 1 commit into
knightxiaoxi wants to merge 1 commit into
Conversation
…eval
## Summary
Make hybrid retrieval source weights configurable per-request via `HybridWeights` record.
## Changes
- New `HybridWeights` record with auto-normalization and preset profiles
- `HybridRetrievalService.retrieve()` now accepts optional `HybridWeights` parameter
- Presets: `DEFAULT`, `SEMANTIC` (vector-heavy), `KEYWORD` (lexical-heavy), `BALANCED`
- Backward-compatible: existing `retrieve(query, tenantId, chatId, topK)` unchanged
## Motivation
Different query types benefit from different retrieval mixes:
- Factual queries ("What is X?") need more vector weight
- Lookup queries ("Find document Y") need more keyword weight
- Previously weights were hardcoded `static final` constants
## Usage
```java
// Semantic-heavy for conceptual queries
service.retrieve(query, tenantId, chatId, topK, HybridWeights.SEMANTIC);
// Custom weights
service.retrieve(query, tenantId, chatId, topK, HybridWeights.of(0.5, 0.3, 0.1, 0.1));
```
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.
Summary
Make hybrid retrieval source weights configurable per-request via
HybridWeightsrecord.Changes
HybridWeightsrecord with auto-normalization and preset profilesHybridRetrievalService.retrieve()now accepts optionalHybridWeightsparameterDEFAULT,SEMANTIC(vector-heavy),KEYWORD(lexical-heavy),BALANCEDretrieve(query, tenantId, chatId, topK)unchangedMotivation
Different query types benefit from different retrieval mixes:
static finalconstantsUsage