Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/collections/serialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1678,7 +1680,6 @@ export class Serialize {
out.conditions.push(condProto);
}

console.error(JSON.stringify(out));
return out;
};

Expand Down
72 changes: 71 additions & 1 deletion src/collections/serialize/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
Loading