fix(node): rerank vector search results

This commit is contained in:
Gatefixer
2026-08-05 23:34:58 +00:00
parent 7357d63e87
commit 48ca05c7d5
4 changed files with 68 additions and 10 deletions
+12
View File
@@ -79,6 +79,18 @@ describe("rerankers", function () {
expect(result).toHaveLength(2);
});
it("returns relevance scores when reranking a vector search", async function () {
const result = await table
.vectorSearch([0.1, 0.1])
.limit(2)
.rerank(await RRFReranker.create())
.toArray();
expect(result).toHaveLength(2);
expect(result[0]._relevance_score).toBeCloseTo(1 / 60);
expect(result[1]._relevance_score).toBeCloseTo(1 / 61);
});
it("does not keep process alive after rerank query", async function () {
const script = `
import * as lancedb from "./dist/index.js";
+3 -3
View File
@@ -5,9 +5,9 @@ import { RecordBatch } from "apache-arrow";
export * from "./rrf";
// Interface for a reranker. A reranker is used to rerank the results from a
// vector and FTS search. This is useful for combining the results from both
// search methods.
// Interface for a reranker. A reranker is used to rerank vector and hybrid
// search results. For vector-only searches, query is empty and ftsResults is an
// empty batch with the same schema as vecResults.
export interface Reranker {
rerankHybrid(
query: string,