-
Notifications
You must be signed in to change notification settings - Fork 40
Add nearest neighbors support #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
ea45276
600fc19
babb562
a7bda62
084fdc1
5f22cac
dd4a28f
07b9bd3
7af2e05
5e48fcd
29a0645
b99bb93
5c5e674
7944bcb
21378b0
f6eb11b
142b87d
7fff07a
483da4a
2864ee5
d68dcda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@osdk/foundry-sdk-generator": patch | ||
| "@osdk/generator-converters": patch | ||
| "@osdk/shared.test": patch | ||
| "@osdk/client": patch | ||
| "@osdk/api": patch | ||
| --- | ||
|
|
||
| Add nearest neighbors search support |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,11 @@ import type { | |
| Augments, | ||
| FetchPageArgs, | ||
| NullabilityAdherence, | ||
| OrderByOptions, | ||
| SelectArg, | ||
| } from "../object/FetchPageArgs.js"; | ||
| import type { Result } from "../object/Result.js"; | ||
| import type { VectorPropertyKeys } from "../ontology/FilteredPropertyKeys.js"; | ||
| import type { InterfaceDefinition } from "../ontology/InterfaceDefinition.js"; | ||
| import type { | ||
| DerivedObjectOrInterfaceDefinition, | ||
|
|
@@ -39,7 +41,11 @@ import type { | |
| } from "../ontology/ObjectTypeDefinition.js"; | ||
| import type { SimplePropertyDef } from "../ontology/SimplePropertyDef.js"; | ||
| import type { PrimaryKeyType } from "../OsdkBase.js"; | ||
| import type { ExtractOptions, Osdk } from "../OsdkObjectFrom.js"; | ||
| import type { | ||
| ExtractOptions, | ||
| ExtractOrderByOptions, | ||
| Osdk, | ||
| } from "../OsdkObjectFrom.js"; | ||
| import type { PageResult } from "../PageResult.js"; | ||
| import type { LinkedType, LinkNames } from "../util/LinkUtils.js"; | ||
| import type { BaseObjectSet } from "./BaseObjectSet.js"; | ||
|
|
@@ -90,15 +96,17 @@ interface FetchPage< | |
| const A extends Augments, | ||
| S extends NullabilityAdherence = NullabilityAdherence.Default, | ||
| T extends boolean = false, | ||
| Z extends OrderByOptions<Q, L> = {}, | ||
| >( | ||
| args?: FetchPageArgs<Q, L, R, A, S, T>, | ||
| args?: FetchPageArgs<Q, L, R, A, S, T, Z>, | ||
| ) => Promise< | ||
| PageResult< | ||
| Osdk.Instance< | ||
| Q, | ||
| ExtractOptions<R, S, T>, | ||
| PropertyKeys<Q> extends L ? PropertyKeys<Q> : PropertyKeys<Q> & L, | ||
| { [K in Extract<keyof RDPs, L>]: RDPs[K] } | ||
| { [K in Extract<keyof RDPs, L>]: RDPs[K] }, | ||
| ExtractOrderByOptions<Z extends "relevance" ? true : false> | ||
| > | ||
| > | ||
| >; | ||
|
|
@@ -123,16 +131,18 @@ interface FetchPage< | |
| const A extends Augments, | ||
| S extends NullabilityAdherence = NullabilityAdherence.Default, | ||
| T extends boolean = false, | ||
| Z extends OrderByOptions<Q, L> = {}, | ||
| >( | ||
| args?: FetchPageArgs<Q, L, R, A, S, T>, | ||
| args?: FetchPageArgs<Q, L, R, A, S, T, Z>, | ||
| ) => Promise< | ||
| Result< | ||
| PageResult< | ||
| Osdk.Instance< | ||
| Q, | ||
| ExtractOptions<R, S, T>, | ||
| PropertyKeys<Q> extends L ? PropertyKeys<Q> : PropertyKeys<Q> & L, | ||
| { [K in Extract<keyof RDPs, L>]: RDPs[K] } | ||
| { [K in Extract<keyof RDPs, L>]: RDPs[K] }, | ||
| ExtractOrderByOptions<Z extends "relevance" ? true : false> | ||
| > | ||
| > | ||
| > | ||
|
|
@@ -177,14 +187,16 @@ interface AsyncIter< | |
| const A extends Augments, | ||
| S extends NullabilityAdherence = NullabilityAdherence.Default, | ||
| T extends boolean = false, | ||
| Z extends OrderByOptions<Q, L> = {}, | ||
| >( | ||
| args?: AsyncIterArgs<Q, L, R, A, S, T>, | ||
| args?: AsyncIterArgs<Q, L, R, A, S, T, Z>, | ||
| ) => AsyncIterableIterator< | ||
| Osdk.Instance< | ||
| Q, | ||
| ExtractOptions<R, S, T>, | ||
| PropertyKeys<Q> extends L ? PropertyKeys<Q> : PropertyKeys<Q> & L, | ||
| { [K in Extract<keyof RDPs, L>]: RDPs[K] } | ||
| { [K in Extract<keyof RDPs, L>]: RDPs[K] }, | ||
| ExtractOrderByOptions<Z extends "relevance" ? true : false> | ||
| > | ||
| >; | ||
| } | ||
|
|
@@ -212,6 +224,27 @@ interface WithProperties< | |
| >; | ||
| } | ||
|
|
||
| interface NearestNeighbors<Q extends ObjectOrInterfaceDefinition> { | ||
| /** | ||
| * Finds the nearest neighbors for a given text or vector within the object set. | ||
| * | ||
| * @param query - Queries support either a vector matching the embedding model defined on the property, or text that is | ||
| automatically embedded. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting it automatically embedded is cool |
||
| * @param numNeighbors - The number of objects to return. If the number of documents in the objectType is less than the provided | ||
| value, all objects will be returned. This value is limited to 1 ≤ numNeighbors ≥ 500. | ||
| * @param property - The property key with a defined embedding model to search over. | ||
| * | ||
| * @returns An object set containing the `numNeighbors` nearest neighbors. To return the objects ordered by relevance and each | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I nest two nearest neighbors object sets, which one takes precedence? Or do we throw
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It operates the same way as nested unions/intersects in that it executes from inner to outer and returns the outer result. Added an example in 2538015 |
||
| * objects associated score, specify "relevance" in the orderBy. | ||
| */ | ||
|
|
||
| readonly nearestNeighbors: ( | ||
| query: string | number[], | ||
| numNeighbors: number, | ||
| property: VectorPropertyKeys<Q>, | ||
|
||
| ) => this; | ||
| } | ||
|
|
||
| export interface ObjectSet< | ||
| Q extends ObjectOrInterfaceDefinition = any, | ||
| // Generated code has what is basically ObjectSet<Q> set in here | ||
|
|
@@ -391,6 +424,7 @@ interface ObjectSetCleanedTypes< | |
| WithProperties<Q, D>, | ||
| Aggregate<MERGED>, | ||
| SetArithmetic<MERGED>, | ||
| NearestNeighbors<MERGED>, | ||
| PivotTo<MERGED>, | ||
| FetchOne<Q, D>, | ||
| Subscribe<MERGED> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting for myself that this isn't exported, so this arg reorder is fine