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