@datastax/astra-db-ts
Version:
Data API TypeScript client
110 lines (109 loc) • 3.99 kB
JavaScript
// Copyright Datastax, Inc
// SPDX-License-Identifier: Apache-2.0
import { AbstractCursor } from '../../documents/cursors/abstract-cursor.js';
import { $CustomInspect } from '../../lib/constants.js';
import { FLCInternal } from '../../documents/cursors/flc-internal.js';
export 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;
}
}
export class FindAndRerankCursor extends 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 FLCInternal(this, parent, serdes, filter, options);
this._currentPage = initialPage;
}
[$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);
}
rerankOverride(rerank) {
return this._internal.withOption('rerank', rerank);
}
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;
}
}
Object.defineProperty(FindAndRerankCursor, "InternalNextPageOptions", {
enumerable: true,
configurable: true,
writable: true,
value: {
commandName: 'findAndRerank',
commandOptions: ['limit', 'hybridLimits', 'rerankOn', 'rerankQuery', 'includeScores', 'includeSortVector', 'rerank'],
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,
};
},
}
});