weaviate-client
Version:
JS/TS client for Weaviate
155 lines (154 loc) • 4.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Diversity = exports.Bm25Operator = exports.Boost = exports.TargetVectorInputGuards = exports.ArrayInputGuards = exports.NearVectorInputGuards = void 0;
const errors_js_1 = require("../../errors.js");
class NearVectorInputGuards {
static is1D(input) {
return Array.isArray(input) && input.length > 0 && !Array.isArray(input[0]);
}
static is2D(input) {
return Array.isArray(input) && input.length > 0 && Array.isArray(input[0]) && input[0].length > 0;
}
static isObject(input) {
return !Array.isArray(input);
}
static isListOf1D(input) {
const i = input;
return !Array.isArray(input) && i.kind === 'listOfVectors' && i.dimensionality == '1D';
}
static isListOf2D(input) {
const i = input;
return !Array.isArray(input) && i.kind === 'listOfVectors' && i.dimensionality == '2D';
}
}
exports.NearVectorInputGuards = NearVectorInputGuards;
class ArrayInputGuards {
static is1DArray(input) {
return Array.isArray(input) && input.length > 0 && !Array.isArray(input[0]);
}
static is2DArray(input) {
return Array.isArray(input) && input.length > 0 && Array.isArray(input[0]);
}
}
exports.ArrayInputGuards = ArrayInputGuards;
class TargetVectorInputGuards {
static isSingle(input) {
return typeof input === 'string';
}
static isMulti(input) {
return Array.isArray(input);
}
static isMultiJoin(input) {
const i = input;
return i.combination !== undefined && i.targetVectors !== undefined;
}
}
exports.TargetVectorInputGuards = TargetVectorInputGuards;
class Boost {
static filter(filter, args) {
return {
...args,
conditions: [
{
weight: args?.weight,
func: {
...filter,
type: 'filter',
},
},
],
};
}
static timeDecay(args) {
const { weight, depth, ...func } = args;
return {
conditions: [
{
weight,
func: {
...func,
type: 'timeDecay',
},
},
],
weight,
depth,
};
}
static numericDecay(args) {
const { weight, depth, ...func } = args;
return {
conditions: [
{
weight,
func: {
...func,
type: 'numericDecay',
},
},
],
weight,
depth,
};
}
static numericProperty(args) {
const { weight, depth, ...func } = args;
return {
conditions: [
{
weight,
func: {
...func,
type: 'propertyValue',
},
},
],
weight,
depth,
};
}
static blend(boosts, options) {
const out = { ...options, conditions: [] };
for (const boost of boosts) {
if (boost.depth) {
throw new errors_js_1.WeaviateInvalidInputError('A boost passed to Boost.blend() cannot set its own depth.');
}
for (let cond of boost.conditions) {
if (!cond.weight && boost.weight) {
cond = {
...cond,
weight: boost.weight,
};
}
out.conditions.push({ ...cond });
}
}
return out;
}
}
exports.Boost = Boost;
class Bm25Operator {
static and(opts) {
return { ...opts, operator: 'And' };
}
static andCross(opts) {
return { ...opts, operator: 'AndCross' };
}
static or(opts) {
return { ...opts, operator: 'Or' };
}
}
exports.Bm25Operator = Bm25Operator;
class Diversity {
/** Use Maximal Marginal Relevance diversity selection. */
static mmr(args) {
return {
...args,
type: 'mmr',
};
}
static isMMR(args) {
return args.type === 'mmr';
}
}
exports.Diversity = Diversity;