mirror of
https://github.com/lancedb/lancedb.git
synced 2026-05-30 02:10:40 +00:00
* Make `npm run docs` fail if there are any warnings. This will catch items missing from the API reference. * Add a check in our CI to make sure `npm run dos` runs without warnings and doesn't generate any new files (indicating it might be out-of-date. * Hide constructors that aren't user facing. * Remove unused enum `WriteMode`. Closes #2068
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
import { RecordBatch } from "apache-arrow";
|
|
import { fromBufferToRecordBatch, fromRecordBatchToBuffer } from "../arrow";
|
|
import { RrfReranker as NativeRRFReranker } from "../native";
|
|
|
|
/**
|
|
* Reranks the results using the Reciprocal Rank Fusion (RRF) algorithm.
|
|
*
|
|
* @hideconstructor
|
|
*/
|
|
export class RRFReranker {
|
|
private inner: NativeRRFReranker;
|
|
|
|
/** @ignore */
|
|
constructor(inner: NativeRRFReranker) {
|
|
this.inner = inner;
|
|
}
|
|
|
|
public static async create(k: number = 60) {
|
|
return new RRFReranker(
|
|
await NativeRRFReranker.tryNew(new Float32Array([k])),
|
|
);
|
|
}
|
|
|
|
async rerankHybrid(
|
|
query: string,
|
|
vecResults: RecordBatch,
|
|
ftsResults: RecordBatch,
|
|
): Promise<RecordBatch> {
|
|
const buffer = await this.inner.rerankHybrid(
|
|
query,
|
|
await fromRecordBatchToBuffer(vecResults),
|
|
await fromRecordBatchToBuffer(ftsResults),
|
|
);
|
|
const recordBatch = await fromBufferToRecordBatch(buffer);
|
|
|
|
return recordBatch as RecordBatch;
|
|
}
|
|
}
|