Skip to content

feat(retrieval): add configurable per-source weights for hybrid retrieval#115

Open
knightxiaoxi wants to merge 1 commit into
however-yir:mainfrom
knightxiaoxi:feat/configurable-retrieval-weights
Open

feat(retrieval): add configurable per-source weights for hybrid retrieval#115
knightxiaoxi wants to merge 1 commit into
however-yir:mainfrom
knightxiaoxi:feat/configurable-retrieval-weights

Conversation

@knightxiaoxi

Copy link
Copy Markdown

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

// 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));

…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));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant