@lancedb/lancedb β’ Docs
@lancedb/lancedb / embedding / OpenAIEmbeddingFunction
Class: OpenAIEmbeddingFunction
An embedding function that automatically creates vector representation for a given column.
Extends
EmbeddingFunction
<string
,Partial
<OpenAIOptions
>>
Constructors
new OpenAIEmbeddingFunction()
new OpenAIEmbeddingFunction(
options
):OpenAIEmbeddingFunction
Parameters
β’ options: Partial
<OpenAIOptions
> = ...
Returns
Overrides
Methods
computeQueryEmbeddings()
computeQueryEmbeddings(
data
):Promise
<number
[]>
Compute the embeddings for a single query
Parameters
β’ data: string
Returns
Promise
<number
[]>
Overrides
EmbeddingFunction
.computeQueryEmbeddings
computeSourceEmbeddings()
computeSourceEmbeddings(
data
):Promise
<number
[][]>
Creates a vector representation for the given values.
Parameters
β’ data: string
[]
Returns
Promise
<number
[][]>
Overrides
EmbeddingFunction
.computeSourceEmbeddings
embeddingDataType()
embeddingDataType():
Float
<Floats
>
The datatype of the embeddings
Returns
Float
<Floats
>
Overrides
EmbeddingFunction
.embeddingDataType
ndims()
ndims():
number
The number of dimensions of the embeddings
Returns
number
Overrides
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
Inherited from
toJSON()
toJSON():
object
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
object
model
model:
string
&object
|"text-embedding-ada-002"
|"text-embedding-3-small"
|"text-embedding-3-large"
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,
};
}
Overrides
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