@datastax/astra-db-ts
Version:
Data API TypeScript client
112 lines (111 loc) • 4.17 kB
JavaScript
"use strict";
// Copyright Datastax, Inc
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.FindAndRerankCursor = exports.RerankedResult = void 0;
const abstract_cursor_js_1 = require("../../documents/cursors/abstract-cursor.js");
const constants_js_1 = require("../../lib/constants.js");
const flc_internal_js_1 = require("../../documents/cursors/flc-internal.js");
class RerankedResult {
constructor(document, scores) {
Object.defineProperty(this, "document", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "scores", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.document = document;
this.scores = scores;
}
}
exports.RerankedResult = RerankedResult;
class FindAndRerankCursor extends abstract_cursor_js_1.AbstractCursor {
constructor(parent, serdes, filter, options, mapping, initialPage) {
super(options ?? {}, mapping);
Object.defineProperty(this, "_internal", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._internal = new flc_internal_js_1.FLCInternal(this, parent, serdes, filter, options);
this._currentPage = initialPage;
}
[constants_js_1.$CustomInspect]() {
return `${this.constructor.name}(source="${this._internal._parent.keyspace}.${this._internal._parent.name}",state="${this._state}",consumed=${this.consumed()},buffered=${this.buffered()})`;
}
filter(filter) {
return this._internal.withFilter(filter);
}
sort(sort) {
return this._internal.withSort(sort);
}
limit(limit) {
return this._internal.withOption('limit', limit || undefined);
}
hybridLimits(hybridLimits) {
return this._internal.withOption('hybridLimits', hybridLimits);
}
rerankOn(rerankOn) {
return this._internal.withOption('rerankOn', rerankOn);
}
rerankQuery(rerankQuery) {
return this._internal.withOption('rerankQuery', rerankQuery);
}
includeScores(includeScores) {
return this._internal.withOption('includeScores', includeScores ?? true);
}
includeSortVector(includeSortVector) {
return this._internal.withOption('includeSortVector', includeSortVector ?? true);
}
project(projection) {
return this._internal.withPreMapOption('projection', projection);
}
map(map) {
return this._internal.withMap(map);
}
initialPageState(initialPageState) {
return this._internal.withInitialPageState(initialPageState);
}
async getSortVector() {
return this._internal.getSortVector();
}
clone() {
return this._internal.freshClone();
}
async fetchNextPage() {
return this._internal.fetchNextPageMapped(FindAndRerankCursor.InternalNextPageOptions);
}
async _fetchNextPage(extra, tm) {
return this._internal.fetchNextPageRaw(extra, tm, FindAndRerankCursor.InternalNextPageOptions);
}
_tm() {
return this._internal._httpClient.tm;
}
}
exports.FindAndRerankCursor = FindAndRerankCursor;
Object.defineProperty(FindAndRerankCursor, "InternalNextPageOptions", {
enumerable: true,
configurable: true,
writable: true,
value: {
commandName: 'findAndRerank',
commandOptions: ['limit', 'hybridLimits', 'rerankOn', 'rerankQuery', 'includeScores', 'includeSortVector'],
mapPage(page, raw) {
for (let i = 0, n = page.result.length; i < n; i++) {
page.result[i] = new RerankedResult(page.result[i], raw.status?.documentResponses?.[i]?.scores ?? {});
}
return {
nextPageState: page.nextPageState,
result: page.result,
sortVector: page.sortVector,
};
},
}
});