@lancedb/lancedb 0.4.3 → 0.4.15

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 (64) hide show
  1. package/README.md +35 -3
  2. package/dist/arrow.d.ts +189 -0
  3. package/dist/arrow.js +539 -0
  4. package/dist/connection.d.ts +97 -0
  5. package/dist/connection.js +126 -0
  6. package/dist/embedding/embedding_function.d.ts +45 -0
  7. package/dist/embedding/embedding_function.js +27 -0
  8. package/dist/embedding/index.d.ts +2 -0
  9. package/dist/embedding/index.js +7 -0
  10. package/dist/embedding/openai.d.ts +8 -0
  11. package/dist/embedding/openai.js +53 -0
  12. package/dist/index.d.ts +22 -0
  13. package/dist/index.js +52 -0
  14. package/dist/indices.d.ts +165 -0
  15. package/dist/indices.js +71 -0
  16. package/dist/native.d.ts +147 -0
  17. package/dist/native.js +314 -0
  18. package/dist/query.d.ts +248 -0
  19. package/dist/query.js +346 -0
  20. package/dist/sanitize.d.ts +9 -0
  21. package/dist/sanitize.js +369 -0
  22. package/dist/table.d.ts +252 -0
  23. package/dist/table.js +298 -0
  24. package/nodejs-artifacts/arrow.d.ts +189 -0
  25. package/nodejs-artifacts/arrow.js +539 -0
  26. package/nodejs-artifacts/connection.d.ts +97 -0
  27. package/nodejs-artifacts/connection.js +126 -0
  28. package/nodejs-artifacts/embedding/embedding_function.d.ts +45 -0
  29. package/nodejs-artifacts/embedding/embedding_function.js +27 -0
  30. package/nodejs-artifacts/embedding/index.d.ts +2 -0
  31. package/nodejs-artifacts/embedding/index.js +7 -0
  32. package/nodejs-artifacts/embedding/openai.d.ts +8 -0
  33. package/nodejs-artifacts/embedding/openai.js +53 -0
  34. package/nodejs-artifacts/index.d.ts +22 -0
  35. package/nodejs-artifacts/index.js +52 -0
  36. package/nodejs-artifacts/indices.d.ts +165 -0
  37. package/nodejs-artifacts/indices.js +71 -0
  38. package/nodejs-artifacts/native.d.ts +147 -0
  39. package/nodejs-artifacts/native.js +314 -0
  40. package/nodejs-artifacts/query.d.ts +248 -0
  41. package/nodejs-artifacts/query.js +346 -0
  42. package/nodejs-artifacts/sanitize.d.ts +9 -0
  43. package/nodejs-artifacts/sanitize.js +369 -0
  44. package/nodejs-artifacts/table.d.ts +252 -0
  45. package/nodejs-artifacts/table.js +298 -0
  46. package/package.json +9 -11
  47. package/typedoc.json +10 -0
  48. package/examples/js/index.mjs +0 -40
  49. package/examples/js/package.json +0 -14
  50. package/examples/js-openai/index.mjs +0 -43
  51. package/examples/js-openai/package-lock.json +0 -256
  52. package/examples/js-openai/package.json +0 -15
  53. package/examples/js-transformers/index.mjs +0 -65
  54. package/examples/js-transformers/package-lock.json +0 -1418
  55. package/examples/js-transformers/package.json +0 -15
  56. package/examples/js-youtube-transcripts/index.mjs +0 -135
  57. package/examples/js-youtube-transcripts/package.json +0 -15
  58. package/examples/ts/data/sample-lancedb/vectors.lance/_latest.manifest +0 -0
  59. package/examples/ts/data/sample-lancedb/vectors.lance/_transactions/0-adde4e05-fcfc-415c-86a6-5b252cb9e79a.txn +0 -0
  60. package/examples/ts/data/sample-lancedb/vectors.lance/_versions/1.manifest +0 -0
  61. package/examples/ts/data/sample-lancedb/vectors.lance/data/3618b33e-3eea-4b5e-a0fc-7d1f718d551e.lance +0 -0
  62. package/examples/ts/package-lock.json +0 -1340
  63. package/examples/ts/package.json +0 -22
  64. package/examples/ts/tsconfig.json +0 -10
package/README.md CHANGED
@@ -1,12 +1,44 @@
1
- # (New) LanceDB NodeJS SDK
1
+ # LanceDB JavaScript SDK
2
2
 
3
- It will replace the NodeJS SDK when it is ready.
3
+ A JavaScript library for [LanceDB](https://github.com/lancedb/lancedb).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @lancedb/lancedb
9
+ ```
10
+
11
+ This will download the appropriate native library for your platform. We currently
12
+ support:
13
+
14
+ - Linux (x86_64 and aarch64)
15
+ - MacOS (Intel and ARM/M1/M2)
16
+ - Windows (x86_64 only)
17
+
18
+ We do not yet support musl-based Linux (such as Alpine Linux) or aarch64 Windows.
19
+
20
+ ## Usage
21
+
22
+ ### Basic Example
23
+
24
+ ```javascript
25
+ import * as lancedb from "@lancedb/lancedb";
26
+ const db = await lancedb.connect("data/sample-lancedb");
27
+ const table = await db.createTable("my_table", [
28
+ { id: 1, vector: [0.1, 1.0], item: "foo", price: 10.0 },
29
+ { id: 2, vector: [3.9, 0.5], item: "bar", price: 20.0 },
30
+ ]);
31
+ const results = await table.vectorSearch([0.1, 0.3]).limit(20).toArray();
32
+ console.log(results);
33
+ ```
34
+
35
+ The [quickstart](../basic.md) contains a more complete example.
4
36
 
5
37
  ## Development
6
38
 
7
39
  ```sh
8
40
  npm run build
9
- npm t
41
+ npm run test
10
42
  ```
11
43
 
12
44
  ### Running lint / format
@@ -0,0 +1,189 @@
1
+ /// <reference types="node" />
2
+ import { type Schema, Table as ArrowTable, type Float } from "apache-arrow";
3
+ import { type EmbeddingFunction } from "./embedding/embedding_function";
4
+ /** Data type accepted by NodeJS SDK */
5
+ export type Data = Record<string, unknown>[] | ArrowTable;
6
+ export declare class VectorColumnOptions {
7
+ /** Vector column type. */
8
+ type: Float;
9
+ constructor(values?: Partial<VectorColumnOptions>);
10
+ }
11
+ /** Options to control the makeArrowTable call. */
12
+ export declare class MakeArrowTableOptions {
13
+ schema?: Schema;
14
+ vectorColumns: Record<string, VectorColumnOptions>;
15
+ /**
16
+ * If true then string columns will be encoded with dictionary encoding
17
+ *
18
+ * Set this to true if your string columns tend to repeat the same values
19
+ * often. For more precise control use the `schema` property to specify the
20
+ * data type for individual columns.
21
+ *
22
+ * If `schema` is provided then this property is ignored.
23
+ */
24
+ dictionaryEncodeStrings: boolean;
25
+ constructor(values?: Partial<MakeArrowTableOptions>);
26
+ }
27
+ /**
28
+ * An enhanced version of the {@link makeTable} function from Apache Arrow
29
+ * that supports nested fields and embeddings columns.
30
+ *
31
+ * (typically you do not need to call this function. It will be called automatically
32
+ * when creating a table or adding data to it)
33
+ *
34
+ * This function converts an array of Record<String, any> (row-major JS objects)
35
+ * to an Arrow Table (a columnar structure)
36
+ *
37
+ * Note that it currently does not support nulls.
38
+ *
39
+ * If a schema is provided then it will be used to determine the resulting array
40
+ * types. Fields will also be reordered to fit the order defined by the schema.
41
+ *
42
+ * If a schema is not provided then the types will be inferred and the field order
43
+ * will be controlled by the order of properties in the first record. If a type
44
+ * is inferred it will always be nullable.
45
+ *
46
+ * If the input is empty then a schema must be provided to create an empty table.
47
+ *
48
+ * When a schema is not specified then data types will be inferred. The inference
49
+ * rules are as follows:
50
+ *
51
+ * - boolean => Bool
52
+ * - number => Float64
53
+ * - String => Utf8
54
+ * - Buffer => Binary
55
+ * - Record<String, any> => Struct
56
+ * - Array<any> => List
57
+ * @example
58
+ * import { fromTableToBuffer, makeArrowTable } from "../arrow";
59
+ * import { Field, FixedSizeList, Float16, Float32, Int32, Schema } from "apache-arrow";
60
+ *
61
+ * const schema = new Schema([
62
+ * new Field("a", new Int32()),
63
+ * new Field("b", new Float32()),
64
+ * new Field("c", new FixedSizeList(3, new Field("item", new Float16()))),
65
+ * ]);
66
+ * const table = makeArrowTable([
67
+ * { a: 1, b: 2, c: [1, 2, 3] },
68
+ * { a: 4, b: 5, c: [4, 5, 6] },
69
+ * { a: 7, b: 8, c: [7, 8, 9] },
70
+ * ], { schema });
71
+ * ```
72
+ *
73
+ * By default it assumes that the column named `vector` is a vector column
74
+ * and it will be converted into a fixed size list array of type float32.
75
+ * The `vectorColumns` option can be used to support other vector column
76
+ * names and data types.
77
+ *
78
+ * ```ts
79
+ *
80
+ * const schema = new Schema([
81
+ new Field("a", new Float64()),
82
+ new Field("b", new Float64()),
83
+ new Field(
84
+ "vector",
85
+ new FixedSizeList(3, new Field("item", new Float32()))
86
+ ),
87
+ ]);
88
+ const table = makeArrowTable([
89
+ { a: 1, b: 2, vector: [1, 2, 3] },
90
+ { a: 4, b: 5, vector: [4, 5, 6] },
91
+ { a: 7, b: 8, vector: [7, 8, 9] },
92
+ ]);
93
+ assert.deepEqual(table.schema, schema);
94
+ * ```
95
+ *
96
+ * You can specify the vector column types and names using the options as well
97
+ *
98
+ * ```typescript
99
+ *
100
+ * const schema = new Schema([
101
+ new Field('a', new Float64()),
102
+ new Field('b', new Float64()),
103
+ new Field('vec1', new FixedSizeList(3, new Field('item', new Float16()))),
104
+ new Field('vec2', new FixedSizeList(3, new Field('item', new Float16())))
105
+ ]);
106
+ * const table = makeArrowTable([
107
+ { a: 1, b: 2, vec1: [1, 2, 3], vec2: [2, 4, 6] },
108
+ { a: 4, b: 5, vec1: [4, 5, 6], vec2: [8, 10, 12] },
109
+ { a: 7, b: 8, vec1: [7, 8, 9], vec2: [14, 16, 18] }
110
+ ], {
111
+ vectorColumns: {
112
+ vec1: { type: new Float16() },
113
+ vec2: { type: new Float16() }
114
+ }
115
+ }
116
+ * assert.deepEqual(table.schema, schema)
117
+ * ```
118
+ */
119
+ export declare function makeArrowTable(data: Array<Record<string, unknown>>, options?: Partial<MakeArrowTableOptions>): ArrowTable;
120
+ /**
121
+ * Create an empty Arrow table with the provided schema
122
+ */
123
+ export declare function makeEmptyTable(schema: Schema): ArrowTable;
124
+ /**
125
+ * Convert an Array of records into an Arrow Table, optionally applying an
126
+ * embeddings function to it.
127
+ *
128
+ * This function calls `makeArrowTable` first to create the Arrow Table.
129
+ * Any provided `makeTableOptions` (e.g. a schema) will be passed on to
130
+ * that call.
131
+ *
132
+ * The embedding function will be passed a column of values (based on the
133
+ * `sourceColumn` of the embedding function) and expects to receive back
134
+ * number[][] which will be converted into a fixed size list column. By
135
+ * default this will be a fixed size list of Float32 but that can be
136
+ * customized by the `embeddingDataType` property of the embedding function.
137
+ *
138
+ * If a schema is provided in `makeTableOptions` then it should include the
139
+ * embedding columns. If no schema is provded then embedding columns will
140
+ * be placed at the end of the table, after all of the input columns.
141
+ */
142
+ export declare function convertToTable<T>(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunction<T>, makeTableOptions?: Partial<MakeArrowTableOptions>): Promise<ArrowTable>;
143
+ /**
144
+ * Serialize an Array of records into a buffer using the Arrow IPC File serialization
145
+ *
146
+ * This function will call `convertToTable` and pass on `embeddings` and `schema`
147
+ *
148
+ * `schema` is required if data is empty
149
+ */
150
+ export declare function fromRecordsToBuffer<T>(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
151
+ /**
152
+ * Serialize an Array of records into a buffer using the Arrow IPC Stream serialization
153
+ *
154
+ * This function will call `convertToTable` and pass on `embeddings` and `schema`
155
+ *
156
+ * `schema` is required if data is empty
157
+ */
158
+ export declare function fromRecordsToStreamBuffer<T>(data: Array<Record<string, unknown>>, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
159
+ /**
160
+ * Serialize an Arrow Table into a buffer using the Arrow IPC File serialization
161
+ *
162
+ * This function will apply `embeddings` to the table in a manner similar to
163
+ * `convertToTable`.
164
+ *
165
+ * `schema` is required if the table is empty
166
+ */
167
+ export declare function fromTableToBuffer<T>(table: ArrowTable, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
168
+ /**
169
+ * Serialize an Arrow Table into a buffer using the Arrow IPC File serialization
170
+ *
171
+ * This function will apply `embeddings` to the table in a manner similar to
172
+ * `convertToTable`.
173
+ *
174
+ * `schema` is required if the table is empty
175
+ */
176
+ export declare function fromDataToBuffer<T>(data: Data, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
177
+ /**
178
+ * Serialize an Arrow Table into a buffer using the Arrow IPC Stream serialization
179
+ *
180
+ * This function will apply `embeddings` to the table in a manner similar to
181
+ * `convertToTable`.
182
+ *
183
+ * `schema` is required if the table is empty
184
+ */
185
+ export declare function fromTableToStreamBuffer<T>(table: ArrowTable, embeddings?: EmbeddingFunction<T>, schema?: Schema): Promise<Buffer>;
186
+ /**
187
+ * Create an empty table with the given schema
188
+ */
189
+ export declare function createEmptyTable(schema: Schema): ArrowTable;