Skip to content

Commit 483da4a

Browse files
Fix tests + change WithOrderRelevance type
1 parent 7fff07a commit 483da4a

File tree

9 files changed

+92
-29
lines changed

9 files changed

+92
-29
lines changed

etc/api.report.api.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,8 @@ export type WhereClause<T extends ObjectOrInterfaceDefinition> = OrWhereClause<T
13001300
export type WirePropertyTypes = BaseWirePropertyTypes | Record<string, BaseWirePropertyTypes>;
13011301

13021302
// @public (undocumented)
1303-
export type WithOrderByRelevance<T extends Osdk.Instance<any>> = {
1303+
export type WithOrderByRelevance<T extends Osdk.Instance<any>> = T & {
13041304
$score: number
1305-
object: T
13061305
};
13071306

13081307
// Warnings were encountered during analysis:

packages/api/src/OsdkObjectFrom.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ export type Osdk<
190190
ExtractPropsKeysFromOldPropsStyle<Q, OPTIONS>
191191
>;
192192

193-
export type WithOrderByRelevance<T extends Osdk.Instance<any>> = {
193+
export type WithOrderByRelevance<T extends Osdk.Instance<any>> = T & {
194194
$score: number;
195-
object: T;
196195
};
197196

198197
export namespace Osdk {
@@ -274,8 +273,3 @@ export type ExtractOptions<
274273
S extends NullabilityAdherence = NullabilityAdherence.Default,
275274
T extends boolean = false,
276275
> = ExtractRidOption<R> | ExtractAllPropertiesOption<T>;
277-
278-
export type ExtractOrderByOptions<R extends boolean> = IsNever<R> extends true
279-
? never
280-
: DefaultToFalse<R> extends false ? never
281-
: "$score";
675 KB
Binary file not shown.

packages/client/src/objectSet/ObjectSet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe("ObjectSet", () => {
210210
employees.forEach(e => expect(e.$score).toBeUndefined());
211211
});
212212

213-
it("nearest neighbors object set ordered by relevance", async () => {
213+
it.only("nearest neighbors object set ordered by relevance", async () => {
214214
const objectSet = client(Employee);
215215
const { data: employees } = await objectSet.nearestNeighbors(
216216
"python3",

packages/e2e.sandbox.catchall/src/runNearestNeighborsTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function runNearestNeighborsTest(): Promise<void> {
4444
});
4545
resultOrderedByRelevance.data.map(s => {
4646
invariant(s.$score !== undefined);
47-
console.log(s.object.orderTitle, s.$score);
47+
console.log(s.orderTitle, s.$score);
4848
});
4949

5050
// Ensure regular ordering still works

packages/shared.test/src/FauxFoundry/getObjectsFromSet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616

1717
import type * as OntologiesV2 from "@osdk/foundry.ontologies";
18+
import stableStringify from "json-stable-stringify";
1819
import invariant from "tiny-invariant";
20+
import { nearestNeighborRequestHandlers } from "../stubs/nearestNeighborRequests.js";
1921
import type { BaseServerObject } from "./BaseServerObject.js";
2022
import type { FauxDataStore } from "./FauxDataStore.js";
2123
import { filterObjects } from "./filterObjects.js";
@@ -114,6 +116,10 @@ export function getObjectsFromSet(
114116
});
115117
}
116118

119+
case "nearestNeighbors": {
120+
return nearestNeighborRequestHandlers[stableStringify(objectSet)];
121+
}
122+
117123
case "methodInput":
118124
invariant(methodInput, "expected a methodInput");
119125
return [methodInput];

packages/shared.test/src/handlers/objectSetEndpoints.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ export const objectSetHandlers: Array<RequestHandler> = [
5757
};
5858
}
5959

60-
if (parsedBody.orderBy) {
61-
objects = objects.sort(createOrderBySortFn(parsedBody.orderBy));
60+
const orderBy = parsedBody.orderBy;
61+
if (orderBy) {
62+
if (orderBy?.orderType === "relevance") {
63+
objects = objects.map(o => ({ ...o, "$score": 0.1 }));
64+
} else {
65+
objects = objects.sort(createOrderBySortFn(orderBy));
66+
}
6267
}
6368

6469
const page = pageThroughResponseSearchParams(
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import type * as OntologiesV2 from "@osdk/foundry.ontologies";
18+
import stableStringify from "json-stable-stringify";
19+
import type { BaseServerObject } from "../FauxFoundry/BaseServerObject.js";
20+
import { employee1, employee2, employee3 } from "./objects.js";
21+
import { employeeObjectType } from "./objectTypeV2.js";
22+
23+
type NearestNeighborType = OntologiesV2.ObjectSetNearestNeighborsType & {
24+
type: "nearestNeighbors";
25+
};
26+
27+
const nearestNeighborsObjectSet: NearestNeighborType = {
28+
type: "nearestNeighbors",
29+
objectSet: {
30+
type: "base",
31+
objectType: employeeObjectType.apiName,
32+
},
33+
propertyIdentifier: {
34+
type: "property",
35+
apiName: "skillSetEmbedding",
36+
},
37+
numNeighbors: 3,
38+
query: {
39+
type: "text",
40+
value: "python3",
41+
},
42+
};
43+
44+
const nearestNeighborsObjectSetVectorQuery: NearestNeighborType = {
45+
type: "nearestNeighbors",
46+
objectSet: {
47+
type: "base",
48+
objectType: employeeObjectType.apiName,
49+
},
50+
propertyIdentifier: {
51+
type: "property",
52+
apiName: "skillSetEmbedding",
53+
},
54+
numNeighbors: 3,
55+
query: {
56+
type: "vector",
57+
value: Array.from({ length: 1536 }, () => 0.3),
58+
},
59+
};
60+
61+
export const nearestNeighborRequestHandlers: Record<
62+
string,
63+
BaseServerObject[]
64+
> = {
65+
[stableStringify(nearestNeighborsObjectSet)]: [
66+
employee1,
67+
employee2,
68+
employee3,
69+
],
70+
[stableStringify(nearestNeighborsObjectSetVectorQuery)]: [
71+
employee1,
72+
employee2,
73+
employee3,
74+
],
75+
};

packages/shared.test/src/stubs/objects.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import type { GeoJsonObject } from "@osdk/foundry.geo";
18-
import type { OntologyObjectV2 } from "@osdk/foundry.ontologies";
1918
import { employeeInterfaceScoped } from "./interfaces.js";
2019

2120
export const employee50050: {
@@ -54,11 +53,6 @@ export const employee1 = {
5453
} as const;
5554
export const employee1_50030_JohnDoe: typeof employee1 = employee1;
5655

57-
export const employee1WithScore: OntologyObjectV2 = {
58-
...employee1,
59-
__score: 0.95,
60-
};
61-
6256
export const employee2 = {
6357
__rid:
6458
"ri.phonograph2-objects.main.object.ae6a0b9a-9b9a-4b9e-8b0a-2b0b9a9a0b9a",
@@ -76,11 +70,6 @@ export const employee2 = {
7670
} as const;
7771
export const employee2_50031_JaneDoe: typeof employee2 = employee2;
7872

79-
export const employee2WithScore: OntologyObjectV2 = {
80-
...employee1,
81-
__score: 0.91,
82-
};
83-
8473
export const employee3 = {
8574
__rid:
8675
"ri.phonograph2-objects.main.object.b9a0b2b0-0a2b-0b8b-9e4b-a9a9b9a0b9a0",
@@ -98,11 +87,6 @@ export const employee3 = {
9887
};
9988
export const employee3_Jack_50032: typeof employee3 = employee3;
10089

101-
export const employee3WithScore: OntologyObjectV2 = {
102-
...employee1,
103-
__score: 0.85,
104-
};
105-
10690
// DELETE THIS
10791
export const employee4withDerived = {
10892
__rid:

0 commit comments

Comments
 (0)