Search: words found only in a description come back (Q8)
The model sums up a whole record in one vector: a rare word of the description weighs too little (« métamorphose »: 5 records missing or far). With the neighbours, the keyword query over every field runs again, all words required, best 100 matches, reordered by closeness to the phrase, then fused with the neighbours. Without the model it stays the former any-word query. RankFusion takes a weight per list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,11 +30,13 @@ final class RankFusion {
|
||||
* Ranked lists of node IDs (keyword OR query, kNN neighbours…).
|
||||
* @param int $k
|
||||
* RRF constant.
|
||||
* @param array<float> $weights
|
||||
* Weight of each ranking, same keys; 1 when missing (Q8).
|
||||
*
|
||||
* @return array<int|string>
|
||||
* Node IDs, each once.
|
||||
*/
|
||||
public static function fuse(array $exact, array $rankings, int $k = self::K): array {
|
||||
public static function fuse(array $exact, array $rankings, int $k = self::K, array $weights = []): array {
|
||||
$merged = [];
|
||||
foreach ($exact as $nid) {
|
||||
$merged[$nid] ??= $nid;
|
||||
@@ -42,7 +44,8 @@ final class RankFusion {
|
||||
$scores = [];
|
||||
$first = [];
|
||||
$position = 0;
|
||||
foreach ($rankings as $ranking) {
|
||||
foreach ($rankings as $key => $ranking) {
|
||||
$weight = $weights[$key] ?? 1.0;
|
||||
$rank = 0;
|
||||
foreach ($ranking as $nid) {
|
||||
$rank++;
|
||||
@@ -53,7 +56,7 @@ final class RankFusion {
|
||||
$scores[$nid] = 0.0;
|
||||
$first[$nid] = [$position++, $nid];
|
||||
}
|
||||
$scores[$nid] += 1 / ($k + $rank);
|
||||
$scores[$nid] += $weight / ($k + $rank);
|
||||
}
|
||||
}
|
||||
uksort($scores, static fn ($a, $b): int => [$scores[$b], $first[$a][0]] <=> [$scores[$a], $first[$b][0]]);
|
||||
|
||||
Reference in New Issue
Block a user