Elffuss BraidHub

kikocis/lancedb public

e822b4e34fb7 · 3.7 KiBRenderedRawPermalink
1[**@lancedb/lancedb**](../../../README.md) • **Docs**
2
3***
4
5[@lancedb/lancedb](../../../globals.md) / [embedding](../README.md) / EmbeddingFunction
6
7# Class: `abstract` EmbeddingFunction<T, M>
8
9An embedding function that automatically creates vector representation for a given column.
10
11## Extended by
12
13- [`OpenAIEmbeddingFunction`](OpenAIEmbeddingFunction.md)
14
15## Type Parameters
16
17• **T** = `any`
18
19• **M** *extends* `FunctionOptions` = `FunctionOptions`
20
21## Constructors
22
23### new EmbeddingFunction()
24
25> **new EmbeddingFunction**<`T`, `M`>(): [`EmbeddingFunction`](EmbeddingFunction.md)<`T`, `M`>
26
27#### Returns
28
29[`EmbeddingFunction`](EmbeddingFunction.md)<`T`, `M`>
30
31## Methods
32
33### computeQueryEmbeddings()
34
35> **computeQueryEmbeddings**(`data`): `Promise`<`number`[] \| `Float32Array` \| `Float64Array`>
36
37Compute the embeddings for a single query
38
39#### Parameters
40
41• **data**: `T`
42
43#### Returns
44
45`Promise`<`number`[] \| `Float32Array` \| `Float64Array`>
46
47***
48
49### computeSourceEmbeddings()
50
51> `abstract` **computeSourceEmbeddings**(`data`): `Promise`<`number`[][] \| `Float32Array`[] \| `Float64Array`[]>
52
53Creates a vector representation for the given values.
54
55#### Parameters
56
57• **data**: `T`[]
58
59#### Returns
60
61`Promise`<`number`[][] \| `Float32Array`[] \| `Float64Array`[]>
62
63***
64
65### embeddingDataType()
66
67> `abstract` **embeddingDataType**(): `Float`<`Floats`>
68
69The datatype of the embeddings
70
71#### Returns
72
73`Float`<`Floats`>
74
75***
76
77### ndims()
78
79> **ndims**(): `undefined` \| `number`
80
81The number of dimensions of the embeddings
82
83#### Returns
84
85`undefined` \| `number`
86
87***
88
89### sourceField()
90
91> **sourceField**(`optionsOrDatatype`): [`DataType`<`Type`, `any`>, `Map`<`string`, [`EmbeddingFunction`](EmbeddingFunction.md)<`any`, `FunctionOptions`>>]
92
93sourceField is used in combination with `LanceSchema` to provide a declarative data model
94
95#### Parameters
96
97• **optionsOrDatatype**: `DataType`<`Type`, `any`> \| `Partial`<`FieldOptions`<`DataType`<`Type`, `any`>>>
98
99The options for the field or the datatype
100
101#### Returns
102
103[`DataType`<`Type`, `any`>, `Map`<`string`, [`EmbeddingFunction`](EmbeddingFunction.md)<`any`, `FunctionOptions`>>]
104
105#### See
106
107lancedb.LanceSchema
108
109***
110
111### toJSON()
112
113> `abstract` **toJSON**(): `Partial`<`M`>
114
115Convert the embedding function to a JSON object
116It is used to serialize the embedding function to the schema
117It's important that any object returned by this method contains all the necessary
118information to recreate the embedding function
119
120It should return the same object that was passed to the constructor
121If it does not, the embedding function will not be able to be recreated, or could be recreated incorrectly
122
123#### Returns
124
125`Partial`<`M`>
126
127#### Example
128
129```ts
130class MyEmbeddingFunction extends EmbeddingFunction {
131 constructor(options: {model: string, timeout: number}) {
132 super();
133 this.model = options.model;
134 this.timeout = options.timeout;
135 }
136 toJSON() {
137 return {
138 model: this.model,
139 timeout: this.timeout,
140 };
141}
142```
143
144***
145
146### vectorField()
147
148> **vectorField**(`optionsOrDatatype`?): [`DataType`<`Type`, `any`>, `Map`<`string`, [`EmbeddingFunction`](EmbeddingFunction.md)<`any`, `FunctionOptions`>>]
149
150vectorField is used in combination with `LanceSchema` to provide a declarative data model
151
152#### Parameters
153
154• **optionsOrDatatype?**: `DataType`<`Type`, `any`> \| `Partial`<`FieldOptions`<`DataType`<`Type`, `any`>>>
155
156#### Returns
157
158[`DataType`<`Type`, `any`>, `Map`<`string`, [`EmbeddingFunction`](EmbeddingFunction.md)<`any`, `FunctionOptions`>>]
159
160#### See
161
162lancedb.LanceSchema