From 5a3af57367c7d50193499246e0c0bcb95103c9b2 Mon Sep 17 00:00:00 2001 From: Parker Duckworth Date: Fri, 1 Jul 2022 12:22:56 -0500 Subject: [PATCH] add distance as user-facing similarity metric --- graphql/ask.js | 15 +++ graphql/getter.test.js | 269 +++++++++++++++++++++++++++++++++++++-- graphql/journey.test.js | 274 +++++++++++++++++++++++++++++++++++++--- graphql/nearImage.js | 15 +++ graphql/nearObject.js | 15 +++ graphql/nearText.js | 15 +++ graphql/nearVector.js | 15 +++ 7 files changed, 592 insertions(+), 26 deletions(-) diff --git a/graphql/ask.js b/graphql/ask.js index d69eaf5..63c5df7 100644 --- a/graphql/ask.js +++ b/graphql/ask.js @@ -21,6 +21,10 @@ export default class GraphQLAsk { args = [...args, `certainty:${this.certainty}`]; } + if (this.distance) { + args = [...args, `distance:${this.distance}`]; + } + if (this.autocorrect !== undefined) { args = [...args, `autocorrect:${this.autocorrect}`]; } @@ -53,6 +57,9 @@ export default class GraphQLAsk { case "certainty": this.parseCertainty(this.source[key]); break; + case "distance": + this.parseDistance(this.source[key]); + break; case "autocorrect": this.parseAutocorrect(this.source[key]); break; @@ -89,6 +96,14 @@ export default class GraphQLAsk { this.certainty = cert; } + parseDistance(dist) { + if (typeof dist !== "number") { + throw new Error("ask filter: distance must be a number"); + } + + this.distance = dist; + } + parseAutocorrect(autocorrect) { if (typeof autocorrect !== "boolean") { throw new Error("ask filter: autocorrect must be a boolean"); diff --git a/graphql/getter.test.js b/graphql/getter.test.js index 4083cfe..54b1a6f 100644 --- a/graphql/getter.test.js +++ b/graphql/getter.test.js @@ -220,7 +220,7 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("with optional parameters", () => { + test("with optional parameters (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -244,7 +244,31 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("with optional parameters and autocorrect", () => { + test("with optional parameters (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + + `(nearText:{concepts:["foo","bar"],distance:0.3,moveTo:{concepts:["foo"],force:0.7},moveAwayFrom:{concepts:["bar"],force:0.5}})` + + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearText({ + concepts: ["foo", "bar"], + distance: 0.3, + moveTo: { concepts: ["foo"], force: 0.7 }, + moveAwayFrom: { concepts: ["bar"], force: 0.5 }, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + + test("with optional parameters and autocorrect (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -269,6 +293,31 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); + test("with optional parameters and autocorrect (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + + `(nearText:{concepts:["foo","bar"],distance:0.7,moveTo:{concepts:["foo"],force:0.7},moveAwayFrom:{concepts:["bar"],force:0.5},autocorrect:true})` + + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearText({ + concepts: ["foo", "bar"], + distance: 0.7, + moveTo: { concepts: ["foo"], force: 0.7 }, + moveAwayFrom: { concepts: ["bar"], force: 0.5 }, + autocorrect: true, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + test("a query with a valid nearText and autocorrect set to false", () => { const mockClient = { query: jest.fn(), @@ -286,7 +335,7 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("with moveTo with objects parameter", () => { + test("with moveTo with objects parameter (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -309,7 +358,30 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("with moveAwayFrom with objects parameter", () => { + test("with moveTo with objects parameter (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + + `(nearText:{concepts:["foo","bar"],distance:0.7,moveTo:{objects:[{id:"uuid"},{beacon:"beacon"}],force:0.7}})` + + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearText({ + concepts: ["foo", "bar"], + distance: 0.7, + moveTo: { force: 0.7, objects: [{ id: "uuid" }, {beacon: "beacon"}] }, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + + test("with moveAwayFrom with objects parameter (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -332,7 +404,30 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("with moveTo and moveAway with objects parameter", () => { + test("with moveAwayFrom with objects parameter (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + + `(nearText:{concepts:["foo","bar"],distance:0.7,moveAwayFrom:{objects:[{id:"uuid"},{beacon:"beacon"}],force:0.7}})` + + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearText({ + concepts: ["foo", "bar"], + distance: 0.7, + moveAwayFrom: { force: 0.7, objects: [{ id: "uuid" }, {beacon: "beacon"}] }, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + + test("with moveTo and moveAway with objects parameter (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -356,6 +451,30 @@ describe("nearText searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); + test("with moveTo and moveAway with objects parameter (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + + `(nearText:{concepts:["foo","bar"],distance:0.7,moveTo:{objects:[{id:"uuid"}],force:0.7},moveAwayFrom:{objects:[{beacon:"beacon"}],force:0.5}})` + + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearText({ + concepts: ["foo", "bar"], + distance: 0.7, + moveTo: { force: 0.7, objects: [{ id: "uuid" }] }, + moveAwayFrom: { force: 0.5, objects: [{ beacon: "beacon" }] }, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + describe("queries with invalid nearText searchers", () => { const mockClient = { query: jest.fn(), @@ -377,6 +496,11 @@ describe("nearText searchers", () => { nearText: { concepts: ["foo"], certainty: "foo" }, msg: "nearText filter: certainty must be a number", }, + { + title: "distance of wrong type", + nearText: { concepts: ["foo"], distance: "foo" }, + msg: "nearText filter: distance must be a number", + }, { title: "moveTo empty object", nearText: { concepts: ["foo"], moveTo: {} }, @@ -510,7 +634,7 @@ describe("nearVector searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("with optional parameters", () => { + test("with optional parameters (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -532,6 +656,28 @@ describe("nearVector searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); + test("with optional parameters (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + + `(nearVector:{vector:[0.1234,0.9876],distance:0.7})` + + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearVector({ + vector: [0.1234, 0.9876], + distance: 0.7, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + describe("queries with invalid nearVector searchers", () => { const mockClient = { query: jest.fn(), @@ -558,6 +704,11 @@ describe("nearVector searchers", () => { nearVector: { vector: [0.123, 0.987], certainty: "foo" }, msg: "nearVector filter: certainty must be a number", }, + { + title: "distance of wrong type", + nearVector: { vector: [0.123, 0.987], distance: "foo" }, + msg: "nearVector filter: distance must be a number", + }, ]; tests.forEach((t) => { @@ -611,7 +762,7 @@ describe("nearObject searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("a query with a valid nearObject with all params", () => { + test("a query with a valid nearObject with all params (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -632,6 +783,27 @@ describe("nearObject searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); + test("a query with a valid nearObject with all params (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + `(nearObject:{id:"some-uuid",beacon:"weaviate/some-uuid",distance:0.7})` + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearObject({ + id: "some-uuid", + beacon: "weaviate/some-uuid", + distance: 0.7 + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + describe("queries with invalid nearObject searchers", () => { const mockClient = { query: jest.fn(), @@ -657,6 +829,11 @@ describe("nearObject searchers", () => { title: "certainty of wrong type", nearObject: { id: "foo", certainty: "foo" }, msg: "nearObject filter: certainty must be a number", + }, + { + title: "distance of wrong type", + nearObject: { id: "foo", distance: "foo" }, + msg: "nearObject filter: distance must be a number", } ]; @@ -732,7 +909,28 @@ describe("ask searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("a query with a valid ask with all params", () => { + test("a query with a valid ask with question, properties, distance", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + `(ask:{question:"What is Weaviate?",properties:["prop1","prop2"],distance:0.8})` + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withAsk({ + question: "What is Weaviate?", + properties: ["prop1", "prop2"], + distance: 0.8, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + + test("a query with a valid ask with all params (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -755,6 +953,29 @@ describe("ask searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); + test("a query with a valid ask with all params (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + `(ask:{question:"What is Weaviate?",properties:["prop1","prop2"],distance:0.8,autocorrect:true,rerank:true})` + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withAsk({ + question: "What is Weaviate?", + properties: ["prop1", "prop2"], + distance: 0.8, + autocorrect: true, + rerank: true, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + test("a query with a valid ask with question and autocorrect", () => { const mockClient = { query: jest.fn(), @@ -849,6 +1070,11 @@ describe("ask searchers", () => { ask: { question: "foo", certainty: "foo" }, msg: "ask filter: certainty must be a number", }, + { + title: "distance of wrong type", + ask: { question: "foo", distance: "foo" }, + msg: "ask filter: distance must be a number", + }, { title: "autocorrect of wrong type", ask: { question: "foo", autocorrect: "foo" }, @@ -890,7 +1116,7 @@ describe("nearImage searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); - test("a query with a valid nearImage with all params", () => { + test("a query with a valid nearImage with all params (with certainty)", () => { const mockClient = { query: jest.fn(), }; @@ -910,6 +1136,26 @@ describe("nearImage searchers", () => { expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); }); + test("a query with a valid nearImage with all params (with distance)", () => { + const mockClient = { + query: jest.fn(), + }; + + const expectedQuery = + `{Get{Person` + `(nearImage:{image:"iVBORw0KGgoAAAANS",distance:0.8})` + `{name}}}`; + + new Getter(mockClient) + .withClassName("Person") + .withFields("name") + .withNearImage({ + image: "iVBORw0KGgoAAAANS", + distance: 0.8, + }) + .do(); + + expect(mockClient.query).toHaveBeenCalledWith(expectedQuery); + }); + test("a query with a valid nearImage with base64 encoded image", () => { const mockClient = { query: jest.fn(), @@ -947,6 +1193,11 @@ describe("nearImage searchers", () => { title: "certainty of wrong type", nearImage: { image: "foo", certainty: "foo" }, msg: "nearImage filter: certainty must be a number", + }, + { + title: "distance of wrong type", + nearImage: { image: "foo", distance: "foo" }, + msg: "nearImage filter: distance must be a number", } ]; diff --git a/graphql/journey.test.js b/graphql/journey.test.js index ba9c480..b6ee489 100644 --- a/graphql/journey.test.js +++ b/graphql/journey.test.js @@ -23,7 +23,7 @@ describe("the graphql journey", () => { }); }); - test("graphql get method with optional fields", () => { + test("graphql get method with optional fields (with certainty)", () => { return client.graphql .get() .withClassName("Article") @@ -46,6 +46,29 @@ describe("the graphql journey", () => { }); }); + test("graphql get method with optional fields (with distance)", () => { + return client.graphql + .get() + .withClassName("Article") + .withFields("title url wordCount") + .withNearText({ concepts: ["news"], distance: 0.9 }) + .withWhere({ + operator: Operator.GREATER_THAN_EQUAL, + path: ["wordCount"], + valueInt: 50, + }) + .withLimit(7) + .do() + .then(function (result) { + expect(result.data.Get.Article.length).toBeLessThan(3); + expect(result.data.Get.Article[0]["title"].length).toBeGreaterThan(0); + expect(result.data.Get.Article[0]["url"].length).toBeGreaterThan(0); + expect(result.data.Get.Article[0]["wordCount"]).toBeGreaterThanOrEqual( + 50 + ); + }); + }); + test("graphql get with group", () => { return client.graphql .get() @@ -61,7 +84,7 @@ describe("the graphql journey", () => { }); }); - test("graphql get with nearVector", () => { + test("graphql get with nearVector (with certainty)", () => { var searchVec = [-0.15047126, 0.061322376, -0.17812507, 0.12811552, 0.36847013, -0.50840724, -0.10406531, 0.11413283, 0.2997712, 0.7039331, 0.22155242, 0.1413957, 0.025396502, 0.14802167, 0.26640236, 0.15965445, -0.45570126, -0.5215438, 0.14628491, 0.10946681, 0.0040095793, 0.017442623, -0.1988451, -0.05362646, 0.104278944, -0.2506941, 0.2667653, 0.36438593, -0.44370207, 0.07204353, 0.077371456, 0.14557181, 0.6026817, 0.45073593, 0.09438019, 0.03936342, -0.20441438, 0.12333719, -0.20247602, 0.5078446, -0.06079732, -0.02166342, 0.02165861, -0.11712191, 0.0493167, -0.012123002, 0.26458082, -0.10784768, -0.26852348, 0.049759883, -0.39999008, -0.08977922, 0.003169497, -0.36184034, -0.069065355, 0.18940343, 0.5684866, -0.24626277, -0.2326087, 0.090373255, 0.33161184, -1.0541122, -0.039116446, -0.17496277, -0.16834813, -0.0765323, -0.16189013, -0.062876746, -0.19826415, 0.07437007, -0.018362755, 0.23634757, -0.19062655, -0.26524994, 0.33691254, -0.1926698, 0.018848037, 0.1735524, 0.34301907, -0.014238952, -0.07596742, -0.61302894, -0.044652265, 0.1545376, 0.67256856, 0.08630557, 0.50236076, 0.23438522, 0.27686095, 0.13633616, -0.27525797, 0.04282576, 0.18319897, -0.008353968, -0.27330264, 0.12624736, -0.17051372, -0.35854533, -0.008455927, 0.154786, -0.20306401, -0.09021733, 0.80594194, 0.036562894, -0.48894945, -0.27981675, -0.5001396, -0.3581464, -0.057082724, -0.0051904973, -0.3209166, 0.057098284, 0.111587055, -0.09097725, -0.213181, -0.5038173, -0.024070809, -0.05350453, 0.13345918, -0.42136985, 0.24050911, -0.2556207, 0.03156968, 0.4381214, 0.053237516, -0.20783865, 1.885739, 0.28429136, -0.12231187, -0.30934808, 0.032250155, -0.32959512, 0.08670603, -0.60112613, -0.43010503, 0.70870006, 0.3548015, -0.010406012, 0.036294986, 0.0030629474, -0.017579105, 0.28948352, -0.48063236, -0.39739868, 0.17860937, 0.5099417, -0.24304488, -0.12671146, -0.018249692, -0.32057074, -0.08146134, 0.3572229, -0.47601065, 0.35100546, -0.19663939, 0.34194613, -0.04653828, 0.47278664, -0.8723091, -0.19756387, -0.5890681, 0.16688067, -0.23709822, -0.26478595, -0.18792373, 0.2204168, 0.030987943, 0.15885714, -0.38817936, -0.4194334, -0.3287098, 0.15394142, -0.09496768, 0.6561987, -0.39340565, -0.5479265, -0.22363484, -0.1193662, 0.2014849, 0.31138006, -0.45485613, -0.9879565, 0.3708223, 0.17318928, 0.21229307, 0.042776756, -0.077399045, 0.42621315, -0.09917796, 0.34220153, 0.06380378, 0.14129028, -0.14563583, -0.07081333, 0.026335392, 0.10566285, -0.28074324, -0.059861198, -0.24855351, 0.13623764, -0.8228192, -0.15095113, 0.16250934, 0.031107651, -0.1504525, 0.20840737, 0.12919411, -0.0926323, 0.30937102, 0.16636328, -0.36754072, 0.035581365, -0.2799259, 0.1446048, -0.11680267, 0.13226685, 0.175023, -0.18840964, 0.27609056, -0.09350581, 0.08284562, 0.45897093, 0.13188471, -0.07115303, 0.18009436, 0.16689545, -0.6991295, 0.26496106, -0.29619592, -0.19242188, -0.6362671, -0.16330126, 0.2474778, 0.37738156, -0.12921557, -0.07843309, 0.28509396, 0.5658691, 0.16096894, 0.095068075, 0.02419672, -0.30691084, 0.21180221, 0.21670066, 0.0027263877, 0.30853105, -0.16187873, 0.20786561, 0.22136153, -0.008828387, -0.011165021, 0.60076475, 0.0089871045, 0.6179727, -0.38049766, -0.08179336, -0.15306218, -0.13186441, -0.5360041, -0.06123339, -0.06399122, 0.21292226, -0.18383273, -0.21540102, 0.28566808, -0.29953584, -0.36946672, 0.03341637, -0.08435299, -0.5381947, -0.28651953, 0.08704594, -0.25493965, 0.0019178925, -0.7242109, 0.3578676, -0.55617595, -0.01930952, 0.32922924, 0.14903364, 0.21613406, -0.11927183, 0.15165499, -0.10101261, 0.2499076, -0.18526322, -0.057230365, 0.10008554, 0.16178907, 0.39356324, -0.03106238, 0.09375929, 0.17185533, 0.10400415, -0.36850816, 0.18424486, -0.081376314, 0.23645392, 0.05198973, 0.09471436]; return client.graphql @@ -76,7 +99,22 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql get with nearObject", () => { + test("graphql get with nearVector (with distance)", () => { + var searchVec = [-0.15047126, 0.061322376, -0.17812507, 0.12811552, 0.36847013, -0.50840724, -0.10406531, 0.11413283, 0.2997712, 0.7039331, 0.22155242, 0.1413957, 0.025396502, 0.14802167, 0.26640236, 0.15965445, -0.45570126, -0.5215438, 0.14628491, 0.10946681, 0.0040095793, 0.017442623, -0.1988451, -0.05362646, 0.104278944, -0.2506941, 0.2667653, 0.36438593, -0.44370207, 0.07204353, 0.077371456, 0.14557181, 0.6026817, 0.45073593, 0.09438019, 0.03936342, -0.20441438, 0.12333719, -0.20247602, 0.5078446, -0.06079732, -0.02166342, 0.02165861, -0.11712191, 0.0493167, -0.012123002, 0.26458082, -0.10784768, -0.26852348, 0.049759883, -0.39999008, -0.08977922, 0.003169497, -0.36184034, -0.069065355, 0.18940343, 0.5684866, -0.24626277, -0.2326087, 0.090373255, 0.33161184, -1.0541122, -0.039116446, -0.17496277, -0.16834813, -0.0765323, -0.16189013, -0.062876746, -0.19826415, 0.07437007, -0.018362755, 0.23634757, -0.19062655, -0.26524994, 0.33691254, -0.1926698, 0.018848037, 0.1735524, 0.34301907, -0.014238952, -0.07596742, -0.61302894, -0.044652265, 0.1545376, 0.67256856, 0.08630557, 0.50236076, 0.23438522, 0.27686095, 0.13633616, -0.27525797, 0.04282576, 0.18319897, -0.008353968, -0.27330264, 0.12624736, -0.17051372, -0.35854533, -0.008455927, 0.154786, -0.20306401, -0.09021733, 0.80594194, 0.036562894, -0.48894945, -0.27981675, -0.5001396, -0.3581464, -0.057082724, -0.0051904973, -0.3209166, 0.057098284, 0.111587055, -0.09097725, -0.213181, -0.5038173, -0.024070809, -0.05350453, 0.13345918, -0.42136985, 0.24050911, -0.2556207, 0.03156968, 0.4381214, 0.053237516, -0.20783865, 1.885739, 0.28429136, -0.12231187, -0.30934808, 0.032250155, -0.32959512, 0.08670603, -0.60112613, -0.43010503, 0.70870006, 0.3548015, -0.010406012, 0.036294986, 0.0030629474, -0.017579105, 0.28948352, -0.48063236, -0.39739868, 0.17860937, 0.5099417, -0.24304488, -0.12671146, -0.018249692, -0.32057074, -0.08146134, 0.3572229, -0.47601065, 0.35100546, -0.19663939, 0.34194613, -0.04653828, 0.47278664, -0.8723091, -0.19756387, -0.5890681, 0.16688067, -0.23709822, -0.26478595, -0.18792373, 0.2204168, 0.030987943, 0.15885714, -0.38817936, -0.4194334, -0.3287098, 0.15394142, -0.09496768, 0.6561987, -0.39340565, -0.5479265, -0.22363484, -0.1193662, 0.2014849, 0.31138006, -0.45485613, -0.9879565, 0.3708223, 0.17318928, 0.21229307, 0.042776756, -0.077399045, 0.42621315, -0.09917796, 0.34220153, 0.06380378, 0.14129028, -0.14563583, -0.07081333, 0.026335392, 0.10566285, -0.28074324, -0.059861198, -0.24855351, 0.13623764, -0.8228192, -0.15095113, 0.16250934, 0.031107651, -0.1504525, 0.20840737, 0.12919411, -0.0926323, 0.30937102, 0.16636328, -0.36754072, 0.035581365, -0.2799259, 0.1446048, -0.11680267, 0.13226685, 0.175023, -0.18840964, 0.27609056, -0.09350581, 0.08284562, 0.45897093, 0.13188471, -0.07115303, 0.18009436, 0.16689545, -0.6991295, 0.26496106, -0.29619592, -0.19242188, -0.6362671, -0.16330126, 0.2474778, 0.37738156, -0.12921557, -0.07843309, 0.28509396, 0.5658691, 0.16096894, 0.095068075, 0.02419672, -0.30691084, 0.21180221, 0.21670066, 0.0027263877, 0.30853105, -0.16187873, 0.20786561, 0.22136153, -0.008828387, -0.011165021, 0.60076475, 0.0089871045, 0.6179727, -0.38049766, -0.08179336, -0.15306218, -0.13186441, -0.5360041, -0.06123339, -0.06399122, 0.21292226, -0.18383273, -0.21540102, 0.28566808, -0.29953584, -0.36946672, 0.03341637, -0.08435299, -0.5381947, -0.28651953, 0.08704594, -0.25493965, 0.0019178925, -0.7242109, 0.3578676, -0.55617595, -0.01930952, 0.32922924, 0.14903364, 0.21613406, -0.11927183, 0.15165499, -0.10101261, 0.2499076, -0.18526322, -0.057230365, 0.10008554, 0.16178907, 0.39356324, -0.03106238, 0.09375929, 0.17185533, 0.10400415, -0.36850816, 0.18424486, -0.081376314, 0.23645392, 0.05198973, 0.09471436]; + + return client.graphql + .get() + .withClassName("Article") + .withNearVector({ vector: searchVec, distance: 0.3 }) + .withFields("_additional { id }") + .do() + .then((res) => { + expect(res.data.Get.Article.length).toBe(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql get with nearObject (with certainty)", () => { return client.graphql .get() .withClassName("Article") @@ -89,7 +127,20 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql get with nearText", () => { + test("graphql get with nearObject (with distance)", () => { + return client.graphql + .get() + .withClassName("Article") + .withNearObject({ id: "abefd256-8574-442b-9293-9205193737ee", distance: 0.3 }) + .withFields("_additional { id }") + .do() + .then((res) => { + expect(res.data.Get.Article.length).toBe(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql get with nearText (with certainty)", () => { return client.graphql .get() .withClassName("Article") @@ -102,7 +153,20 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql get with nearText with moveTo and moveAwayFrom", () => { + test("graphql get with nearText (with distance)", () => { + return client.graphql + .get() + .withClassName("Article") + .withNearText({ concepts: ["Article"], distance: 0.3 }) + .withFields("_additional { id }") + .do() + .then((res) => { + expect(res.data.Get.Article.length).toBe(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql get with nearText with moveTo and moveAwayFrom (with certainty)", () => { return client.graphql .get() .withClassName("Article") @@ -119,7 +183,24 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql get expected failure - multiple nearMedia filters", () => { + test("graphql get with nearText with moveTo and moveAwayFrom (with distance)", () => { + return client.graphql + .get() + .withClassName("Article") + .withNearText({ + concepts: ["Article"], distance: 0.3, + moveTo: { objects:[{ id: "abefd256-8574-442b-9293-9205193737e2" }], force: 0.7 }, + moveAwayFrom: { objects:[{ id: "abefd256-8574-442b-9293-9205193737e1" }], force: 0.5 }, + }) + .withFields("_additional { id }") + .do() + .then((res) => { + expect(res.data.Get.Article.length).toBe(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql get expected failure - multiple nearMedia filters (with certainty)", () => { return expect(() => { client.graphql .get() @@ -131,6 +212,18 @@ describe("the graphql journey", () => { .toThrow("cannot use multiple near filters in a single query") }); + test("graphql get expected failure - multiple nearMedia filters (with distance)", () => { + return expect(() => { + client.graphql + .get() + .withClassName("Article") + .withNearText({ concepts: ["iphone"] }) + .withNearObject({ id: "abefd256-8574-442b-9293-9205193737ee", distance: 0.35 }) + .do() + }) + .toThrow("cannot use multiple near filters in a single query") + }); + test("graphql aggregate method with minimal fields", () => { return client.graphql .aggregate() @@ -166,7 +259,7 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with nearVector", () => { + test("graphql aggregate method with nearVector (with certainty)", () => { var searchVec = [-0.15047126, 0.061322376, -0.17812507, 0.12811552, 0.36847013, -0.50840724, -0.10406531, 0.11413283, 0.2997712, 0.7039331, 0.22155242, 0.1413957, 0.025396502, 0.14802167, 0.26640236, 0.15965445, -0.45570126, -0.5215438, 0.14628491, 0.10946681, 0.0040095793, 0.017442623, -0.1988451, -0.05362646, 0.104278944, -0.2506941, 0.2667653, 0.36438593, -0.44370207, 0.07204353, 0.077371456, 0.14557181, 0.6026817, 0.45073593, 0.09438019, 0.03936342, -0.20441438, 0.12333719, -0.20247602, 0.5078446, -0.06079732, -0.02166342, 0.02165861, -0.11712191, 0.0493167, -0.012123002, 0.26458082, -0.10784768, -0.26852348, 0.049759883, -0.39999008, -0.08977922, 0.003169497, -0.36184034, -0.069065355, 0.18940343, 0.5684866, -0.24626277, -0.2326087, 0.090373255, 0.33161184, -1.0541122, -0.039116446, -0.17496277, -0.16834813, -0.0765323, -0.16189013, -0.062876746, -0.19826415, 0.07437007, -0.018362755, 0.23634757, -0.19062655, -0.26524994, 0.33691254, -0.1926698, 0.018848037, 0.1735524, 0.34301907, -0.014238952, -0.07596742, -0.61302894, -0.044652265, 0.1545376, 0.67256856, 0.08630557, 0.50236076, 0.23438522, 0.27686095, 0.13633616, -0.27525797, 0.04282576, 0.18319897, -0.008353968, -0.27330264, 0.12624736, -0.17051372, -0.35854533, -0.008455927, 0.154786, -0.20306401, -0.09021733, 0.80594194, 0.036562894, -0.48894945, -0.27981675, -0.5001396, -0.3581464, -0.057082724, -0.0051904973, -0.3209166, 0.057098284, 0.111587055, -0.09097725, -0.213181, -0.5038173, -0.024070809, -0.05350453, 0.13345918, -0.42136985, 0.24050911, -0.2556207, 0.03156968, 0.4381214, 0.053237516, -0.20783865, 1.885739, 0.28429136, -0.12231187, -0.30934808, 0.032250155, -0.32959512, 0.08670603, -0.60112613, -0.43010503, 0.70870006, 0.3548015, -0.010406012, 0.036294986, 0.0030629474, -0.017579105, 0.28948352, -0.48063236, -0.39739868, 0.17860937, 0.5099417, -0.24304488, -0.12671146, -0.018249692, -0.32057074, -0.08146134, 0.3572229, -0.47601065, 0.35100546, -0.19663939, 0.34194613, -0.04653828, 0.47278664, -0.8723091, -0.19756387, -0.5890681, 0.16688067, -0.23709822, -0.26478595, -0.18792373, 0.2204168, 0.030987943, 0.15885714, -0.38817936, -0.4194334, -0.3287098, 0.15394142, -0.09496768, 0.6561987, -0.39340565, -0.5479265, -0.22363484, -0.1193662, 0.2014849, 0.31138006, -0.45485613, -0.9879565, 0.3708223, 0.17318928, 0.21229307, 0.042776756, -0.077399045, 0.42621315, -0.09917796, 0.34220153, 0.06380378, 0.14129028, -0.14563583, -0.07081333, 0.026335392, 0.10566285, -0.28074324, -0.059861198, -0.24855351, 0.13623764, -0.8228192, -0.15095113, 0.16250934, 0.031107651, -0.1504525, 0.20840737, 0.12919411, -0.0926323, 0.30937102, 0.16636328, -0.36754072, 0.035581365, -0.2799259, 0.1446048, -0.11680267, 0.13226685, 0.175023, -0.18840964, 0.27609056, -0.09350581, 0.08284562, 0.45897093, 0.13188471, -0.07115303, 0.18009436, 0.16689545, -0.6991295, 0.26496106, -0.29619592, -0.19242188, -0.6362671, -0.16330126, 0.2474778, 0.37738156, -0.12921557, -0.07843309, 0.28509396, 0.5658691, 0.16096894, 0.095068075, 0.02419672, -0.30691084, 0.21180221, 0.21670066, 0.0027263877, 0.30853105, -0.16187873, 0.20786561, 0.22136153, -0.008828387, -0.011165021, 0.60076475, 0.0089871045, 0.6179727, -0.38049766, -0.08179336, -0.15306218, -0.13186441, -0.5360041, -0.06123339, -0.06399122, 0.21292226, -0.18383273, -0.21540102, 0.28566808, -0.29953584, -0.36946672, 0.03341637, -0.08435299, -0.5381947, -0.28651953, 0.08704594, -0.25493965, 0.0019178925, -0.7242109, 0.3578676, -0.55617595, -0.01930952, 0.32922924, 0.14903364, 0.21613406, -0.11927183, 0.15165499, -0.10101261, 0.2499076, -0.18526322, -0.057230365, 0.10008554, 0.16178907, 0.39356324, -0.03106238, 0.09375929, 0.17185533, 0.10400415, -0.36850816, 0.18424486, -0.081376314, 0.23645392, 0.05198973, 0.09471436]; return client.graphql @@ -182,7 +275,23 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with nearObject", () => { + test("graphql aggregate method with nearVector (with distance)", () => { + var searchVec = [-0.15047126, 0.061322376, -0.17812507, 0.12811552, 0.36847013, -0.50840724, -0.10406531, 0.11413283, 0.2997712, 0.7039331, 0.22155242, 0.1413957, 0.025396502, 0.14802167, 0.26640236, 0.15965445, -0.45570126, -0.5215438, 0.14628491, 0.10946681, 0.0040095793, 0.017442623, -0.1988451, -0.05362646, 0.104278944, -0.2506941, 0.2667653, 0.36438593, -0.44370207, 0.07204353, 0.077371456, 0.14557181, 0.6026817, 0.45073593, 0.09438019, 0.03936342, -0.20441438, 0.12333719, -0.20247602, 0.5078446, -0.06079732, -0.02166342, 0.02165861, -0.11712191, 0.0493167, -0.012123002, 0.26458082, -0.10784768, -0.26852348, 0.049759883, -0.39999008, -0.08977922, 0.003169497, -0.36184034, -0.069065355, 0.18940343, 0.5684866, -0.24626277, -0.2326087, 0.090373255, 0.33161184, -1.0541122, -0.039116446, -0.17496277, -0.16834813, -0.0765323, -0.16189013, -0.062876746, -0.19826415, 0.07437007, -0.018362755, 0.23634757, -0.19062655, -0.26524994, 0.33691254, -0.1926698, 0.018848037, 0.1735524, 0.34301907, -0.014238952, -0.07596742, -0.61302894, -0.044652265, 0.1545376, 0.67256856, 0.08630557, 0.50236076, 0.23438522, 0.27686095, 0.13633616, -0.27525797, 0.04282576, 0.18319897, -0.008353968, -0.27330264, 0.12624736, -0.17051372, -0.35854533, -0.008455927, 0.154786, -0.20306401, -0.09021733, 0.80594194, 0.036562894, -0.48894945, -0.27981675, -0.5001396, -0.3581464, -0.057082724, -0.0051904973, -0.3209166, 0.057098284, 0.111587055, -0.09097725, -0.213181, -0.5038173, -0.024070809, -0.05350453, 0.13345918, -0.42136985, 0.24050911, -0.2556207, 0.03156968, 0.4381214, 0.053237516, -0.20783865, 1.885739, 0.28429136, -0.12231187, -0.30934808, 0.032250155, -0.32959512, 0.08670603, -0.60112613, -0.43010503, 0.70870006, 0.3548015, -0.010406012, 0.036294986, 0.0030629474, -0.017579105, 0.28948352, -0.48063236, -0.39739868, 0.17860937, 0.5099417, -0.24304488, -0.12671146, -0.018249692, -0.32057074, -0.08146134, 0.3572229, -0.47601065, 0.35100546, -0.19663939, 0.34194613, -0.04653828, 0.47278664, -0.8723091, -0.19756387, -0.5890681, 0.16688067, -0.23709822, -0.26478595, -0.18792373, 0.2204168, 0.030987943, 0.15885714, -0.38817936, -0.4194334, -0.3287098, 0.15394142, -0.09496768, 0.6561987, -0.39340565, -0.5479265, -0.22363484, -0.1193662, 0.2014849, 0.31138006, -0.45485613, -0.9879565, 0.3708223, 0.17318928, 0.21229307, 0.042776756, -0.077399045, 0.42621315, -0.09917796, 0.34220153, 0.06380378, 0.14129028, -0.14563583, -0.07081333, 0.026335392, 0.10566285, -0.28074324, -0.059861198, -0.24855351, 0.13623764, -0.8228192, -0.15095113, 0.16250934, 0.031107651, -0.1504525, 0.20840737, 0.12919411, -0.0926323, 0.30937102, 0.16636328, -0.36754072, 0.035581365, -0.2799259, 0.1446048, -0.11680267, 0.13226685, 0.175023, -0.18840964, 0.27609056, -0.09350581, 0.08284562, 0.45897093, 0.13188471, -0.07115303, 0.18009436, 0.16689545, -0.6991295, 0.26496106, -0.29619592, -0.19242188, -0.6362671, -0.16330126, 0.2474778, 0.37738156, -0.12921557, -0.07843309, 0.28509396, 0.5658691, 0.16096894, 0.095068075, 0.02419672, -0.30691084, 0.21180221, 0.21670066, 0.0027263877, 0.30853105, -0.16187873, 0.20786561, 0.22136153, -0.008828387, -0.011165021, 0.60076475, 0.0089871045, 0.6179727, -0.38049766, -0.08179336, -0.15306218, -0.13186441, -0.5360041, -0.06123339, -0.06399122, 0.21292226, -0.18383273, -0.21540102, 0.28566808, -0.29953584, -0.36946672, 0.03341637, -0.08435299, -0.5381947, -0.28651953, 0.08704594, -0.25493965, 0.0019178925, -0.7242109, 0.3578676, -0.55617595, -0.01930952, 0.32922924, 0.14903364, 0.21613406, -0.11927183, 0.15165499, -0.10101261, 0.2499076, -0.18526322, -0.057230365, 0.10008554, 0.16178907, 0.39356324, -0.03106238, 0.09375929, 0.17185533, 0.10400415, -0.36850816, 0.18424486, -0.081376314, 0.23645392, 0.05198973, 0.09471436]; + + return client.graphql + .aggregate() + .withClassName("Article") + .withNearVector({ vector: searchVec, distance: 0.3 }) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method with nearObject (with certainty)", () => { return client.graphql .aggregate() .withClassName("Article") @@ -196,7 +305,21 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with nearText", () => { + test("graphql aggregate method with nearObject (with distance)", () => { + return client.graphql + .aggregate() + .withClassName("Article") + .withNearObject({ id: "abefd256-8574-442b-9293-9205193737ee", distance: 0.3 }) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method with nearText (with certainty)", () => { return client.graphql .aggregate() .withClassName("Article") @@ -210,7 +333,21 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method expected failure - multiple nearMedia filters", () => { + test("graphql aggregate method with nearText (with distance)", () => { + return client.graphql + .aggregate() + .withClassName("Article") + .withNearText({ concepts: ["Article"], distance: 0.3 }) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(3); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method expected failure - multiple nearMedia filters (with certainty)", () => { return expect(() => { client.graphql .aggregate() @@ -222,7 +359,19 @@ describe("the graphql journey", () => { .toThrow("cannot use multiple near filters in a single query") }); - test("graphql aggregate method with where and nearVector", () => { + test("graphql aggregate method expected failure - multiple nearMedia filters (with distance)", () => { + return expect(() => { + client.graphql + .aggregate() + .withClassName("Article") + .withNearText({ concepts: ["iphone"] }) + .withNearObject({ id: "abefd256-8574-442b-9293-9205193737ee", distance: 0.35 }) + .do() + }) + .toThrow("cannot use multiple near filters in a single query") + }); + + test("graphql aggregate method with where and nearVector (with certainty)", () => { var searchVec = [-0.15047126, 0.061322376, -0.17812507, 0.12811552, 0.36847013, -0.50840724, -0.10406531, 0.11413283, 0.2997712, 0.7039331, 0.22155242, 0.1413957, 0.025396502, 0.14802167, 0.26640236, 0.15965445, -0.45570126, -0.5215438, 0.14628491, 0.10946681, 0.0040095793, 0.017442623, -0.1988451, -0.05362646, 0.104278944, -0.2506941, 0.2667653, 0.36438593, -0.44370207, 0.07204353, 0.077371456, 0.14557181, 0.6026817, 0.45073593, 0.09438019, 0.03936342, -0.20441438, 0.12333719, -0.20247602, 0.5078446, -0.06079732, -0.02166342, 0.02165861, -0.11712191, 0.0493167, -0.012123002, 0.26458082, -0.10784768, -0.26852348, 0.049759883, -0.39999008, -0.08977922, 0.003169497, -0.36184034, -0.069065355, 0.18940343, 0.5684866, -0.24626277, -0.2326087, 0.090373255, 0.33161184, -1.0541122, -0.039116446, -0.17496277, -0.16834813, -0.0765323, -0.16189013, -0.062876746, -0.19826415, 0.07437007, -0.018362755, 0.23634757, -0.19062655, -0.26524994, 0.33691254, -0.1926698, 0.018848037, 0.1735524, 0.34301907, -0.014238952, -0.07596742, -0.61302894, -0.044652265, 0.1545376, 0.67256856, 0.08630557, 0.50236076, 0.23438522, 0.27686095, 0.13633616, -0.27525797, 0.04282576, 0.18319897, -0.008353968, -0.27330264, 0.12624736, -0.17051372, -0.35854533, -0.008455927, 0.154786, -0.20306401, -0.09021733, 0.80594194, 0.036562894, -0.48894945, -0.27981675, -0.5001396, -0.3581464, -0.057082724, -0.0051904973, -0.3209166, 0.057098284, 0.111587055, -0.09097725, -0.213181, -0.5038173, -0.024070809, -0.05350453, 0.13345918, -0.42136985, 0.24050911, -0.2556207, 0.03156968, 0.4381214, 0.053237516, -0.20783865, 1.885739, 0.28429136, -0.12231187, -0.30934808, 0.032250155, -0.32959512, 0.08670603, -0.60112613, -0.43010503, 0.70870006, 0.3548015, -0.010406012, 0.036294986, 0.0030629474, -0.017579105, 0.28948352, -0.48063236, -0.39739868, 0.17860937, 0.5099417, -0.24304488, -0.12671146, -0.018249692, -0.32057074, -0.08146134, 0.3572229, -0.47601065, 0.35100546, -0.19663939, 0.34194613, -0.04653828, 0.47278664, -0.8723091, -0.19756387, -0.5890681, 0.16688067, -0.23709822, -0.26478595, -0.18792373, 0.2204168, 0.030987943, 0.15885714, -0.38817936, -0.4194334, -0.3287098, 0.15394142, -0.09496768, 0.6561987, -0.39340565, -0.5479265, -0.22363484, -0.1193662, 0.2014849, 0.31138006, -0.45485613, -0.9879565, 0.3708223, 0.17318928, 0.21229307, 0.042776756, -0.077399045, 0.42621315, -0.09917796, 0.34220153, 0.06380378, 0.14129028, -0.14563583, -0.07081333, 0.026335392, 0.10566285, -0.28074324, -0.059861198, -0.24855351, 0.13623764, -0.8228192, -0.15095113, 0.16250934, 0.031107651, -0.1504525, 0.20840737, 0.12919411, -0.0926323, 0.30937102, 0.16636328, -0.36754072, 0.035581365, -0.2799259, 0.1446048, -0.11680267, 0.13226685, 0.175023, -0.18840964, 0.27609056, -0.09350581, 0.08284562, 0.45897093, 0.13188471, -0.07115303, 0.18009436, 0.16689545, -0.6991295, 0.26496106, -0.29619592, -0.19242188, -0.6362671, -0.16330126, 0.2474778, 0.37738156, -0.12921557, -0.07843309, 0.28509396, 0.5658691, 0.16096894, 0.095068075, 0.02419672, -0.30691084, 0.21180221, 0.21670066, 0.0027263877, 0.30853105, -0.16187873, 0.20786561, 0.22136153, -0.008828387, -0.011165021, 0.60076475, 0.0089871045, 0.6179727, -0.38049766, -0.08179336, -0.15306218, -0.13186441, -0.5360041, -0.06123339, -0.06399122, 0.21292226, -0.18383273, -0.21540102, 0.28566808, -0.29953584, -0.36946672, 0.03341637, -0.08435299, -0.5381947, -0.28651953, 0.08704594, -0.25493965, 0.0019178925, -0.7242109, 0.3578676, -0.55617595, -0.01930952, 0.32922924, 0.14903364, 0.21613406, -0.11927183, 0.15165499, -0.10101261, 0.2499076, -0.18526322, -0.057230365, 0.10008554, 0.16178907, 0.39356324, -0.03106238, 0.09375929, 0.17185533, 0.10400415, -0.36850816, 0.18424486, -0.081376314, 0.23645392, 0.05198973, 0.09471436]; return client.graphql @@ -243,7 +392,28 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with where and nearObject", () => { + test("graphql aggregate method with where and nearVector (with distance)", () => { + var searchVec = [-0.15047126, 0.061322376, -0.17812507, 0.12811552, 0.36847013, -0.50840724, -0.10406531, 0.11413283, 0.2997712, 0.7039331, 0.22155242, 0.1413957, 0.025396502, 0.14802167, 0.26640236, 0.15965445, -0.45570126, -0.5215438, 0.14628491, 0.10946681, 0.0040095793, 0.017442623, -0.1988451, -0.05362646, 0.104278944, -0.2506941, 0.2667653, 0.36438593, -0.44370207, 0.07204353, 0.077371456, 0.14557181, 0.6026817, 0.45073593, 0.09438019, 0.03936342, -0.20441438, 0.12333719, -0.20247602, 0.5078446, -0.06079732, -0.02166342, 0.02165861, -0.11712191, 0.0493167, -0.012123002, 0.26458082, -0.10784768, -0.26852348, 0.049759883, -0.39999008, -0.08977922, 0.003169497, -0.36184034, -0.069065355, 0.18940343, 0.5684866, -0.24626277, -0.2326087, 0.090373255, 0.33161184, -1.0541122, -0.039116446, -0.17496277, -0.16834813, -0.0765323, -0.16189013, -0.062876746, -0.19826415, 0.07437007, -0.018362755, 0.23634757, -0.19062655, -0.26524994, 0.33691254, -0.1926698, 0.018848037, 0.1735524, 0.34301907, -0.014238952, -0.07596742, -0.61302894, -0.044652265, 0.1545376, 0.67256856, 0.08630557, 0.50236076, 0.23438522, 0.27686095, 0.13633616, -0.27525797, 0.04282576, 0.18319897, -0.008353968, -0.27330264, 0.12624736, -0.17051372, -0.35854533, -0.008455927, 0.154786, -0.20306401, -0.09021733, 0.80594194, 0.036562894, -0.48894945, -0.27981675, -0.5001396, -0.3581464, -0.057082724, -0.0051904973, -0.3209166, 0.057098284, 0.111587055, -0.09097725, -0.213181, -0.5038173, -0.024070809, -0.05350453, 0.13345918, -0.42136985, 0.24050911, -0.2556207, 0.03156968, 0.4381214, 0.053237516, -0.20783865, 1.885739, 0.28429136, -0.12231187, -0.30934808, 0.032250155, -0.32959512, 0.08670603, -0.60112613, -0.43010503, 0.70870006, 0.3548015, -0.010406012, 0.036294986, 0.0030629474, -0.017579105, 0.28948352, -0.48063236, -0.39739868, 0.17860937, 0.5099417, -0.24304488, -0.12671146, -0.018249692, -0.32057074, -0.08146134, 0.3572229, -0.47601065, 0.35100546, -0.19663939, 0.34194613, -0.04653828, 0.47278664, -0.8723091, -0.19756387, -0.5890681, 0.16688067, -0.23709822, -0.26478595, -0.18792373, 0.2204168, 0.030987943, 0.15885714, -0.38817936, -0.4194334, -0.3287098, 0.15394142, -0.09496768, 0.6561987, -0.39340565, -0.5479265, -0.22363484, -0.1193662, 0.2014849, 0.31138006, -0.45485613, -0.9879565, 0.3708223, 0.17318928, 0.21229307, 0.042776756, -0.077399045, 0.42621315, -0.09917796, 0.34220153, 0.06380378, 0.14129028, -0.14563583, -0.07081333, 0.026335392, 0.10566285, -0.28074324, -0.059861198, -0.24855351, 0.13623764, -0.8228192, -0.15095113, 0.16250934, 0.031107651, -0.1504525, 0.20840737, 0.12919411, -0.0926323, 0.30937102, 0.16636328, -0.36754072, 0.035581365, -0.2799259, 0.1446048, -0.11680267, 0.13226685, 0.175023, -0.18840964, 0.27609056, -0.09350581, 0.08284562, 0.45897093, 0.13188471, -0.07115303, 0.18009436, 0.16689545, -0.6991295, 0.26496106, -0.29619592, -0.19242188, -0.6362671, -0.16330126, 0.2474778, 0.37738156, -0.12921557, -0.07843309, 0.28509396, 0.5658691, 0.16096894, 0.095068075, 0.02419672, -0.30691084, 0.21180221, 0.21670066, 0.0027263877, 0.30853105, -0.16187873, 0.20786561, 0.22136153, -0.008828387, -0.011165021, 0.60076475, 0.0089871045, 0.6179727, -0.38049766, -0.08179336, -0.15306218, -0.13186441, -0.5360041, -0.06123339, -0.06399122, 0.21292226, -0.18383273, -0.21540102, 0.28566808, -0.29953584, -0.36946672, 0.03341637, -0.08435299, -0.5381947, -0.28651953, 0.08704594, -0.25493965, 0.0019178925, -0.7242109, 0.3578676, -0.55617595, -0.01930952, 0.32922924, 0.14903364, 0.21613406, -0.11927183, 0.15165499, -0.10101261, 0.2499076, -0.18526322, -0.057230365, 0.10008554, 0.16178907, 0.39356324, -0.03106238, 0.09375929, 0.17185533, 0.10400415, -0.36850816, 0.18424486, -0.081376314, 0.23645392, 0.05198973, 0.09471436]; + + return client.graphql + .aggregate() + .withClassName("Article") + .withNearVector({ vector: searchVec, distance: 0.3 }) + .withWhere({ + operator: Operator.EQUAL, + path: ["_id"], + valueString: "abefd256-8574-442b-9293-9205193737ee", + }) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(1); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method with where and nearObject (with certainty)", () => { return client.graphql .aggregate() .withClassName("Article") @@ -262,7 +432,26 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with where and nearText", () => { + test("graphql aggregate method with where and nearObject (with distance)", () => { + return client.graphql + .aggregate() + .withClassName("Article") + .withNearObject({ id: "abefd256-8574-442b-9293-9205193737ee", distance: 0.3 }) + .withWhere({ + operator: Operator.EQUAL, + path: ["_id"], + valueString: "abefd256-8574-442b-9293-9205193737ee", + }) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(1); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method with where and nearText (with certainty)", () => { return client.graphql .aggregate() .withClassName("Article") @@ -281,7 +470,26 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with objectLimit", () => { + test("graphql aggregate method with where and nearText (with distance)", () => { + return client.graphql + .aggregate() + .withClassName("Article") + .withNearText({ concepts: ["Article"], distance: 0.3 }) + .withWhere({ + operator: Operator.EQUAL, + path: ["_id"], + valueString: "abefd256-8574-442b-9293-9205193737ee", + }) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(1); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method with objectLimit (with certainty)", () => { var objectLimit = 1 return client.graphql @@ -298,7 +506,24 @@ describe("the graphql journey", () => { .catch((e) => fail("it should not have error'd" + e)); }); - test("graphql aggregate method with bad objectLimit input", () => { + test("graphql aggregate method with objectLimit (with distance)", () => { + var objectLimit = 1 + + return client.graphql + .aggregate() + .withClassName("Article") + .withNearText({ concepts: ["Article"], distance: 0.3 }) + .withObjectLimit(objectLimit) + .withFields("meta { count }") + .do() + .then((res) => { + const count = res.data.Aggregate.Article[0].meta.count; + expect(count).toEqual(objectLimit); + }) + .catch((e) => fail("it should not have error'd" + e)); + }); + + test("graphql aggregate method with bad objectLimit input (with certainty)", () => { var objectLimit = -1.1 return expect(() => { @@ -313,6 +538,21 @@ describe("the graphql journey", () => { .toThrow("objectLimit must be a non-negative integer"); }); + test("graphql aggregate method with bad objectLimit input (with distance)", () => { + var objectLimit = -1.1 + + return expect(() => { + client.graphql + .aggregate() + .withClassName("Article") + .withNearText({ concepts: ["Article"], distance: 0.3 }) + .withObjectLimit(objectLimit) + .withFields("meta { count }") + .do() + }) + .toThrow("objectLimit must be a non-negative integer"); + }); + test("graphql explore with minimal fields", () => { return client.graphql .explore() @@ -329,7 +569,7 @@ describe("the graphql journey", () => { return client.graphql .explore() .withNearText({ concepts: ["iphone"] }) - .withFields("beacon certainty className") + .withFields("beacon certainty distance className") .withLimit(1) .do() .then((res) => { @@ -342,7 +582,7 @@ describe("the graphql journey", () => { return client.graphql .explore() .withNearObject({ id: "abefd256-8574-442b-9293-9205193737ee" }) - .withFields("beacon certainty className") + .withFields("beacon certainty distance className") .do() .then((res) => { expect(res.data.Explore.length).toBeGreaterThan(0); diff --git a/graphql/nearImage.js b/graphql/nearImage.js index 86974c1..20b06e5 100644 --- a/graphql/nearImage.js +++ b/graphql/nearImage.js @@ -22,6 +22,10 @@ export default class GraphQLNearImage { args = [...args, `certainty:${this.certainty}`]; } + if (this.distance) { + args = [...args, `distance:${this.distance}`]; + } + if (!wrap) { return `${args.join(",")}`; } @@ -43,6 +47,9 @@ export default class GraphQLNearImage { case "certainty": this.parseCertainty(this.source[key]); break; + case "distance": + this.parseDistance(this.source[key]); + break; default: throw new Error("nearImage filter: unrecognized key '" + key + "'"); } @@ -64,4 +71,12 @@ export default class GraphQLNearImage { this.certainty = cert; } + + parseDistance(dist) { + if (typeof dist !== "number") { + throw new Error("nearImage filter: distance must be a number"); + } + + this.distance = dist; + } } diff --git a/graphql/nearObject.js b/graphql/nearObject.js index 1a9dd04..1243d5e 100644 --- a/graphql/nearObject.js +++ b/graphql/nearObject.js @@ -21,6 +21,10 @@ export default class GraphQLNearObject { args = [...args, `certainty:${this.certainty}`]; } + if (this.distance) { + args = [...args, `distance:${this.distance}`]; + } + if (!wrap) { return `${args.join(",")}`; } @@ -45,6 +49,9 @@ export default class GraphQLNearObject { case "certainty": this.parseCertainty(this.source[key]); break; + case "distance": + this.parseDistance(this.source[key]); + break; default: throw new Error("nearObject filter: unrecognized key '" + key + "'"); } @@ -74,4 +81,12 @@ export default class GraphQLNearObject { this.certainty = cert; } + + parseDistance(dist) { + if (typeof dist !== "number") { + throw new Error("nearObject filter: distance must be a number"); + } + + this.distance = dist; + } } diff --git a/graphql/nearText.js b/graphql/nearText.js index c6aa3c5..378f8ab 100644 --- a/graphql/nearText.js +++ b/graphql/nearText.js @@ -13,6 +13,10 @@ export default class GraphQLNearText { args = [...args, `certainty:${this.certainty}`]; } + if (this.distance) { + args = [...args, `distance:${this.distance}`]; + } + if (this.moveTo) { let moveToArgs = [] if (this.moveToConcepts) { @@ -85,6 +89,9 @@ export default class GraphQLNearText { case "certainty": this.parseCertainty(this.source[key]); break; + case "distance": + this.parseDistance(this.source[key]); + break; case "moveTo": this.parseMoveTo(this.source[key]); break; @@ -116,6 +123,14 @@ export default class GraphQLNearText { this.certainty = cert; } + parseDistance(dist) { + if (typeof dist !== "number") { + throw new Error("nearText filter: distance must be a number"); + } + + this.distance = dist; + } + parseMoveTo(target) { if (typeof target !== "object") { throw new Error("nearText filter: moveTo must be object"); diff --git a/graphql/nearVector.js b/graphql/nearVector.js index 42d01bc..74eae0c 100644 --- a/graphql/nearVector.js +++ b/graphql/nearVector.js @@ -13,6 +13,10 @@ export default class GraphQLNearVector { args = [...args, `certainty:${this.certainty}`]; } + if (this.distance) { + args = [...args, `distance:${this.distance}`]; + } + if (!wrap) { return `${args.join(",")}`; } @@ -34,6 +38,9 @@ export default class GraphQLNearVector { case "certainty": this.parseCertainty(this.source[key]); break; + case "distance": + this.parseDistance(this.source[key]); + break; default: throw new Error("nearVector filter: unrecognized key '" + key + "'"); } @@ -61,4 +68,12 @@ export default class GraphQLNearVector { this.certainty = cert; } + + parseDistance(dist) { + if (typeof dist !== "number") { + throw new Error("nearVector filter: distance must be a number"); + } + + this.distance = dist; + } }