Skip to content

@lancedb/lancedb β€’ Docs


@lancedb/lancedb / embedding / EmbeddingFunction

Class: abstract EmbeddingFunction<T, M>

An embedding function that automatically creates vector representation for a given column.

Extended by

Type Parameters

β€’ T = any

β€’ M extends FunctionOptions = FunctionOptions

Constructors

new EmbeddingFunction()

new EmbeddingFunction<T, M>(): EmbeddingFunction<T, M>

Returns

EmbeddingFunction<T, M>

Methods

computeQueryEmbeddings()

computeQueryEmbeddings(data): Promise<number[] | Float32Array | Float64Array>

Compute the embeddings for a single query

Parameters

β€’ data: T

Returns

Promise<number[] | Float32Array | Float64Array>


computeSourceEmbeddings()

abstract computeSourceEmbeddings(data): Promise<number[][] | Float32Array[] | Float64Array[]>

Creates a vector representation for the given values.

Parameters

β€’ data: T[]

Returns

Promise<number[][] | Float32Array[] | Float64Array[]>


embeddingDataType()

abstract embeddingDataType(): Float<Floats>

The datatype of the embeddings

Returns

Float<Floats>


ndims()

ndims(): undefined | number

The number of dimensions of the embeddings

Returns

undefined | number


sourceField()

sourceField(optionsOrDatatype): [DataType<Type, any>, Map<string, EmbeddingFunction<any, FunctionOptions>>]

sourceField is used in combination with LanceSchema to provide a declarative data model

Parameters

β€’ optionsOrDatatype: DataType<Type, any> | Partial<FieldOptions<DataType<Type, any>>>

The options for the field or the datatype

Returns

[DataType<Type, any>, Map<string, EmbeddingFunction<any, FunctionOptions>>]

See

lancedb.LanceSchema


toJSON()

abstract toJSON(): Partial<M>

Convert the embedding function to a JSON object It is used to serialize the embedding function to the schema It's important that any object returned by this method contains all the necessary information to recreate the embedding function

It should return the same object that was passed to the constructor If it does not, the embedding function will not be able to be recreated, or could be recreated incorrectly

Returns

Partial<M>

Example

class MyEmbeddingFunction extends EmbeddingFunction {
  constructor(options: {model: string, timeout: number}) {
    super();
    this.model = options.model;
    this.timeout = options.timeout;
  }
  toJSON() {
    return {
      model: this.model,
      timeout: this.timeout,
    };
}

vectorField()

vectorField(optionsOrDatatype?): [DataType<Type, any>, Map<string, EmbeddingFunction<any, FunctionOptions>>]

vectorField is used in combination with LanceSchema to provide a declarative data model

Parameters

β€’ optionsOrDatatype?: DataType<Type, any> | Partial<FieldOptions<DataType<Type, any>>>

Returns

[DataType<Type, any>, Map<string, EmbeddingFunction<any, FunctionOptions>>]

See

lancedb.LanceSchema