Skip to content

Server Data Store

A Server Data Store stores Entities in a database. Its class has only static methods, which you call as This.<ServerDataStoreName>.<method>() to load, save, update and delete the Entities it stores.

Availability: Both¹

This.<ServerDataStoreName> is the Server Data Store class. It is not grouped under a $ namespace.

It is declared in server-side and client-side code, but not in shared code (serverAndClient or calculation). On the client, each method sends the call to the server, where Access Control decides whether it may run.

In the signatures below, EntityClasses stands for the union of the Entity classes this Server Data Store stores, including their subset classes, for example typeof This.Order | typeof This.Order.Summary | typeof This.Customer. The real declaration spells out that union. type parameters take one of these classes, and the result has the type of its instances, InstanceType<C>.

loadById<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'where'>): Promise<InstanceType<C> | null>

Loads the record with the given id.

ParameterTypeDescription
typeCThe Entity class to load.
idIdType<InstanceType<C>>The record’s id. If it is null or undefined, the result is null.
findOptionsOmit<FindManyOptions<InstanceType<C>>, 'where'>Optional. Further options, for example relations. See FindManyOptions under Types.

Returns: Promise<InstanceType<C> | null>, null if no record is found or Access Control hides it · Availability: Both¹

loadByIdOrFail<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'where'>): Promise<InstanceType<C>>

Loads the record with the given id, and throws an error if there is none.

ParameterTypeDescription
typeCThe Entity class to load.
idIdType<InstanceType<C>>The record’s id.
findOptionsOmit<FindManyOptions<InstanceType<C>>, 'where'>Optional. Further options.

Returns: Promise<InstanceType<C>> · Availability: Both¹

loadByIds<C extends EntityClasses>(type: C, ids: IdType<InstanceType<C>>[], findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'where'>, removeEmptyResults?: boolean): Promise<InstanceType<C>[]>

Loads the records with the given ids. Unless findOptions sets an order, the results are in the order of ids.

ParameterTypeDescription
typeCThe Entity class to load.
idsIdType<InstanceType<C>>[]The records’ ids.
findOptionsOmit<FindManyOptions<InstanceType<C>>, 'where'>Optional. Further options.
removeEmptyResultsbooleanOptional. If true, ids without a record are left out of the result. Default: false.

Returns: Promise<InstanceType<C>[]> · Availability: Both¹

Note

Unless removeEmptyResults is true, the result has null at the position of each id for which no record was found, although the declared type has no null.

loadByCondition<C extends EntityClasses>(type: C, findOptions?: FindManyOptions<InstanceType<C>>): Promise<InstanceType<C>[]>

Loads the records that match findOptions.where, or all records if there is no condition. Without an order, the records are sorted by id.

ParameterTypeDescription
typeCThe Entity class to load.
findOptionsFindManyOptions<InstanceType<C>>Optional. Condition, sorting, relations to load and paging. See FindManyOptions under Types.

This example loads the ten largest orders over 1000, then changes and saves the first one:

const largeOrders = await This.MyDataStore.loadByCondition(This.Order, {
where: { amount: This.MyDataStore.MoreThan(1000) },
order: { amount: 'DESC' },
take: 10,
})
const order = largeOrders[0]
order.amount = 900
await This.MyDataStore.saveOne(order)

Returns: Promise<InstanceType<C>[]> · Availability: Both¹

loadPageByCondition<C extends EntityClasses>(type: C, paging: PagingDefinition, findOptions?: FindManyOptions<InstanceType<C>>): Promise<PagedData<InstanceType<C>>>

Loads one page of the records that match findOptions.where, together with the total number of matching records.

ParameterTypeDescription
typeCThe Entity class to load.
pagingPagingDefinitionThe page size and the zero-based page index. It replaces any take and skip in findOptions.
findOptionsFindManyOptions<InstanceType<C>>Optional. Condition, sorting and relations to load.

Returns: Promise<PagedData<InstanceType<C>>> · Availability: Both¹

loadByQuery<C extends EntityClasses>(type: C, query: DataQuery<InstanceType<C>>, findOptions?: FindManyOptions<InstanceType<C>>): Promise<InstanceType<C>[]>

Loads the records that match a search text, such as what an End user typed into a search field. The condition in findOptions.where must match too.

ParameterTypeDescription
typeCThe Entity class to load.
queryDataQuery<InstanceType<C>>The search text and the properties to search in. See DataQuery under Types.
findOptionsFindManyOptions<InstanceType<C>>Optional. Further condition, sorting and relations to load.

Returns: Promise<InstanceType<C>[]> · Availability: Both¹

loadPageByQuery<C extends EntityClasses>(type: C, paging: PagingDefinition, query: DataQuery<InstanceType<C>>, findOptions?: FindManyOptions<InstanceType<C>>): Promise<PagedData<InstanceType<C>>>

Loads one page of the records that match a search text, together with the total number of matching records.

ParameterTypeDescription
typeCThe Entity class to load.
pagingPagingDefinitionThe page size and the zero-based page index.
queryDataQuery<InstanceType<C>>The search text and the properties to search in.
findOptionsFindManyOptions<InstanceType<C>>Optional. Further condition, sorting and relations to load.

Returns: Promise<PagedData<InstanceType<C>>> · Availability: Both¹

loadByVectorDistance<C extends EntityClasses>(type: C, vectorPropertyName: keyof InstanceType<C> & string, searchVector: number[], operator?: DbVectorOperator, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'order'>, order?: 'ASC' | 'DESC'): Promise<InstanceType<C>[]>

Loads records sorted by the distance between a vector property and a search vector, for example to find the texts most similar to an embedding. The database must be PostgreSQL with the pgvector extension.

ParameterTypeDescription
typeCThe Entity class to load.
vectorPropertyNamekeyof InstanceType<C> & stringThe property that holds each record’s vector.
searchVectornumber[]The vector to compare with.
operatorDbVectorOperatorOptional. How the distance is computed. Default: 'l2Distance'.
findOptionsOmit<FindManyOptions<InstanceType<C>>, 'order'>Optional. Condition, number of records (take) and relations to load.
order'ASC' | 'DESC'Optional. Sort direction of the computed value. Default: 'ASC'. With 'l1Distance' and 'l2Distance', 'ASC' returns the closest records first; with 'innerProduct' and 'cosineDistance' the value grows with similarity, so use 'DESC'.

Returns: Promise<InstanceType<C>[]> · Availability: Both¹

loadByVectorDistanceIncludingDistance<C extends EntityClasses>(type: C, vectorPropertyName: keyof InstanceType<C> & string, searchVector: number[], operator?: DbVectorOperator, findOptions?: Omit<FindManyOptions<InstanceType<C>>, 'order'>, order?: 'ASC' | 'DESC'): Promise<{ data: InstanceType<C>, distance: number }[]>

Works like loadByVectorDistance(), and also returns each record’s distance.

ParameterTypeDescription
typeCThe Entity class to load.
vectorPropertyNamekeyof InstanceType<C> & stringThe property that holds each record’s vector.
searchVectornumber[]The vector to compare with.
operatorDbVectorOperatorOptional. How the distance is computed. Default: 'l2Distance'.
findOptionsOmit<FindManyOptions<InstanceType<C>>, 'order'>Optional. Condition, number of records and relations to load.
order'ASC' | 'DESC'Optional. Sort direction of the computed value, as for loadByVectorDistance(). Default: 'ASC'.

Returns: Promise<{ data: InstanceType<C>, distance: number }[]> · Availability: Both¹

aggregate<C extends EntityClasses, G extends keyof InstanceType<C>, A extends typeof allowedAggregationFunctions[number], K extends keyof InstanceType<C>, O extends string>(type: C, groupBy: G[], aggregations: AggregationInput<InstanceType<C>, A, K, O>[], findOptions?: FindManyOptions<InstanceType<C>>): Promise<AggregationOutput<InstanceType<C>, A, G, K, O>[]>

Groups the matching records by the given properties and computes sums, counts, minimums, maximums or averages per group.

ParameterTypeDescription
typeCThe Entity class to aggregate.
groupByG[]The properties to group by. Pass [] for one result over all records.
aggregationsAggregationInput<InstanceType<C>, A, K, O>[]The values to compute. See AggregationInput under Types.
findOptionsFindManyOptions<InstanceType<C>>Optional. The condition the records must match.

Returns: Promise<AggregationOutput<InstanceType<C>, A, G, K, O>[]>, one object per group · Availability: Both¹

count<C extends EntityClasses, G extends keyof InstanceType<C>>(type: C, groupBy?: G[], findOptions?: FindManyOptions<InstanceType<C>>): Promise<GroupedCount<InstanceType<C>, G>[]>

Counts the matching records, optionally per group.

ParameterTypeDescription
typeCThe Entity class to count.
groupByG[]Optional. The properties to group by. Without it, the result has one object.
findOptionsFindManyOptions<InstanceType<C>>Optional. The condition the records must match.

Returns: Promise<GroupedCount<InstanceType<C>, G>[]>, one object per group with the count in $count · Availability: Both¹

updateById<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>, updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>

Changes properties of the record with the given id. Lowgile loads the record, applies the changes and saves it, so the Entity’s change Triggers run.

ParameterTypeDescription
typeCThe Entity class.
idIdType<InstanceType<C>>The record’s id.
updatePropertiesPartial<InstanceType<C>> or a functionThe new property values, or a function that receives the current record and returns them. Client-side code can only pass an object.

Returns: Promise<number | null>, the number of updated records · Availability: Both¹

updateByIds<C extends EntityClasses>(type: C, ids: IdType<InstanceType<C>>[], updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>

Changes properties of the records with the given ids, one record at a time, so the Entity’s change Triggers run.

ParameterTypeDescription
typeCThe Entity class.
idsIdType<InstanceType<C>>[]The records’ ids.
updatePropertiesPartial<InstanceType<C>> or a functionThe new property values, or a function that receives each record and returns them. Client-side code can only pass an object.

Returns: Promise<number | null>, the number of updated records · Availability: Both¹

updateByCondition<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*', updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>

Changes properties of every record that matches a condition, one record at a time, so the Entity’s change Triggers run.

ParameterTypeDescription
typeCThe Entity class.
whereFindOptionsWhere<…>, an array of them, or '*'The condition, written like where in FindManyOptions. '*' matches all records.
updatePropertiesPartial<InstanceType<C>> or a functionThe new property values, or a function that receives each record and returns them. Client-side code can only pass an object.

Returns: Promise<number | null>, the number of updated records · Availability: Both¹

bulkUpdateByConditionWithoutTriggering<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*', updateProperties: Partial<InstanceType<C>> | ((current: InstanceType<C>) => Partial<InstanceType<C>> | Promise<Partial<InstanceType<C>>>)): Promise<number | null>

Changes properties of every record that matches a condition directly in the database, without running the Entity’s change Triggers. Access Control restrictions still apply.

ParameterTypeDescription
typeCThe Entity class.
whereFindOptionsWhere<…>, an array of them, or '*'The condition. '*' matches all records.
updatePropertiesPartial<InstanceType<C>> or a functionThe new property values, or a function that receives each record and returns them.

Returns: Promise<number | null>, the number of updated records · Availability: Server

upsert<C extends EntityClasses>(type: C, objs: InstanceType<C>[], propertiesToMatchBy: [keyof InstanceType<C>, ...(keyof InstanceType<C>)[]]): Promise<SavedIds<InstanceType<C>>[]>

Saves objects, updating the existing record where one has the same values in propertiesToMatchBy and inserting a new record otherwise. Lowgile sets the id of each matched object before saving.

ParameterTypeDescription
typeCThe Entity class.
objsInstanceType<C>[]The objects to save.
propertiesToMatchBy[keyof InstanceType<C>, ...(keyof InstanceType<C>)[]]At least one property that identifies an existing record, such as an external number.

Returns: Promise<SavedIds<InstanceType<C>>[]>, one per object · Availability: Both¹

saveOne<C extends EntityClasses>(obj: InstanceType<C>): Promise<SavedIds<InstanceType<C>>>

Inserts the object as a new record if it has no id, or updates the record with its id. Afterwards, the object and its related objects carry the ids the database assigned.

ParameterTypeDescription
objInstanceType<C>The object to save.

On the client, Lowgile first calls the object’s own beforeUpdate method (if the object has an id) or beforeInsert method (if not), or else its beforeSave method, if the Entity defines one that is available on the client.

Returns: Promise<SavedIds<InstanceType<C>>> · Availability: Both¹

saveOneAndTransferAuditTrail<C extends EntityClasses>(obj: InstanceType<C>, auditTrailUuid: string): Promise<SavedIds<InstanceType<C>>>

Inserts a new record and moves the audit trail entries recorded under auditTrailUuid to it. Use it when audit trail entries were written before the record existed.

ParameterTypeDescription
objInstanceType<C>The object to insert. It must not have an id, otherwise the call throws an error.
auditTrailUuidstringThe UUID under which the audit trail entries were recorded.

Returns: Promise<SavedIds<InstanceType<C>>> · Availability: Both¹

saveMany<C extends EntityClasses>(objs: InstanceType<C>[]): Promise<SavedIds<InstanceType<C>>[]>

Saves several objects in one transaction, inserting or updating each like saveOne().

ParameterTypeDescription
objsInstanceType<C>[]The objects to save. They can be of different Entities stored by this Server Data Store.

Returns: Promise<SavedIds<InstanceType<C>>[]>, one per object · Availability: Both¹

deleteOne<C extends EntityClasses>(obj: InstanceType<C>): Promise<number | null>

Deletes the record of the given object, identified by its id.

ParameterTypeDescription
objInstanceType<C>The object whose record to delete.

Returns: Promise<number | null>, the number of deleted records · Availability: Both¹

deleteMany<C extends EntityClasses>(objs: InstanceType<C>[]): Promise<number | null>

Deletes the records of the given objects, identified by their id.

ParameterTypeDescription
objsInstanceType<C>[]The objects whose records to delete.

Returns: Promise<number | null>, the number of deleted records · Availability: Both¹

deleteById<C extends EntityClasses>(type: C, id: IdType<InstanceType<C>>): Promise<number | null>

Deletes the record with the given id.

ParameterTypeDescription
typeCThe Entity class.
idIdType<InstanceType<C>>The record’s id.

Returns: Promise<number | null>, the number of deleted records · Availability: Both¹

deleteByIds<C extends EntityClasses>(type: C, ids: IdType<InstanceType<C>>[]): Promise<number | null>

Deletes the records with the given ids.

ParameterTypeDescription
typeCThe Entity class.
idsIdType<InstanceType<C>>[]The records’ ids.

Returns: Promise<number | null>, the number of deleted records · Availability: Both¹

deleteByCondition<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*'): Promise<number | null>

Deletes every record that matches a condition.

ParameterTypeDescription
typeCThe Entity class.
whereFindOptionsWhere<…>, an array of them, or '*'The condition. '*' matches all records.

Returns: Promise<number | null>, the number of deleted records · Availability: Both¹

bulkDeleteByConditionWithoutTriggering<C extends EntityClasses>(type: C, where: FindOptionsWhere<EntityRecord<InstanceType<C>>> | FindOptionsWhere<EntityRecord<InstanceType<C>>>[] | '*'): Promise<number | null>

Deletes every record that matches a condition without running the Entity’s change Triggers. Access Control restrictions still apply.

ParameterTypeDescription
typeCThe Entity class.
whereFindOptionsWhere<…>, an array of them, or '*'The condition. '*' matches all records.

Returns: Promise<number | null>, the number of deleted records · Availability: Server

loadAndStreamByCondition<C extends EntityClasses, R>(type: C, findOptions?: FindManyOptions<C>, whatToReturn?: (baseResult: InstanceType<C>) => R): AsyncGenerator<R>
loadAndStreamByCondition<C extends EntityClasses>(type: C, findOptions?: FindManyOptions<C>): AsyncGenerator<InstanceType<C>>

Loads the matching records one by one instead of all at once, for processing large numbers of records. Read the result with for await.

ParameterTypeDescription
typeCThe Entity class to load.
findOptionsFindManyOptions<C>Optional. Condition, sorting and relations to load.
whatToReturn(baseResult: InstanceType<C>) => ROptional. A function that turns each record into the value the generator yields.
for await (const order of This.MyDataStore.loadAndStreamByCondition(This.Order, { where: { amount: This.MyDataStore.MoreThan(1000) } })) {
// process one order at a time
}

Returns: AsyncGenerator<R> or AsyncGenerator<InstanceType<C>> · Availability: Server

createQueryBuilder<T extends EntityClasses, A extends string>(type: T, alias: A): QueryBuilder<EntityClasses, T, A>

Creates a query builder for queries that the other methods can’t express, such as joins across Entities. The query builder has methods to add joins (join()), conditions (condition(), conditionRaw()), sorting and paging (order(), skip(), take()), and to run the query (selectOne(), selectMany(), selectCount(), selectManyAndCount(), their selectRaw…() variants, insert(), update() and delete()).

ParameterTypeDescription
typeTThe main Entity class of the query.
aliasAThe name under which the main Entity appears in the query and its results.

Returns: QueryBuilder<EntityClasses, T, A> · Availability: Server

Note

Queries built with createQueryBuilder() are not restricted by Access Control. The query builder’s update() and delete() return before the database has finished, and errors they cause are not reported to your code.

AndMerge<T>(...whereConditions: (FindOptionsWhere<T> | FindOptionsWhere<T>[])[]): FindOptionsWhere<T>[]

Combines several where conditions so that a record must match all of them. Conditions that are arrays (alternatives) are expanded, so the result is one array of alternatives.

ParameterTypeDescription
whereConditions(FindOptionsWhere<T> | FindOptionsWhere<T>[])[]The conditions to combine. undefined entries are ignored.

Returns: FindOptionsWhere<T>[] · Availability: Server

readonly And: typeof typeorm['And']
readonly Any: typeof typeorm['Any']
readonly ArrayContainedBy: typeof typeorm['ArrayContainedBy']
readonly ArrayContains: typeof typeorm['ArrayContains']
readonly ArrayOverlap: typeof typeorm['ArrayOverlap']
readonly Between: typeof typeorm['Between']
readonly Equal: typeof typeorm['Equal']
readonly ILike: typeof typeorm['ILike']
readonly In: typeof typeorm['In']
readonly IsNull: typeof typeorm['IsNull']
readonly LessThan: typeof typeorm['LessThan']
readonly LessThanOrEqual: typeof typeorm['LessThanOrEqual']
readonly Like: typeof typeorm['Like']
readonly MoreThan: typeof typeorm['MoreThan']
readonly MoreThanOrEqual: typeof typeorm['MoreThanOrEqual']
readonly Not: typeof typeorm['Not']
readonly Or: typeof typeorm['Or']

The find operators of TypeORM 1.1.1, re-exported unchanged, for use as values in where conditions. See the TypeORM documentation for each operator.

const orders = await This.MyDataStore.loadByCondition(This.Order, {
where: { status: This.MyDataStore.In(['open', 'approved']), deletedOn: This.MyDataStore.IsNull() },
})

Type: TypeORM find operator functions · Availability: Both

interface FindManyOptions<T> {
select?: FindOptionsSelect<EntityRecord<T>>
where?: FindOptionsWhere<EntityRecord<T>>[] | FindOptionsWhere<EntityRecord<T>>
relations?: FindOptionsRelations<EntityRecord<T>>
order?: FindOptionsOrder<EntityRecord<T>>
cache?: boolean | number | { id: any; milliseconds: number }
lock?: { mode: 'optimistic'; version: number | Date } | { mode: 'pessimistic_read' | 'pessimistic_write' | 'dirty_read' | 'for_no_key_update' | 'for_key_share'; tables?: string[]; onLocked?: 'nowait' | 'skip_locked' }
transaction?: boolean
skip?: number
take?: number
}

Options for loading records. The select, where, relations and order types are TypeORM’s, applied to the Entity’s properties.

FindManyOptions fields

FieldTypeRequiredDescription
selectFindOptionsSelect<…>OptionalThe properties to load, as { propertyName: true }.
whereFindOptionsWhere<…> or an array of themOptionalThe condition, as { propertyName: value }. A value can be a TypeORM operator such as This.<ServerDataStoreName>.MoreThan(5); null matches empty values. Properties of a related Entity are written as a nested object. An array of conditions matches records that fulfil any of them.
relationsFindOptionsRelations<…>OptionalThe related Entities to load with each record, as { relationName: true }, nested for deeper levels.
orderFindOptionsOrder<…>OptionalThe sort order, as { propertyName: 'ASC' } or 'DESC'.
cacheboolean | number | { id: any; milliseconds: number }OptionalCaches the query result, for the given number of milliseconds if a number is given.
lockan object with modeOptionalLocks the loaded rows. 'optimistic' needs a version; the other modes accept the tables to lock and what to do with locked rows.
transactionbooleanOptionalIf true, runs the query in a transaction.
skipnumberOptionalThe number of records to skip.
takenumberOptionalThe maximum number of records to load.

Availability: Both

interface PagingDefinition {
pageSize: number
pageIndex: number
}

Which page of records to load.

FieldTypeRequiredDescription
pageSizenumberRequiredThe number of records per page.
pageIndexnumberRequiredThe page to load, starting at 0.

Availability: Both

interface PagedData<T> extends PagingDefinition {
list: T[]
length: number
pageStartIndex: number
pageEndIndex: number
}

One page of records, with the paging information.

FieldTypeRequiredDescription
listT[]RequiredThe records on this page.
lengthnumberRequiredThe total number of matching records on all pages.
pageStartIndexnumberRequiredThe zero-based position of the page’s first record among all matching records.
pageEndIndexnumberRequiredThe zero-based position of the page’s last record among all matching records.
pageSizenumberRequiredThe page size.
pageIndexnumberRequiredThe page index.

Availability: Both

interface DataQuery<T> {
query: string
searchInProperties?: string[]
caseSensitive?: boolean
}

A search text for loadByQuery() and loadPageByQuery().

FieldTypeRequiredDescription
querystringRequiredThe search text. Each word must match. A word on its own matches if any searched property contains it. A word can also name a property and an operator, such as name:smith or amount>100. Put text with spaces in double quotes.
searchInPropertiesstring[]OptionalThe properties to search in. Default: the Entity properties marked as searchable by default.
caseSensitivebooleanOptionalIf true, upper and lower case must match. Default: false.

Availability: Both

interface AggregationInput<T, A extends 'count' | 'sum' | 'min' | 'max' | 'avg', K extends keyof T, O extends string> {
aggregationFunction: A
column: '*' | K
outputName: O
}

One value for aggregate() to compute per group.

FieldTypeRequiredDescription
aggregationFunction'count' | 'sum' | 'min' | 'max' | 'avg'RequiredThe function to apply.
column'*' | KRequiredThe property to apply it to, or '*' for all records (with 'count').
outputNameORequiredThe name of the field that holds the result.

Availability: Both

type AggregationOutput<T, A, G extends keyof T, K extends keyof T, O extends string> =
{ [P in G]: T[P] } & { [P in O]: A extends 'count' ? number : T[K] }

One result of aggregate(): the group-by properties with the group’s values, plus one field per outputName.

Availability: Both

type GroupedCount<T, G extends keyof T> = { [P in G]: T[P] } & { $count: number }

One result of count(): the group-by properties with the group’s values, plus the number of records in $count.

Availability: Both

type SavedIds<T> = {
id: T['id']
<oneToManyRelation>: (number | string)[]
<manyToOneRelation>: number | string
}

The ids a save assigned: the record’s id, and the ids of the related records saved with it, per relation.

Availability: Both

type DbVectorOperator = 'l1Distance' | 'l2Distance' | 'innerProduct' | 'cosineDistance'

How loadByVectorDistance() compares two vectors: 'l1Distance' (Manhattan distance), 'l2Distance' (Euclidean distance), 'innerProduct' (inner product) or 'cosineDistance'.

Availability: Both

Note

'cosineDistance' computes 1 minus the cosine distance, which is the cosine similarity: larger values mean more similar vectors.

  • Server Data Store
  • Entity API
  • Transactional Entities
  • Access Control

¹ On the client, the call is sent to the server and is subject to access control.