[**@lancedb/lancedb**](../../../README.md) • **Docs** *** [@lancedb/lancedb](../../../globals.md) / [embedding](../README.md) / EmbeddingFunction # Class: `abstract` EmbeddingFunction<T, M> An embedding function that automatically creates vector representation for a given column. It's important subclasses pass the **original** options to the super constructor and then pass those options to `resolveVariables` to resolve any variables before using them. ## Example ```ts class MyEmbeddingFunction extends EmbeddingFunction { constructor(options: {model: string, timeout: number}) { super(optionsRaw); const options = this.resolveVariables(optionsRaw); this.model = options.model; this.timeout = options.timeout; } } ``` ## Extended by - [`TextEmbeddingFunction`](TextEmbeddingFunction.md) ## Type Parameters • **T** = `any` • **M** *extends* [`FunctionOptions`](../interfaces/FunctionOptions.md) = [`FunctionOptions`](../interfaces/FunctionOptions.md) ## Constructors ### new EmbeddingFunction() ```ts new EmbeddingFunction(): EmbeddingFunction ``` #### Returns [`EmbeddingFunction`](EmbeddingFunction.md)<`T`, `M`> ## Methods ### computeQueryEmbeddings() ```ts computeQueryEmbeddings(data): Promise ``` Compute the embeddings for a single query #### Parameters * **data**: `T` #### Returns `Promise`<`number`[] \| `Float32Array` \| `Float64Array`> *** ### computeSourceEmbeddings() ```ts abstract computeSourceEmbeddings(data): Promise ``` Creates a vector representation for the given values. #### Parameters * **data**: `T`[] #### Returns `Promise`<`number`[][] \| `Float32Array`[] \| `Float64Array`[]> *** ### embeddingDataType() ```ts abstract embeddingDataType(): Float ``` The datatype of the embeddings #### Returns `Float`<`Floats`> *** ### getSensitiveKeys() ```ts protected getSensitiveKeys(): string[] ``` Provide a list of keys in the function options that should be treated as sensitive. If users pass raw values for these keys, they will be rejected. #### Returns `string`[] *** ### init()? ```ts optional init(): Promise ``` Optionally load any resources needed for the embedding function. This method is called after the embedding function has been initialized but before any embeddings are computed. It is useful for loading local models or other resources that are needed for the embedding function to work. #### Returns `Promise`<`void`> *** ### ndims() ```ts ndims(): undefined | number ``` The number of dimensions of the embeddings #### Returns `undefined` \| `number` *** ### resolveVariables() ```ts protected resolveVariables(config): Partial ``` Apply variables to the config. #### Parameters * **config**: `Partial`<`M`> #### Returns `Partial`<`M`> *** ### sourceField() ```ts sourceField(optionsOrDatatype): [DataType, Map>] ``` sourceField is used in combination with `LanceSchema` to provide a declarative data model #### Parameters * **optionsOrDatatype**: `DataType`<`Type`, `any`> \| `Partial`<[`FieldOptions`](../interfaces/FieldOptions.md)<`DataType`<`Type`, `any`>>> The options for the field or the datatype #### Returns [`DataType`<`Type`, `any`>, `Map`<`string`, [`EmbeddingFunction`](EmbeddingFunction.md)<`any`, [`FunctionOptions`](../interfaces/FunctionOptions.md)>>] #### See [LanceSchema](../functions/LanceSchema.md) *** ### toJSON() ```ts toJSON(): Record ``` Get the original arguments to the constructor, to serialize them so they can be used to recreate the embedding function later. #### Returns `Record`<`string`, `any`> *** ### vectorField() ```ts vectorField(optionsOrDatatype?): [DataType, Map>] ``` vectorField is used in combination with `LanceSchema` to provide a declarative data model #### Parameters * **optionsOrDatatype?**: `DataType`<`Type`, `any`> \| `Partial`<[`FieldOptions`](../interfaces/FieldOptions.md)<`DataType`<`Type`, `any`>>> The options for the field #### Returns [`DataType`<`Type`, `any`>, `Map`<`string`, [`EmbeddingFunction`](EmbeddingFunction.md)<`any`, [`FunctionOptions`](../interfaces/FunctionOptions.md)>>] #### See [LanceSchema](../functions/LanceSchema.md)