@lancedb/lancedb 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/arrow.d.ts +5 -3
  2. package/dist/arrow.js +1 -1
  3. package/dist/embedding/embedding_function.d.ts +4 -3
  4. package/dist/embedding/index.d.ts +1 -0
  5. package/dist/embedding/index.js +1 -0
  6. package/dist/embedding/registry.d.ts +9 -7
  7. package/dist/embedding/registry.js +24 -6
  8. package/dist/embedding/transformers.d.ts +37 -0
  9. package/dist/embedding/transformers.js +147 -0
  10. package/dist/query.js +15 -9
  11. package/dist/remote/client.d.ts +1 -1
  12. package/dist/remote/client.js +6 -8
  13. package/dist/remote/connection.d.ts +2 -3
  14. package/dist/remote/connection.js +2 -2
  15. package/dist/table.d.ts +3 -0
  16. package/dist/table.js +1 -1
  17. package/package.json +17 -14
  18. package/Cargo.toml +0 -28
  19. package/biome.json +0 -158
  20. package/build.rs +0 -5
  21. package/dist/native.d.ts +0 -208
  22. package/examples/ann_indexes.ts +0 -49
  23. package/examples/basic.ts +0 -149
  24. package/examples/embedding.ts +0 -83
  25. package/examples/filtering.ts +0 -34
  26. package/examples/jsconfig.json +0 -27
  27. package/examples/package-lock.json +0 -79
  28. package/examples/package.json +0 -18
  29. package/examples/search.ts +0 -37
  30. package/jest.config.js +0 -7
  31. package/lancedb/arrow.ts +0 -947
  32. package/lancedb/connection.ts +0 -333
  33. package/lancedb/embedding/embedding_function.ts +0 -194
  34. package/lancedb/embedding/index.ts +0 -113
  35. package/lancedb/embedding/openai.ts +0 -113
  36. package/lancedb/embedding/registry.ts +0 -188
  37. package/lancedb/index.ts +0 -142
  38. package/lancedb/indices.ts +0 -203
  39. package/lancedb/merge.ts +0 -70
  40. package/lancedb/query.ts +0 -507
  41. package/lancedb/remote/client.ts +0 -221
  42. package/lancedb/remote/connection.ts +0 -201
  43. package/lancedb/remote/index.ts +0 -3
  44. package/lancedb/remote/table.ts +0 -226
  45. package/lancedb/sanitize.ts +0 -588
  46. package/lancedb/table.ts +0 -669
  47. package/lancedb/util.ts +0 -69
  48. package/native.d.ts +0 -208
  49. package/nodejs-artifacts/arrow.d.ts +0 -250
  50. package/nodejs-artifacts/arrow.js +0 -768
  51. package/nodejs-artifacts/connection.d.ts +0 -171
  52. package/nodejs-artifacts/connection.js +0 -135
  53. package/nodejs-artifacts/embedding/embedding_function.d.ts +0 -79
  54. package/nodejs-artifacts/embedding/embedding_function.js +0 -112
  55. package/nodejs-artifacts/embedding/index.d.ts +0 -28
  56. package/nodejs-artifacts/embedding/index.js +0 -114
  57. package/nodejs-artifacts/embedding/openai.d.ts +0 -18
  58. package/nodejs-artifacts/embedding/openai.js +0 -105
  59. package/nodejs-artifacts/embedding/registry.d.ts +0 -53
  60. package/nodejs-artifacts/embedding/registry.js +0 -127
  61. package/nodejs-artifacts/index.d.ts +0 -55
  62. package/nodejs-artifacts/index.js +0 -57
  63. package/nodejs-artifacts/indices.d.ts +0 -165
  64. package/nodejs-artifacts/indices.js +0 -71
  65. package/nodejs-artifacts/merge.d.ts +0 -54
  66. package/nodejs-artifacts/merge.js +0 -64
  67. package/nodejs-artifacts/native.d.ts +0 -208
  68. package/nodejs-artifacts/native.js +0 -330
  69. package/nodejs-artifacts/query.d.ts +0 -283
  70. package/nodejs-artifacts/query.js +0 -448
  71. package/nodejs-artifacts/remote/client.d.ts +0 -28
  72. package/nodejs-artifacts/remote/client.js +0 -172
  73. package/nodejs-artifacts/remote/connection.d.ts +0 -25
  74. package/nodejs-artifacts/remote/connection.js +0 -110
  75. package/nodejs-artifacts/remote/index.d.ts +0 -3
  76. package/nodejs-artifacts/remote/index.js +0 -9
  77. package/nodejs-artifacts/remote/table.d.ts +0 -42
  78. package/nodejs-artifacts/remote/table.js +0 -179
  79. package/nodejs-artifacts/sanitize.d.ts +0 -31
  80. package/nodejs-artifacts/sanitize.js +0 -436
  81. package/nodejs-artifacts/table.d.ts +0 -395
  82. package/nodejs-artifacts/table.js +0 -230
  83. package/nodejs-artifacts/util.d.ts +0 -14
  84. package/nodejs-artifacts/util.js +0 -65
  85. package/tsconfig.json +0 -25
  86. package/typedoc.json +0 -10
package/biome.json DELETED
@@ -1,158 +0,0 @@
1
- {
2
- "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
3
- "organizeImports": {
4
- "enabled": true
5
- },
6
- "files": {
7
- "ignore": [
8
- "**/dist/**/*",
9
- "**/native.js",
10
- "**/native.d.ts",
11
- "**/npm/**/*",
12
- "**/.vscode/**"
13
- ]
14
- },
15
- "formatter": {
16
- "indentStyle": "space"
17
- },
18
- "linter": {
19
- "enabled": true,
20
- "rules": {
21
- "recommended": false,
22
- "complexity": {
23
- "noBannedTypes": "error",
24
- "noExtraBooleanCast": "error",
25
- "noMultipleSpacesInRegularExpressionLiterals": "error",
26
- "noUselessCatch": "error",
27
- "noUselessThisAlias": "error",
28
- "noUselessTypeConstraint": "error",
29
- "noWith": "error"
30
- },
31
- "correctness": {
32
- "noConstAssign": "error",
33
- "noConstantCondition": "error",
34
- "noEmptyCharacterClassInRegex": "error",
35
- "noEmptyPattern": "error",
36
- "noGlobalObjectCalls": "error",
37
- "noInnerDeclarations": "error",
38
- "noInvalidConstructorSuper": "error",
39
- "noNewSymbol": "error",
40
- "noNonoctalDecimalEscape": "error",
41
- "noPrecisionLoss": "error",
42
- "noSelfAssign": "error",
43
- "noSetterReturn": "error",
44
- "noSwitchDeclarations": "error",
45
- "noUndeclaredVariables": "error",
46
- "noUnreachable": "error",
47
- "noUnreachableSuper": "error",
48
- "noUnsafeFinally": "error",
49
- "noUnsafeOptionalChaining": "error",
50
- "noUnusedLabels": "error",
51
- "noUnusedVariables": "warn",
52
- "useIsNan": "error",
53
- "useValidForDirection": "error",
54
- "useYield": "error"
55
- },
56
- "style": {
57
- "noNamespace": "error",
58
- "useAsConstAssertion": "error",
59
- "useBlockStatements": "off",
60
- "useNamingConvention": {
61
- "level": "error",
62
- "options": {
63
- "strictCase": false
64
- }
65
- }
66
- },
67
- "suspicious": {
68
- "noAssignInExpressions": "error",
69
- "noAsyncPromiseExecutor": "error",
70
- "noCatchAssign": "error",
71
- "noClassAssign": "error",
72
- "noCompareNegZero": "error",
73
- "noControlCharactersInRegex": "error",
74
- "noDebugger": "error",
75
- "noDuplicateCase": "error",
76
- "noDuplicateClassMembers": "error",
77
- "noDuplicateObjectKeys": "error",
78
- "noDuplicateParameters": "error",
79
- "noEmptyBlockStatements": "error",
80
- "noExplicitAny": "warn",
81
- "noExtraNonNullAssertion": "error",
82
- "noFallthroughSwitchClause": "error",
83
- "noFunctionAssign": "error",
84
- "noGlobalAssign": "error",
85
- "noImportAssign": "error",
86
- "noMisleadingCharacterClass": "error",
87
- "noMisleadingInstantiator": "error",
88
- "noPrototypeBuiltins": "error",
89
- "noRedeclare": "error",
90
- "noShadowRestrictedNames": "error",
91
- "noUnsafeDeclarationMerging": "error",
92
- "noUnsafeNegation": "error",
93
- "useGetterReturn": "error",
94
- "useValidTypeof": "error"
95
- }
96
- },
97
- "ignore": [
98
- "**/dist/**/*",
99
- "**/native.js",
100
- "**/native.d.ts",
101
- "__test__/docs/**/*",
102
- "examples/**/*"
103
- ]
104
- },
105
- "javascript": {
106
- "globals": []
107
- },
108
- "overrides": [
109
- {
110
- "include": ["__test__/s3_integration.test.ts"],
111
- "linter": {
112
- "rules": {
113
- "style": {
114
- "useNamingConvention": "off"
115
- }
116
- }
117
- }
118
- },
119
- {
120
- "include": [
121
- "**/*.ts",
122
- "**/*.tsx",
123
- "**/*.mts",
124
- "**/*.cts",
125
- "__test__/*.test.ts"
126
- ],
127
- "linter": {
128
- "rules": {
129
- "correctness": {
130
- "noConstAssign": "off",
131
- "noGlobalObjectCalls": "off",
132
- "noInvalidConstructorSuper": "off",
133
- "noNewSymbol": "off",
134
- "noSetterReturn": "off",
135
- "noUndeclaredVariables": "off",
136
- "noUnreachable": "off",
137
- "noUnreachableSuper": "off"
138
- },
139
- "style": {
140
- "noArguments": "error",
141
- "noVar": "error",
142
- "useConst": "error"
143
- },
144
- "suspicious": {
145
- "noDuplicateClassMembers": "off",
146
- "noDuplicateObjectKeys": "off",
147
- "noDuplicateParameters": "off",
148
- "noFunctionAssign": "off",
149
- "noImportAssign": "off",
150
- "noRedeclare": "off",
151
- "noUnsafeNegation": "off",
152
- "useGetterReturn": "off"
153
- }
154
- }
155
- }
156
- }
157
- ]
158
- }
package/build.rs DELETED
@@ -1,5 +0,0 @@
1
- extern crate napi_build;
2
-
3
- fn main() {
4
- napi_build::setup();
5
- }
package/dist/native.d.ts DELETED
@@ -1,208 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
-
4
- /* auto-generated by NAPI-RS */
5
-
6
- /** A description of an index currently configured on a column */
7
- export interface IndexConfig {
8
- /** The name of the index */
9
- name: string
10
- /** The type of the index */
11
- indexType: string
12
- /**
13
- * The columns in the index
14
- *
15
- * Currently this is always an array of size 1. In the future there may
16
- * be more columns to represent composite indices.
17
- */
18
- columns: Array<string>
19
- }
20
- /** Statistics about a compaction operation. */
21
- export interface CompactionStats {
22
- /** The number of fragments removed */
23
- fragmentsRemoved: number
24
- /** The number of new, compacted fragments added */
25
- fragmentsAdded: number
26
- /** The number of data files removed */
27
- filesRemoved: number
28
- /** The number of new, compacted data files added */
29
- filesAdded: number
30
- }
31
- /** Statistics about a cleanup operation */
32
- export interface RemovalStats {
33
- /** The number of bytes removed */
34
- bytesRemoved: number
35
- /** The number of old versions removed */
36
- oldVersionsRemoved: number
37
- }
38
- /** Statistics about an optimize operation */
39
- export interface OptimizeStats {
40
- /** Statistics about the compaction operation */
41
- compaction: CompactionStats
42
- /** Statistics about the removal operation */
43
- prune: RemovalStats
44
- }
45
- /**
46
- * A definition of a column alteration. The alteration changes the column at
47
- * `path` to have the new name `name`, to be nullable if `nullable` is true,
48
- * and to have the data type `data_type`. At least one of `rename` or `nullable`
49
- * must be provided.
50
- */
51
- export interface ColumnAlteration {
52
- /**
53
- * The path to the column to alter. This is a dot-separated path to the column.
54
- * If it is a top-level column then it is just the name of the column. If it is
55
- * a nested column then it is the path to the column, e.g. "a.b.c" for a column
56
- * `c` nested inside a column `b` nested inside a column `a`.
57
- */
58
- path: string
59
- /**
60
- * The new name of the column. If not provided then the name will not be changed.
61
- * This must be distinct from the names of all other columns in the table.
62
- */
63
- rename?: string
64
- /** Set the new nullability. Note that a nullable column cannot be made non-nullable. */
65
- nullable?: boolean
66
- }
67
- /** A definition of a new column to add to a table. */
68
- export interface AddColumnsSql {
69
- /** The name of the new column. */
70
- name: string
71
- /**
72
- * The values to populate the new column with, as a SQL expression.
73
- * The expression can reference other columns in the table.
74
- */
75
- valueSql: string
76
- }
77
- export interface IndexStatistics {
78
- /** The number of rows indexed by the index */
79
- numIndexedRows: number
80
- /** The number of rows not indexed */
81
- numUnindexedRows: number
82
- /** The type of the index */
83
- indexType?: string
84
- /** The metadata for each index */
85
- indices: Array<IndexMetadata>
86
- }
87
- export interface IndexMetadata {
88
- metricType?: string
89
- indexType?: string
90
- }
91
- export interface ConnectionOptions {
92
- /**
93
- * (For LanceDB OSS only): The interval, in seconds, at which to check for
94
- * updates to the table from other processes. If None, then consistency is not
95
- * checked. For performance reasons, this is the default. For strong
96
- * consistency, set this to zero seconds. Then every read will check for
97
- * updates from other processes. As a compromise, you can set this to a
98
- * non-zero value for eventual consistency. If more than that interval
99
- * has passed since the last check, then the table will be checked for updates.
100
- * Note: this consistency only applies to read operations. Write operations are
101
- * always consistent.
102
- */
103
- readConsistencyInterval?: number
104
- /**
105
- * (For LanceDB OSS only): configuration for object storage.
106
- *
107
- * The available options are described at https://lancedb.github.io/lancedb/guides/storage/
108
- */
109
- storageOptions?: Record<string, string>
110
- }
111
- /** Write mode for writing a table. */
112
- export const enum WriteMode {
113
- Create = 'Create',
114
- Append = 'Append',
115
- Overwrite = 'Overwrite'
116
- }
117
- /** Write options when creating a Table. */
118
- export interface WriteOptions {
119
- /** Write mode for writing to a table. */
120
- mode?: WriteMode
121
- }
122
- export interface OpenTableOptions {
123
- storageOptions?: Record<string, string>
124
- }
125
- export class Connection {
126
- /** Create a new Connection instance from the given URI. */
127
- static new(uri: string, options: ConnectionOptions): Promise<Connection>
128
- display(): string
129
- isOpen(): boolean
130
- close(): void
131
- /** List all tables in the dataset. */
132
- tableNames(startAfter?: string | undefined | null, limit?: number | undefined | null): Promise<Array<string>>
133
- /**
134
- * Create table from a Apache Arrow IPC (file) buffer.
135
- *
136
- * Parameters:
137
- * - name: The name of the table.
138
- * - buf: The buffer containing the IPC file.
139
- *
140
- */
141
- createTable(name: string, buf: Buffer, mode: string, storageOptions?: Record<string, string> | undefined | null, useLegacyFormat?: boolean | undefined | null): Promise<Table>
142
- createEmptyTable(name: string, schemaBuf: Buffer, mode: string, storageOptions?: Record<string, string> | undefined | null, useLegacyFormat?: boolean | undefined | null): Promise<Table>
143
- openTable(name: string, storageOptions?: Record<string, string> | undefined | null, indexCacheSize?: number | undefined | null): Promise<Table>
144
- /** Drop table with the name. Or raise an error if the table does not exist. */
145
- dropTable(name: string): Promise<void>
146
- }
147
- export class Index {
148
- static ivfPq(distanceType?: string | undefined | null, numPartitions?: number | undefined | null, numSubVectors?: number | undefined | null, maxIterations?: number | undefined | null, sampleRate?: number | undefined | null): Index
149
- static btree(): Index
150
- }
151
- /** Typescript-style Async Iterator over RecordBatches */
152
- export class RecordBatchIterator {
153
- next(): Promise<Buffer | null>
154
- }
155
- /** A builder used to create and run a merge insert operation */
156
- export class NativeMergeInsertBuilder {
157
- whenMatchedUpdateAll(condition?: string | undefined | null): NativeMergeInsertBuilder
158
- whenNotMatchedInsertAll(): NativeMergeInsertBuilder
159
- whenNotMatchedBySourceDelete(filter?: string | undefined | null): NativeMergeInsertBuilder
160
- execute(buf: Buffer): Promise<void>
161
- }
162
- export class Query {
163
- onlyIf(predicate: string): void
164
- select(columns: Array<[string, string]>): void
165
- limit(limit: number): void
166
- nearestTo(vector: Float32Array): VectorQuery
167
- execute(maxBatchLength?: number | undefined | null): Promise<RecordBatchIterator>
168
- explainPlan(verbose: boolean): Promise<string>
169
- }
170
- export class VectorQuery {
171
- column(column: string): void
172
- distanceType(distanceType: string): void
173
- postfilter(): void
174
- refineFactor(refineFactor: number): void
175
- nprobes(nprobe: number): void
176
- bypassVectorIndex(): void
177
- onlyIf(predicate: string): void
178
- select(columns: Array<[string, string]>): void
179
- limit(limit: number): void
180
- execute(maxBatchLength?: number | undefined | null): Promise<RecordBatchIterator>
181
- explainPlan(verbose: boolean): Promise<string>
182
- }
183
- export class Table {
184
- name: string
185
- display(): string
186
- isOpen(): boolean
187
- close(): void
188
- /** Return Schema as empty Arrow IPC file. */
189
- schema(): Promise<Buffer>
190
- add(buf: Buffer, mode: string): Promise<void>
191
- countRows(filter?: string | undefined | null): Promise<number>
192
- delete(predicate: string): Promise<void>
193
- createIndex(index: Index | undefined | null, column: string, replace?: boolean | undefined | null): Promise<void>
194
- update(onlyIf: string | undefined | null, columns: Array<[string, string]>): Promise<void>
195
- query(): Query
196
- vectorSearch(vector: Float32Array): VectorQuery
197
- addColumns(transforms: Array<AddColumnsSql>): Promise<void>
198
- alterColumns(alterations: Array<ColumnAlteration>): Promise<void>
199
- dropColumns(columns: Array<string>): Promise<void>
200
- version(): Promise<number>
201
- checkout(version: number): Promise<void>
202
- checkoutLatest(): Promise<void>
203
- restore(): Promise<void>
204
- optimize(olderThanMs?: number | undefined | null): Promise<OptimizeStats>
205
- listIndices(): Promise<Array<IndexConfig>>
206
- indexStats(indexName: string): Promise<IndexStatistics | null>
207
- mergeInsert(on: Array<string>): NativeMergeInsertBuilder
208
- }
@@ -1,49 +0,0 @@
1
- // --8<-- [start:import]
2
- import * as lancedb from "@lancedb/lancedb";
3
- // --8<-- [end:import]
4
-
5
- // --8<-- [start:ingest]
6
- const db = await lancedb.connect("/tmp/lancedb/");
7
-
8
- const data = Array.from({ length: 10_000 }, (_, i) => ({
9
- vector: Array(1536).fill(i),
10
- id: `${i}`,
11
- content: "",
12
- longId: `${i}`,
13
- }));
14
-
15
- const table = await db.createTable("my_vectors", data, { mode: "overwrite" });
16
- await table.createIndex("vector", {
17
- config: lancedb.Index.ivfPq({
18
- numPartitions: 16,
19
- numSubVectors: 48,
20
- }),
21
- });
22
- // --8<-- [end:ingest]
23
-
24
- // --8<-- [start:search1]
25
- const _results1 = await table
26
- .search(Array(1536).fill(1.2))
27
- .limit(2)
28
- .nprobes(20)
29
- .refineFactor(10)
30
- .toArray();
31
- // --8<-- [end:search1]
32
-
33
- // --8<-- [start:search2]
34
- const _results2 = await table
35
- .search(Array(1536).fill(1.2))
36
- .where("id != '1141'")
37
- .limit(2)
38
- .toArray();
39
- // --8<-- [end:search2]
40
-
41
- // --8<-- [start:search3]
42
- const _results3 = await table
43
- .search(Array(1536).fill(1.2))
44
- .select(["id"])
45
- .limit(2)
46
- .toArray();
47
- // --8<-- [end:search3]
48
-
49
- console.log("Ann indexes: done");
package/examples/basic.ts DELETED
@@ -1,149 +0,0 @@
1
- // --8<-- [start:imports]
2
- import * as lancedb from "@lancedb/lancedb";
3
- import * as arrow from "apache-arrow";
4
- import { Field, FixedSizeList, Float16, Int32, Schema } from "apache-arrow";
5
-
6
- // --8<-- [end:imports]
7
-
8
- // --8<-- [start:connect]
9
- const uri = "/tmp/lancedb/";
10
- const db = await lancedb.connect(uri);
11
- // --8<-- [end:connect]
12
- {
13
- // --8<-- [start:create_table]
14
- const data = [
15
- { vector: [3.1, 4.1], item: "foo", price: 10.0 },
16
- { vector: [5.9, 26.5], item: "bar", price: 20.0 },
17
- ];
18
- const _tbl = await db.createTable("myTable", data);
19
- // --8<-- [end:create_table]
20
- {
21
- // --8<-- [start:create_table_exists_ok]
22
- const _tbl = await db.createTable("myTable", data, {
23
- existsOk: true,
24
- });
25
- // --8<-- [end:create_table_exists_ok]
26
- }
27
- {
28
- // --8<-- [start:create_table_overwrite]
29
- const _tbl = await db.createTable("myTable", data, {
30
- mode: "overwrite",
31
- });
32
- // --8<-- [end:create_table_overwrite]
33
- }
34
- }
35
-
36
- {
37
- // --8<-- [start:create_table_with_schema]
38
- const schema = new arrow.Schema([
39
- new arrow.Field(
40
- "vector",
41
- new arrow.FixedSizeList(
42
- 2,
43
- new arrow.Field("item", new arrow.Float32(), true),
44
- ),
45
- ),
46
- new arrow.Field("item", new arrow.Utf8(), true),
47
- new arrow.Field("price", new arrow.Float32(), true),
48
- ]);
49
- const data = [
50
- { vector: [3.1, 4.1], item: "foo", price: 10.0 },
51
- { vector: [5.9, 26.5], item: "bar", price: 20.0 },
52
- ];
53
- const _tbl = await db.createTable("myTable", data, {
54
- schema,
55
- });
56
- // --8<-- [end:create_table_with_schema]
57
- }
58
-
59
- {
60
- // --8<-- [start:create_empty_table]
61
- const schema = new arrow.Schema([
62
- new arrow.Field(
63
- "vector",
64
- new arrow.FixedSizeList(
65
- 2,
66
- new arrow.Field("item", new arrow.Float32(), true),
67
- ),
68
- ),
69
- ]);
70
- const _tbl = await db.createEmptyTable("empty_table", schema);
71
- // --8<-- [end:create_empty_table]
72
- }
73
- {
74
- // --8<-- [start:open_table]
75
- const _tbl = await db.openTable("myTable");
76
- // --8<-- [end:open_table]
77
- }
78
-
79
- {
80
- // --8<-- [start:table_names]
81
- const tableNames = await db.tableNames();
82
- console.log(tableNames);
83
- // --8<-- [end:table_names]
84
- }
85
-
86
- const tbl = await db.openTable("myTable");
87
- {
88
- // --8<-- [start:add_data]
89
- const data = [
90
- { vector: [1.3, 1.4], item: "fizz", price: 100.0 },
91
- { vector: [9.5, 56.2], item: "buzz", price: 200.0 },
92
- ];
93
- await tbl.add(data);
94
- // --8<-- [end:add_data]
95
- }
96
- {
97
- // --8<-- [start:vector_search]
98
- const _res = tbl.search([100, 100]).limit(2).toArray();
99
- // --8<-- [end:vector_search]
100
- }
101
- {
102
- const data = Array.from({ length: 1000 })
103
- .fill(null)
104
- .map(() => ({
105
- vector: [Math.random(), Math.random()],
106
- item: "autogen",
107
- price: Math.round(Math.random() * 100),
108
- }));
109
-
110
- await tbl.add(data);
111
- }
112
-
113
- // --8<-- [start:create_index]
114
- await tbl.createIndex("vector");
115
- // --8<-- [end:create_index]
116
-
117
- // --8<-- [start:delete_rows]
118
- await tbl.delete('item = "fizz"');
119
- // --8<-- [end:delete_rows]
120
-
121
- // --8<-- [start:drop_table]
122
- await db.dropTable("myTable");
123
- // --8<-- [end:drop_table]
124
- await db.dropTable("empty_table");
125
-
126
- {
127
- // --8<-- [start:create_f16_table]
128
- const db = await lancedb.connect("/tmp/lancedb");
129
- const dim = 16;
130
- const total = 10;
131
- const f16Schema = new Schema([
132
- new Field("id", new Int32()),
133
- new Field(
134
- "vector",
135
- new FixedSizeList(dim, new Field("item", new Float16(), true)),
136
- false,
137
- ),
138
- ]);
139
- const data = lancedb.makeArrowTable(
140
- Array.from(Array(total), (_, i) => ({
141
- id: i,
142
- vector: Array.from(Array(dim), Math.random),
143
- })),
144
- { schema: f16Schema },
145
- );
146
- const _table = await db.createTable("f16_tbl", data);
147
- // --8<-- [end:create_f16_table]
148
- await db.dropTable("f16_tbl");
149
- }
@@ -1,83 +0,0 @@
1
- // --8<-- [start:imports]
2
- import * as lancedb from "@lancedb/lancedb";
3
- import { LanceSchema, getRegistry, register } from "@lancedb/lancedb/embedding";
4
- import { EmbeddingFunction } from "@lancedb/lancedb/embedding";
5
- import { type Float, Float32, Utf8 } from "apache-arrow";
6
- // --8<-- [end:imports]
7
-
8
- {
9
- // --8<-- [start:openai_embeddings]
10
-
11
- const db = await lancedb.connect("/tmp/db");
12
- const func = getRegistry()
13
- .get("openai")
14
- ?.create({ model: "text-embedding-ada-002" }) as EmbeddingFunction;
15
-
16
- const wordsSchema = LanceSchema({
17
- text: func.sourceField(new Utf8()),
18
- vector: func.vectorField(),
19
- });
20
- const tbl = await db.createEmptyTable("words", wordsSchema, {
21
- mode: "overwrite",
22
- });
23
- await tbl.add([{ text: "hello world" }, { text: "goodbye world" }]);
24
-
25
- const query = "greetings";
26
- const actual = (await (await tbl.search(query)).limit(1).toArray())[0];
27
-
28
- // --8<-- [end:openai_embeddings]
29
- console.log("result = ", actual.text);
30
- }
31
-
32
- {
33
- // --8<-- [start:embedding_function]
34
- const db = await lancedb.connect("/tmp/db");
35
-
36
- @register("my_embedding")
37
- class MyEmbeddingFunction extends EmbeddingFunction<string> {
38
- toJSON(): object {
39
- return {};
40
- }
41
- ndims() {
42
- return 3;
43
- }
44
- embeddingDataType(): Float {
45
- return new Float32();
46
- }
47
- async computeQueryEmbeddings(_data: string) {
48
- // This is a placeholder for a real embedding function
49
- return [1, 2, 3];
50
- }
51
- async computeSourceEmbeddings(data: string[]) {
52
- // This is a placeholder for a real embedding function
53
- return Array.from({ length: data.length }).fill([1, 2, 3]) as number[][];
54
- }
55
- }
56
-
57
- const func = new MyEmbeddingFunction();
58
-
59
- const data = [{ text: "pepperoni" }, { text: "pineapple" }];
60
-
61
- // Option 1: manually specify the embedding function
62
- const table = await db.createTable("vectors", data, {
63
- embeddingFunction: {
64
- function: func,
65
- sourceColumn: "text",
66
- vectorColumn: "vector",
67
- },
68
- mode: "overwrite",
69
- });
70
-
71
- // Option 2: provide the embedding function through a schema
72
-
73
- const schema = LanceSchema({
74
- text: func.sourceField(new Utf8()),
75
- vector: func.vectorField(),
76
- });
77
-
78
- const table2 = await db.createTable("vectors2", data, {
79
- schema,
80
- mode: "overwrite",
81
- });
82
- // --8<-- [end:embedding_function]
83
- }
@@ -1,34 +0,0 @@
1
- import * as lancedb from "@lancedb/lancedb";
2
-
3
- const db = await lancedb.connect("data/sample-lancedb");
4
-
5
- const data = Array.from({ length: 10_000 }, (_, i) => ({
6
- vector: Array(1536).fill(i),
7
- id: i,
8
- item: `item ${i}`,
9
- strId: `${i}`,
10
- }));
11
-
12
- const tbl = await db.createTable("myVectors", data, { mode: "overwrite" });
13
-
14
- // --8<-- [start:search]
15
- const _result = await tbl
16
- .search(Array(1536).fill(0.5))
17
- .limit(1)
18
- .where("id = 10")
19
- .toArray();
20
- // --8<-- [end:search]
21
-
22
- // --8<-- [start:vec_search]
23
- await tbl
24
- .search(Array(1536).fill(0))
25
- .where("(item IN ('item 0', 'item 2')) AND (id > 10)")
26
- .postfilter()
27
- .toArray();
28
- // --8<-- [end:vec_search]
29
-
30
- // --8<-- [start:sql_search]
31
- await tbl.query().where("id = 10").limit(10).toArray();
32
- // --8<-- [end:sql_search]
33
-
34
- console.log("SQL search: done");