diff --git a/src/collections/serialize/index.ts b/src/collections/serialize/index.ts index a2c5092c..41fe93e4 100644 --- a/src/collections/serialize/index.ts +++ b/src/collections/serialize/index.ts @@ -1642,23 +1642,25 @@ export class Serialize { }; break; case 'timeDecay': { - const { curve, ...timeDecay } = func as TimeDecay; + const { curve, decay, ...timeDecay } = func as TimeDecay; condProto = { ...condProto, timeDecay: Boost_TimeDecayFunction.fromPartial({ ...timeDecay, curve: this.boostCurve(curve), + decayValue: decay, }), }; break; } case 'numericDecay': { - const { curve, ...numericDecay } = func as NumericDecay; + const { curve, decay, ...numericDecay } = func as NumericDecay; condProto = { ...condProto, numericDecay: Boost_NumericDecayFunction.fromPartial({ ...numericDecay, curve: this.boostCurve(curve), + decayValue: decay, }), }; break; @@ -1678,7 +1680,6 @@ export class Serialize { out.conditions.push(condProto); } - console.error(JSON.stringify(out)); return out; }; diff --git a/src/collections/serialize/unit.test.ts b/src/collections/serialize/unit.test.ts index b8915e43..34ccec11 100644 --- a/src/collections/serialize/unit.test.ts +++ b/src/collections/serialize/unit.test.ts @@ -34,7 +34,7 @@ import { Targets, } from '../../proto/v1/base_search.js'; import { GenerativeSearch } from '../../proto/v1/generative.js'; -import { GroupBy, MetadataRequest, PropertiesRequest } from '../../proto/v1/search_get.js'; +import { Boost_DecayCurve, GroupBy, MetadataRequest, PropertiesRequest } from '../../proto/v1/search_get.js'; import { Filters as FiltersFactory } from '../filters/classes.js'; import filter from '../filters/index.js'; import { Bm25OperatorOptions, TargetVectorInputType } from '../query/types.js'; @@ -1032,6 +1032,76 @@ describe('Unit testing of Serialize', () => { }); }); }); + + describe('.boostGRPC', () => { + it('should serialize a TimeDecay boost to the full proto shape with decay mapped to decayValue', () => { + const out = Serialize.boostGRPC({ + conditions: [ + { + func: { + type: 'timeDecay', + property: 'createdAt', + scale: '35d', + origin: '2024-01-01T00:00:00Z', + curve: 'exponential', + decay: 0.2, + }, + }, + ], + }); + expect(out).toEqual({ + weight: undefined, + depth: undefined, + conditions: [ + { + weight: undefined, + timeDecay: { + property: 'createdAt', + origin: '2024-01-01T00:00:00Z', + scale: '35d', + offset: undefined, + curve: Boost_DecayCurve.DECAY_CURVE_EXPONENTIAL, + decayValue: 0.2, + }, + }, + ], + }); + }); + + it('should serialize a NumericDecay boost to the full proto shape with decay mapped to decayValue', () => { + const out = Serialize.boostGRPC({ + conditions: [ + { + func: { + type: 'numericDecay', + property: 'rating', + scale: 10, + origin: 0, + curve: 'linear', + decay: 0.5, + }, + }, + ], + }); + expect(out).toEqual({ + weight: undefined, + depth: undefined, + conditions: [ + { + weight: undefined, + numericDecay: { + property: 'rating', + origin: 0, + scale: 10, + offset: undefined, + curve: Boost_DecayCurve.DECAY_CURVE_LINEAR, + decayValue: 0.5, + }, + }, + ], + }); + }); + }); }); describe('Unit testing of DataGuards', () => {