Elffuss BraidHub

kikocis/lancedb public

bbc8a2ecbe2c · 5.8 KiBRenderedRawPermalink
1[**@lancedb/lancedb**](../README.md) • **Docs**
2
3***
4
5[@lancedb/lancedb](../globals.md) / QueryBase
6
7# Class: QueryBase<NativeQueryType>
8
9Common methods supported by all query types
10
11## Extended by
12
13- [`Query`](Query.md)
14- [`VectorQuery`](VectorQuery.md)
15
16## Type Parameters
17
18• **NativeQueryType** *extends* `NativeQuery` \| `NativeVectorQuery`
19
20## Implements
21
22- `AsyncIterable`<`RecordBatch`>
23
24## Constructors
25
26### new QueryBase()
27
28> `protected` **new QueryBase**<`NativeQueryType`>(`inner`): [`QueryBase`](QueryBase.md)<`NativeQueryType`>
29
30#### Parameters
31
32• **inner**: `NativeQueryType` \| `Promise`<`NativeQueryType`>
33
34#### Returns
35
36[`QueryBase`](QueryBase.md)<`NativeQueryType`>
37
38## Properties
39
40### inner
41
42> `protected` **inner**: `NativeQueryType` \| `Promise`<`NativeQueryType`>
43
44## Methods
45
46### \[asyncIterator\]()
47
48> **\[asyncIterator\]**(): `AsyncIterator`<`RecordBatch`<`any`>, `any`, `undefined`>
49
50#### Returns
51
52`AsyncIterator`<`RecordBatch`<`any`>, `any`, `undefined`>
53
54#### Implementation of
55
56`AsyncIterable.[asyncIterator]`
57
58***
59
60### doCall()
61
62> `protected` **doCall**(`fn`): `void`
63
64#### Parameters
65
66• **fn**
67
68#### Returns
69
70`void`
71
72***
73
74### execute()
75
76> `protected` **execute**(`options`?): [`RecordBatchIterator`](RecordBatchIterator.md)
77
78Execute the query and return the results as an
79
80#### Parameters
81
82• **options?**: `Partial`<`QueryExecutionOptions`>
83
84#### Returns
85
86[`RecordBatchIterator`](RecordBatchIterator.md)
87
88#### See
89
90 - AsyncIterator
91of
92 - RecordBatch.
93
94By default, LanceDb will use many threads to calculate results and, when
95the result set is large, multiple batches will be processed at one time.
96This readahead is limited however and backpressure will be applied if this
97stream is consumed slowly (this constrains the maximum memory used by a
98single query)
99
100***
101
102### explainPlan()
103
104> **explainPlan**(`verbose`): `Promise`<`string`>
105
106Generates an explanation of the query execution plan.
107
108#### Parameters
109
110• **verbose**: `boolean` = `false`
111
112If true, provides a more detailed explanation. Defaults to false.
113
114#### Returns
115
116`Promise`<`string`>
117
118A Promise that resolves to a string containing the query execution plan explanation.
119
120#### Example
121
122```ts
123import * as lancedb from "@lancedb/lancedb"
124const db = await lancedb.connect("./.lancedb");
125const table = await db.createTable("my_table", [
126 { vector: [1.1, 0.9], id: "1" },
127]);
128const plan = await table.query().nearestTo([0.5, 0.2]).explainPlan();
129```
130
131***
132
133### ~~filter()~~
134
135> **filter**(`predicate`): `this`
136
137A filter statement to be applied to this query.
138
139#### Parameters
140
141• **predicate**: `string`
142
143#### Returns
144
145`this`
146
147#### Alias
148
149where
150
151#### Deprecated
152
153Use `where` instead
154
155***
156
157### limit()
158
159> **limit**(`limit`): `this`
160
161Set the maximum number of results to return.
162
163By default, a plain search has no limit. If this method is not
164called then every valid row from the table will be returned.
165
166#### Parameters
167
168• **limit**: `number`
169
170#### Returns
171
172`this`
173
174***
175
176### nativeExecute()
177
178> `protected` **nativeExecute**(`options`?): `Promise`<`RecordBatchIterator`>
179
180#### Parameters
181
182• **options?**: `Partial`<`QueryExecutionOptions`>
183
184#### Returns
185
186`Promise`<`RecordBatchIterator`>
187
188***
189
190### select()
191
192> **select**(`columns`): `this`
193
194Return only the specified columns.
195
196By default a query will return all columns from the table. However, this can have
197a very significant impact on latency. LanceDb stores data in a columnar fashion. This
198means we can finely tune our I/O to select exactly the columns we need.
199
200As a best practice you should always limit queries to the columns that you need. If you
201pass in an array of column names then only those columns will be returned.
202
203You can also use this method to create new "dynamic" columns based on your existing columns.
204For example, you may not care about "a" or "b" but instead simply want "a + b". This is often
205seen in the SELECT clause of an SQL query (e.g. `SELECT a+b FROM my_table`).
206
207To create dynamic columns you can pass in a Map<string, string>. A column will be returned
208for each entry in the map. The key provides the name of the column. The value is
209an SQL string used to specify how the column is calculated.
210
211For example, an SQL query might state `SELECT a + b AS combined, c`. The equivalent
212input to this method would be:
213
214#### Parameters
215
216• **columns**: `string` \| `string`[] \| `Record`&lt;`string`, `string`&gt; \| `Map`&lt;`string`, `string`&gt;
217
218#### Returns
219
220`this`
221
222#### Example
223
224```ts
225new Map([["combined", "a + b"], ["c", "c"]])
226
227Columns will always be returned in the order given, even if that order is different than
228the order used when adding the data.
229
230Note that you can pass in a `Record<string, string>` (e.g. an object literal). This method
231uses `Object.entries` which should preserve the insertion order of the object. However,
232object insertion order is easy to get wrong and `Map` is more foolproof.
233```
234
235***
236
237### toArray()
238
239> **toArray**(`options`?): `Promise`&lt;`any`[]&gt;
240
241Collect the results as an array of objects.
242
243#### Parameters
244
245• **options?**: `Partial`&lt;`QueryExecutionOptions`&gt;
246
247#### Returns
248
249`Promise`&lt;`any`[]&gt;
250
251***
252
253### toArrow()
254
255> **toArrow**(`options`?): `Promise`&lt;`Table`&lt;`any`&gt;&gt;
256
257Collect the results as an Arrow
258
259#### Parameters
260
261• **options?**: `Partial`&lt;`QueryExecutionOptions`&gt;
262
263#### Returns
264
265`Promise`&lt;`Table`&lt;`any`&gt;&gt;
266
267#### See
268
269ArrowTable.
270
271***
272
273### where()
274
275> **where**(`predicate`): `this`
276
277A filter statement to be applied to this query.
278
279The filter should be supplied as an SQL query string. For example:
280
281#### Parameters
282
283• **predicate**: `string`
284
285#### Returns
286
287`this`
288
289#### Example
290
291```ts
292x > 10
293y > 0 AND y < 100
294x > 5 OR y = 'test'
295
296Filtering performance can often be improved by creating a scalar index
297on the filter column(s).
298```