Skip to content

@lancedb/lancedb β€’ Docs


@lancedb/lancedb / embedding / TextEmbeddingFunction

Class: abstract TextEmbeddingFunction<M>

an abstract class for implementing embedding functions that take text as input

Extends

Type Parameters

β€’ M extends FunctionOptions = FunctionOptions

Constructors

new TextEmbeddingFunction()

new TextEmbeddingFunction<M>(): TextEmbeddingFunction<M>

Returns

TextEmbeddingFunction<M>

Inherited from

EmbeddingFunction.constructor

Methods

computeQueryEmbeddings()

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

Compute the embeddings for a single query

Parameters

  • data: string

Returns

Promise<number[] | Float32Array | Float64Array>

Overrides

EmbeddingFunction.computeQueryEmbeddings


computeSourceEmbeddings()

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

Creates a vector representation for the given values.

Parameters

  • data: string[]

Returns

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

Overrides

EmbeddingFunction.computeSourceEmbeddings


embeddingDataType()

embeddingDataType(): Float<Floats>

The datatype of the embeddings

Returns

Float<Floats>

Overrides

EmbeddingFunction.embeddingDataType


generateEmbeddings()

abstract generateEmbeddings(texts, ...args): Promise<number[][] | Float32Array[] | Float64Array[]>

Parameters

  • texts: string[]

  • ...args: any[]

Returns

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


init()?

optional init(): Promise<void>

Returns

Promise<void>

Inherited from

EmbeddingFunction.init


ndims()

ndims(): undefined | number

The number of dimensions of the embeddings

Returns

undefined | number

Inherited from

EmbeddingFunction.ndims


sourceField()

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

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

Returns

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

See

lancedb.LanceSchema

Overrides

EmbeddingFunction.sourceField


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,
    };
}

Inherited from

EmbeddingFunction.toJSON


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

Inherited from

EmbeddingFunction.vectorField