Skip to content

Commit e67bcb4

Browse files
committed
MLE-20906 : Update Node Client based on changes to functions in Optic
1 parent f57dc15 commit e67bcb4

File tree

3 files changed

+86
-12
lines changed

3 files changed

+86
-12
lines changed

lib/plan-builder-base.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ function castArg(arg, funcName, paramName, argPos, paramTypes) {
401401
}
402402
});
403403
return true;
404+
case 'PlanAnnTopKOptions':
405+
const planAnnTopKOptionsSet = new Set(['maxDistance', 'max-distance', 'searchFactor','search-factor']);
406+
if(Object.getPrototypeOf(arg) === Map.prototype){
407+
arg.forEach((value, key) => {
408+
if(!planAnnTopKOptionsSet.has(key)) {
409+
throw new Error(
410+
`${argLabel(funcName, paramName, argPos)} has invalid key- ${key}`
411+
);
412+
}
413+
});
414+
}
415+
return true;
404416
default:
405417
return false;
406418
}
@@ -428,7 +440,7 @@ function castArg(arg, funcName, paramName, argPos, paramTypes) {
428440
break;
429441
case 'string':
430442
if (isProtoChained(paramTypes, [types.XsAnyAtomicType, types.TextNode, types.JsonContentNode, types.XmlContentNode,
431-
types.XsString])) {
443+
types.XsString, types.ServerType])) {
432444
return arg;
433445
}
434446
break;

lib/plan-builder-generated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8089,7 +8089,7 @@ shortestPath(...args) {
80898089
*/
80908090
annTopK(...args) {
80918091
const namer = bldrbase.getNamer(args, 'inputK');
8092-
const paramdefs = [['inputK', [types.XsInteger, PlanParam], true, false], ['vectorColumn', [PlanExprCol, PlanColumn, types.XsString], true, false], ['queryVector', [PlanParam, types.VecVector], true, false], ['distanceColumn', [PlanExprCol, PlanColumn, types.XsString], false, false], ['options', [PlanAnnTopKOptions], false, false]];
8092+
const paramdefs = [['inputK', [types.XsInteger, PlanParam], true, false], ['vectorColumn', [PlanExprCol, PlanColumn, types.XsString], true, false], ['queryVector', [PlanParam, types.VecVector], true, false], ['distanceColumn', [PlanExprCol, PlanColumn, types.XsString], false, false], ['options', [PlanAnnTopKOptions], false, true]];
80938093
const checkedArgs = (namer !== null) ?
80948094
bldrbase.makeNamedArgs(namer, 'PlanModifyPlan.annTopK', 3, new Set(['inputK', 'vectorColumn', 'queryVector', 'distanceColumn', 'options']), paramdefs, args) :
80958095
bldrbase.makePositionalArgs('PlanModifyPlan.annTopK', 3, false, paramdefs, args);

test-basic/annTopK.js

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let serverConfiguration = {};
1313
const execPlan = pbb.execPlan;
1414

1515
describe('tests for annTopK', function () {
16+
this.timeout(5000)
1617
before(function (done) {
1718
try {
1819
testlib.findServerConfiguration(serverConfiguration);
@@ -27,22 +28,83 @@ describe('tests for annTopK', function () {
2728
}
2829
});
2930

30-
it('happy path', function (done) {
31+
it('annTopK without PlanAnnTopKOptions', function (done) {
3132
execPlan(p
3233
.fromView('vectors', 'persons', '')
33-
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'), 0.5)
34+
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'))
3435
.orderBy(p.col('name'))
3536
)
3637
.then(function (response) {
37-
const rows = response.rows;
38-
assert(rows.length === 2, 'Expecting both rows in the view to be returned.');
39-
assert(rows[0].name.value === 'Alice');
40-
assert(rows[0].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
41-
assert(rows[1].name.value === 'Bob');
42-
assert(rows[1].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
43-
done();
38+
verifyResults(response.rows, done);
39+
})
40+
.catch(error => done(error));
41+
});
42+
43+
it('annTopK with PlanAnnTopKOptions as a single string', function (done) {
44+
execPlan(p
45+
.fromView('vectors', 'persons', '')
46+
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'), 'onlyIndex')
47+
.orderBy(p.col('name'))
48+
)
49+
.then(function (response) {
50+
verifyResults(response.rows, done);
4451
})
45-
.catch(done);
52+
.catch(error => done(error));
53+
});
54+
55+
it('annTopK with PlanAnnTopKOptions as an array of string', function (done) {
56+
execPlan(p
57+
.fromView('vectors', 'persons', '')
58+
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
59+
['onlyIndex', "maxDistance=0.15", "searchFactor=1.0"])
60+
.orderBy(p.col('name'))
61+
).then(function (response) {
62+
verifyResults(response.rows, done);
63+
}).catch(error => done(error));
4664
});
4765

66+
it('annTopK with PlanAnnTopKOptions as a map', function (done) {
67+
const planAnnTopKOptionsMap = new Map();
68+
planAnnTopKOptionsMap.set("maxDistance", 0.158454656600952);
69+
planAnnTopKOptionsMap.set("searchFactor", 10.0);
70+
execPlan(p
71+
.fromView('vectors', 'persons', '')
72+
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
73+
planAnnTopKOptionsMap)
74+
.orderBy(p.col('name'))
75+
)
76+
.then(function (response) {
77+
verifyResults(response.rows, done);
78+
})
79+
.catch(error => done(error));
80+
});
81+
82+
it('annTopK with invalid PlanAnnTopKOptions', function (done) {
83+
const planAnnTopKOptionsMap = new Map();
84+
planAnnTopKOptionsMap.set('invalid', 10.0);
85+
try{
86+
execPlan(p
87+
.fromView('vectors', 'persons', '')
88+
.annTopK(10, p.col('embedding'), p.vec.vector([1.1, 2.2, 3.3]), p.col('distance'),
89+
planAnnTopKOptionsMap)
90+
.orderBy(p.col('name'))
91+
);
92+
} catch(error){
93+
assert(error.message.toString().includes('options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid'))
94+
done();
95+
}
96+
});
97+
98+
function verifyResults(rows, done){
99+
try {
100+
assert(rows.length === 2, 'Expecting both rows in the view to be returned.');
101+
assert(rows[0].name.value === 'Alice');
102+
assert(rows[0].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
103+
assert(rows[1].name.value === 'Bob');
104+
assert(rows[1].distance.type === 'xs:float', 'Verifying that the distance column was populated.');
105+
done();
106+
} catch (error){
107+
done(error)
108+
}
109+
}
48110
});

0 commit comments

Comments
 (0)