presubmit 0.1.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 (220) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +51 -0
  3. package/THIRD_PARTY_NOTICES.md +24 -0
  4. package/apps/web/dist/assets/FileCode-CZZH52o7.js +5 -0
  5. package/apps/web/dist/assets/FileCode-DovDO7Jh.css +1 -0
  6. package/apps/web/dist/assets/SettingsPage-CRvOwdjt.js +4 -0
  7. package/apps/web/dist/assets/SettingsPage-UbYSCwJj.css +1 -0
  8. package/apps/web/dist/assets/TerminalPanel-0sw-J6YS.css +1 -0
  9. package/apps/web/dist/assets/TerminalPanel-BqUjPWav.js +16 -0
  10. package/apps/web/dist/assets/index-BhqNNFja.js +54 -0
  11. package/apps/web/dist/assets/index-DD8VXy8H.css +1 -0
  12. package/apps/web/dist/assets/presubmit-mark-BBQ19Fmr.svg +7 -0
  13. package/apps/web/dist/assets/presubmit-mark-busy-CwBC-7on.svg +8 -0
  14. package/apps/web/dist/assets/react-vendor-wiHys0m2.js +9 -0
  15. package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
  16. package/apps/web/dist/index.html +6 -0
  17. package/apps/web/dist/service-worker.js +11 -0
  18. package/dist/apps/server/src/agent-builder.js +204 -0
  19. package/dist/apps/server/src/attach.js +163 -0
  20. package/dist/apps/server/src/attachments.js +86 -0
  21. package/dist/apps/server/src/browser-access.js +131 -0
  22. package/dist/apps/server/src/check-provenance.js +95 -0
  23. package/dist/apps/server/src/check-supervisor.js +112 -0
  24. package/dist/apps/server/src/checks.js +402 -0
  25. package/dist/apps/server/src/child-collaboration-guidance.js +2 -0
  26. package/dist/apps/server/src/child-sessions.js +191 -0
  27. package/dist/apps/server/src/cli.js +162 -0
  28. package/dist/apps/server/src/conversation-search.js +12 -0
  29. package/dist/apps/server/src/coordinator-messages.js +72 -0
  30. package/dist/apps/server/src/dev-auth.js +54 -0
  31. package/dist/apps/server/src/dev-server.js +201 -0
  32. package/dist/apps/server/src/dev-worker.js +48 -0
  33. package/dist/apps/server/src/diagnostics.js +105 -0
  34. package/dist/apps/server/src/fast-mode.js +8 -0
  35. package/dist/apps/server/src/folder-picker.js +54 -0
  36. package/dist/apps/server/src/git-blobs.js +62 -0
  37. package/dist/apps/server/src/git-handoff.js +127 -0
  38. package/dist/apps/server/src/history-sources.js +59 -0
  39. package/dist/apps/server/src/hub.js +159 -0
  40. package/dist/apps/server/src/internal-transport.js +38 -0
  41. package/dist/apps/server/src/local-embeddings.js +70 -0
  42. package/dist/apps/server/src/ollama-setup.js +56 -0
  43. package/dist/apps/server/src/planning.js +30 -0
  44. package/dist/apps/server/src/project-agents.js +276 -0
  45. package/dist/apps/server/src/project-memory.js +94 -0
  46. package/dist/apps/server/src/projects.js +106 -0
  47. package/dist/apps/server/src/queued-launch.js +13 -0
  48. package/dist/apps/server/src/reply-search.js +172 -0
  49. package/dist/apps/server/src/review-context.js +60 -0
  50. package/dist/apps/server/src/review-refresh.js +14 -0
  51. package/dist/apps/server/src/reviewers.js +75 -0
  52. package/dist/apps/server/src/search-settings.js +22 -0
  53. package/dist/apps/server/src/semantic-history.js +186 -0
  54. package/dist/apps/server/src/server.js +4338 -0
  55. package/dist/apps/server/src/session-changes.js +181 -0
  56. package/dist/apps/server/src/session-router-settings.js +198 -0
  57. package/dist/apps/server/src/session-workspaces.js +135 -0
  58. package/dist/apps/server/src/sessions.js +579 -0
  59. package/dist/apps/server/src/shared-auth.js +70 -0
  60. package/dist/apps/server/src/shell-evaluator-settings.js +53 -0
  61. package/dist/apps/server/src/store.js +203 -0
  62. package/dist/apps/server/src/tailscale-process.js +115 -0
  63. package/dist/apps/server/src/tailscale-serve-worker.js +33 -0
  64. package/dist/apps/server/src/tailscale-serve.js +276 -0
  65. package/dist/apps/server/src/task-capacity.js +92 -0
  66. package/dist/apps/server/src/task-graph.js +190 -0
  67. package/dist/apps/server/src/task-logs.js +74 -0
  68. package/dist/apps/server/src/task-numbers.js +25 -0
  69. package/dist/apps/server/src/task-orchestrator.js +1088 -0
  70. package/dist/apps/server/src/terminal.js +182 -0
  71. package/dist/apps/server/src/terminals.js +80 -0
  72. package/dist/apps/server/src/tool-safety.js +2 -0
  73. package/dist/apps/server/src/workspace-lock.js +140 -0
  74. package/dist/apps/server/src/workspace-watcher.js +65 -0
  75. package/dist/apps/server/src/workspace.js +517 -0
  76. package/dist/packages/agent-pi/src/agent-builder-tool.js +32 -0
  77. package/dist/packages/agent-pi/src/agent-capabilities.js +44 -0
  78. package/dist/packages/agent-pi/src/ask-user.js +86 -0
  79. package/dist/packages/agent-pi/src/auth.js +510 -0
  80. package/dist/packages/agent-pi/src/check-tools.js +72 -0
  81. package/dist/packages/agent-pi/src/command-policy.js +246 -0
  82. package/dist/packages/agent-pi/src/coordinator-tools.js +122 -0
  83. package/dist/packages/agent-pi/src/fast-mode.js +67 -0
  84. package/dist/packages/agent-pi/src/file-tools.js +163 -0
  85. package/dist/packages/agent-pi/src/history-tool.js +40 -0
  86. package/dist/packages/agent-pi/src/history.js +34 -0
  87. package/dist/packages/agent-pi/src/index.js +177 -0
  88. package/dist/packages/agent-pi/src/ipc.js +314 -0
  89. package/dist/packages/agent-pi/src/jev-session-router.js +408 -0
  90. package/dist/packages/agent-pi/src/jev-tools.js +71 -0
  91. package/dist/packages/agent-pi/src/local-model.js +277 -0
  92. package/dist/packages/agent-pi/src/memory-tools.js +119 -0
  93. package/dist/packages/agent-pi/src/model.js +25 -0
  94. package/dist/packages/agent-pi/src/planning.js +206 -0
  95. package/dist/packages/agent-pi/src/resource-loader.js +23 -0
  96. package/dist/packages/agent-pi/src/review-tools.js +158 -0
  97. package/dist/packages/agent-pi/src/review-transition.js +73 -0
  98. package/dist/packages/agent-pi/src/review.js +40 -0
  99. package/dist/packages/agent-pi/src/routing.js +27 -0
  100. package/dist/packages/agent-pi/src/session-setup.js +118 -0
  101. package/dist/packages/agent-pi/src/shell-context.js +51 -0
  102. package/dist/packages/agent-pi/src/shell-policy.js +281 -0
  103. package/dist/packages/agent-pi/src/shell-safety.js +205 -0
  104. package/dist/packages/agent-pi/src/shell.js +121 -0
  105. package/dist/packages/agent-pi/src/snapshot-permissions.js +12 -0
  106. package/dist/packages/agent-pi/src/spike.js +41 -0
  107. package/dist/packages/agent-pi/src/task-tools.js +53 -0
  108. package/dist/packages/agent-pi/src/types.js +1 -0
  109. package/dist/packages/agent-pi/src/usage.js +30 -0
  110. package/dist/packages/agent-pi/src/worker.js +602 -0
  111. package/dist/packages/protocol/src/activity-summary.js +77 -0
  112. package/dist/packages/protocol/src/agents.js +301 -0
  113. package/dist/packages/protocol/src/browser-access.js +1 -0
  114. package/dist/packages/protocol/src/checks.js +40 -0
  115. package/dist/packages/protocol/src/child-sessions.js +28 -0
  116. package/dist/packages/protocol/src/command-policy.js +3 -0
  117. package/dist/packages/protocol/src/coordinator.js +135 -0
  118. package/dist/packages/protocol/src/delegation.js +40 -0
  119. package/dist/packages/protocol/src/git-diff.js +71 -0
  120. package/dist/packages/protocol/src/git-handoff.js +1 -0
  121. package/dist/packages/protocol/src/index.js +1 -0
  122. package/dist/packages/protocol/src/memory.js +46 -0
  123. package/dist/packages/protocol/src/metrics.js +70 -0
  124. package/dist/packages/protocol/src/planning.js +138 -0
  125. package/dist/packages/protocol/src/retrieval.js +36 -0
  126. package/dist/packages/protocol/src/reviewers.js +17 -0
  127. package/dist/packages/protocol/src/search.js +16 -0
  128. package/dist/packages/protocol/src/session-changes.js +29 -0
  129. package/dist/packages/protocol/src/session-router.js +123 -0
  130. package/dist/packages/protocol/src/shell-evaluator.js +43 -0
  131. package/dist/packages/protocol/src/task-graph.js +1 -0
  132. package/dist/packages/protocol/src/token-usage.js +17 -0
  133. package/dist/packages/protocol/src/user-questions.js +106 -0
  134. package/package.json +71 -0
  135. package/vendor/lancedb/NODEJS_THIRD_PARTY_LICENSES.md +668 -0
  136. package/vendor/lancedb/RUST_THIRD_PARTY_LICENSES.html +14607 -0
  137. package/vendor/lancedb/dist/arrow.d.ts +296 -0
  138. package/vendor/lancedb/dist/arrow.js +1145 -0
  139. package/vendor/lancedb/dist/arrow_type.d.ts +9 -0
  140. package/vendor/lancedb/dist/arrow_type.js +29 -0
  141. package/vendor/lancedb/dist/connection.d.ts +508 -0
  142. package/vendor/lancedb/dist/connection.js +298 -0
  143. package/vendor/lancedb/dist/embedding/embedding_function.d.ts +103 -0
  144. package/vendor/lancedb/dist/embedding/embedding_function.js +192 -0
  145. package/vendor/lancedb/dist/embedding/index.d.ts +37 -0
  146. package/vendor/lancedb/dist/embedding/index.js +108 -0
  147. package/vendor/lancedb/dist/embedding/openai.d.ts +16 -0
  148. package/vendor/lancedb/dist/embedding/openai.js +81 -0
  149. package/vendor/lancedb/dist/embedding/registry.d.ts +94 -0
  150. package/vendor/lancedb/dist/embedding/registry.js +221 -0
  151. package/vendor/lancedb/dist/embedding/transformers.d.ts +36 -0
  152. package/vendor/lancedb/dist/embedding/transformers.js +110 -0
  153. package/vendor/lancedb/dist/header.d.ts +162 -0
  154. package/vendor/lancedb/dist/header.js +217 -0
  155. package/vendor/lancedb/dist/index.d.ts +246 -0
  156. package/vendor/lancedb/dist/index.js +176 -0
  157. package/vendor/lancedb/dist/indices.d.ts +721 -0
  158. package/vendor/lancedb/dist/indices.js +166 -0
  159. package/vendor/lancedb/dist/materialized_view.d.ts +69 -0
  160. package/vendor/lancedb/dist/materialized_view.js +112 -0
  161. package/vendor/lancedb/dist/merge.d.ts +104 -0
  162. package/vendor/lancedb/dist/merge.js +120 -0
  163. package/vendor/lancedb/dist/native.d.ts +1193 -0
  164. package/vendor/lancedb/dist/native.js +688 -0
  165. package/vendor/lancedb/dist/oauth.d.ts +66 -0
  166. package/vendor/lancedb/dist/oauth.js +15 -0
  167. package/vendor/lancedb/dist/otel.d.ts +26 -0
  168. package/vendor/lancedb/dist/otel.js +114 -0
  169. package/vendor/lancedb/dist/permutation.d.ts +143 -0
  170. package/vendor/lancedb/dist/permutation.js +184 -0
  171. package/vendor/lancedb/dist/query.d.ts +663 -0
  172. package/vendor/lancedb/dist/query.js +966 -0
  173. package/vendor/lancedb/dist/rerankers/index.d.ts +5 -0
  174. package/vendor/lancedb/dist/rerankers/index.js +19 -0
  175. package/vendor/lancedb/dist/rerankers/rrf.d.ts +14 -0
  176. package/vendor/lancedb/dist/rerankers/rrf.js +28 -0
  177. package/vendor/lancedb/dist/sanitize.d.ts +32 -0
  178. package/vendor/lancedb/dist/sanitize.js +544 -0
  179. package/vendor/lancedb/dist/scannable.d.ts +92 -0
  180. package/vendor/lancedb/dist/scannable.js +200 -0
  181. package/vendor/lancedb/dist/schema.d.ts +16 -0
  182. package/vendor/lancedb/dist/schema.js +387 -0
  183. package/vendor/lancedb/dist/table.d.ts +1069 -0
  184. package/vendor/lancedb/dist/table.js +498 -0
  185. package/vendor/lancedb/dist/util.d.ts +14 -0
  186. package/vendor/lancedb/dist/util.js +77 -0
  187. package/vendor/lancedb/license_header.txt +2 -0
  188. package/vendor/lancedb/package.json +56 -0
  189. package/vendor/transformers/LICENSE +202 -0
  190. package/vendor/transformers/dist/transformers.cjs +30844 -0
  191. package/vendor/transformers/dist/transformers.mjs +31404 -0
  192. package/vendor/transformers/package.json +55 -0
  193. package/vendor/transformers/types/backends/onnx.d.ts +30 -0
  194. package/vendor/transformers/types/configs.d.ts +85 -0
  195. package/vendor/transformers/types/env.d.ts +110 -0
  196. package/vendor/transformers/types/generation/configuration_utils.d.ts +320 -0
  197. package/vendor/transformers/types/generation/logits_process.d.ts +354 -0
  198. package/vendor/transformers/types/generation/logits_sampler.d.ts +51 -0
  199. package/vendor/transformers/types/generation/parameters.d.ts +47 -0
  200. package/vendor/transformers/types/generation/stopping_criteria.d.ts +81 -0
  201. package/vendor/transformers/types/generation/streamers.d.ts +81 -0
  202. package/vendor/transformers/types/models/whisper/common_whisper.d.ts +8 -0
  203. package/vendor/transformers/types/models/whisper/generation_whisper.d.ts +76 -0
  204. package/vendor/transformers/types/models.d.ts +3684 -0
  205. package/vendor/transformers/types/ops/registry.d.ts +11 -0
  206. package/vendor/transformers/types/pipelines.d.ts +2402 -0
  207. package/vendor/transformers/types/processors.d.ts +924 -0
  208. package/vendor/transformers/types/tokenizers.d.ts +990 -0
  209. package/vendor/transformers/types/transformers.d.ts +13 -0
  210. package/vendor/transformers/types/utils/audio.d.ts +130 -0
  211. package/vendor/transformers/types/utils/constants.d.ts +2 -0
  212. package/vendor/transformers/types/utils/core.d.ts +98 -0
  213. package/vendor/transformers/types/utils/data-structures.d.ts +236 -0
  214. package/vendor/transformers/types/utils/devices.d.ts +18 -0
  215. package/vendor/transformers/types/utils/dtypes.d.ts +19 -0
  216. package/vendor/transformers/types/utils/generic.d.ts +11 -0
  217. package/vendor/transformers/types/utils/hub.d.ts +152 -0
  218. package/vendor/transformers/types/utils/image.d.ts +119 -0
  219. package/vendor/transformers/types/utils/maths.d.ts +280 -0
  220. package/vendor/transformers/types/utils/tensor.d.ts +418 -0
@@ -0,0 +1,966 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.Query = exports.AutoQuery = exports.TakeQuery = exports.VectorQuery = exports.StandardQueryBase = exports.QueryBase = void 0;
6
+ exports.RecordBatchIterator = RecordBatchIterator;
7
+ exports.createAutoQuery = createAutoQuery;
8
+ exports.instanceOfFullTextQuery = instanceOfFullTextQuery;
9
+ const arrow_1 = require("./arrow");
10
+ const native_1 = require("./native");
11
+ async function* RecordBatchIterator(promisedInner) {
12
+ const inner = await promisedInner;
13
+ if (inner === undefined) {
14
+ throw new Error("Invalid iterator state");
15
+ }
16
+ for (let buffer = await inner.next(); buffer; buffer = await inner.next()) {
17
+ const { batches } = (0, arrow_1.tableFromIPC)(buffer);
18
+ if (batches.length !== 1) {
19
+ throw new Error("Expected only one batch");
20
+ }
21
+ yield batches[0];
22
+ }
23
+ }
24
+ class RecordBatchIterable {
25
+ inner;
26
+ options;
27
+ constructor(inner, options) {
28
+ this.inner = inner;
29
+ this.options = options;
30
+ }
31
+ // biome-ignore lint/suspicious/noExplicitAny: skip
32
+ [Symbol.asyncIterator]() {
33
+ return RecordBatchIterator(this.inner.execute(this.options?.maxBatchLength, this.options?.timeoutMs));
34
+ }
35
+ }
36
+ function nearestToNative(inner, vector) {
37
+ const raw = Array.isArray(vector) ? null : (0, arrow_1.extractVectorBuffer)(vector);
38
+ if (raw) {
39
+ return inner.nearestToRaw(raw.data, raw.dtype);
40
+ }
41
+ return inner.nearestTo(Float32Array.from(vector));
42
+ }
43
+ function addQueryVectorToNative(inner, vector) {
44
+ const raw = Array.isArray(vector) ? null : (0, arrow_1.extractVectorBuffer)(vector);
45
+ if (raw) {
46
+ inner.addQueryVectorRaw(raw.data, raw.dtype);
47
+ }
48
+ else {
49
+ inner.addQueryVector(Float32Array.from(vector));
50
+ }
51
+ }
52
+ /** Common methods supported by all query types
53
+ *
54
+ * @see {@link Query}
55
+ * @see {@link VectorQuery}
56
+ *
57
+ * @hideconstructor
58
+ */
59
+ class QueryBase {
60
+ inner;
61
+ /**
62
+ * @hidden
63
+ */
64
+ constructor(inner) {
65
+ if (inner !== undefined) {
66
+ this.inner = inner;
67
+ }
68
+ }
69
+ // call a function on the inner (either a promise or the actual object)
70
+ /**
71
+ * @hidden
72
+ */
73
+ doCall(fn) {
74
+ if (this.inner instanceof Promise) {
75
+ this.inner = this.inner.then((inner) => {
76
+ fn(inner);
77
+ return inner;
78
+ });
79
+ }
80
+ else {
81
+ fn(this.inner);
82
+ }
83
+ }
84
+ /**
85
+ * Return the native query used by the next terminal operation.
86
+ *
87
+ * @hidden
88
+ */
89
+ async getInner() {
90
+ return this.inner;
91
+ }
92
+ /**
93
+ * Return only the specified columns.
94
+ *
95
+ * By default a query will return all columns from the table. However, this can have
96
+ * a very significant impact on latency. LanceDb stores data in a columnar fashion. This
97
+ * means we can finely tune our I/O to select exactly the columns we need.
98
+ *
99
+ * As a best practice you should always limit queries to the columns that you need. If you
100
+ * pass in an array of column names then only those columns will be returned.
101
+ *
102
+ * You can also use this method to create new "dynamic" columns based on your existing columns.
103
+ * For example, you may not care about "a" or "b" but instead simply want "a + b". This is often
104
+ * seen in the SELECT clause of an SQL query (e.g. `SELECT a+b FROM my_table`).
105
+ *
106
+ * To create dynamic columns you can pass in a Map<string, string>. A column will be returned
107
+ * for each entry in the map. The key provides the name of the column. The value is
108
+ * an SQL string used to specify how the column is calculated.
109
+ *
110
+ * For example, an SQL query might state `SELECT a + b AS combined, c`. The equivalent
111
+ * input to this method would be:
112
+ * @example
113
+ * new Map([["combined", "a + b"], ["c", "c"]])
114
+ *
115
+ * Columns will always be returned in the order given, even if that order is different than
116
+ * the order used when adding the data.
117
+ *
118
+ * Note that you can pass in a `Record<string, string>` (e.g. an object literal). This method
119
+ * uses `Object.entries` which should preserve the insertion order of the object. However,
120
+ * object insertion order is easy to get wrong and `Map` is more foolproof.
121
+ */
122
+ select(columns) {
123
+ const selectColumns = (columnArray) => {
124
+ this.doCall((inner) => {
125
+ inner.selectColumns(columnArray);
126
+ });
127
+ };
128
+ const selectMapping = (columnTuples) => {
129
+ this.doCall((inner) => {
130
+ inner.select(columnTuples);
131
+ });
132
+ };
133
+ if (typeof columns === "string") {
134
+ selectColumns([columns]);
135
+ }
136
+ else if (Array.isArray(columns)) {
137
+ selectColumns(columns);
138
+ }
139
+ else if (columns instanceof Map) {
140
+ selectMapping(Array.from(columns.entries()));
141
+ }
142
+ else {
143
+ selectMapping(Object.entries(columns));
144
+ }
145
+ return this;
146
+ }
147
+ /**
148
+ * Whether to return the row id in the results.
149
+ *
150
+ * This column can be used to match results between different queries. For
151
+ * example, to match results from a full text search and a vector search in
152
+ * order to perform hybrid search.
153
+ */
154
+ withRowId() {
155
+ this.doCall((inner) => inner.withRowId());
156
+ return this;
157
+ }
158
+ /**
159
+ * @hidden
160
+ */
161
+ async nativeExecute(options) {
162
+ const inner = await this.getInner();
163
+ return inner.execute(options?.maxBatchLength, options?.timeoutMs);
164
+ }
165
+ /**
166
+ * Execute the query and return the results as an @see {@link AsyncIterator}
167
+ * of @see {@link RecordBatch}.
168
+ *
169
+ * By default, LanceDb will use many threads to calculate results and, when
170
+ * the result set is large, multiple batches will be processed at one time.
171
+ * This readahead is limited however and backpressure will be applied if this
172
+ * stream is consumed slowly (this constrains the maximum memory used by a
173
+ * single query)
174
+ *
175
+ */
176
+ execute(options) {
177
+ return RecordBatchIterator(this.nativeExecute(options));
178
+ }
179
+ /**
180
+ * @hidden
181
+ */
182
+ // biome-ignore lint/suspicious/noExplicitAny: skip
183
+ [Symbol.asyncIterator]() {
184
+ return RecordBatchIterator(this.nativeExecute());
185
+ }
186
+ /** Collect the results as an Arrow @see {@link ArrowTable}. */
187
+ async toArrow(options) {
188
+ const batches = [];
189
+ const inner = await this.getInner();
190
+ for await (const batch of new RecordBatchIterable(inner, options)) {
191
+ batches.push(batch);
192
+ }
193
+ return new arrow_1.Table(batches);
194
+ }
195
+ /** Collect the results as an array of objects. */
196
+ // biome-ignore lint/suspicious/noExplicitAny: arrow.toArrow() returns any[]
197
+ async toArray(options) {
198
+ const tbl = await this.toArrow(options);
199
+ return tbl.toArray();
200
+ }
201
+ /**
202
+ * Generates an explanation of the query execution plan.
203
+ *
204
+ * @example
205
+ * import * as lancedb from "@lancedb/lancedb"
206
+ * const db = await lancedb.connect("./.lancedb");
207
+ * const table = await db.createTable("my_table", [
208
+ * { vector: [1.1, 0.9], id: "1" },
209
+ * ]);
210
+ * const plan = await table.query().nearestTo([0.5, 0.2]).explainPlan();
211
+ *
212
+ * @param verbose - If true, provides a more detailed explanation. Defaults to false.
213
+ * @returns A Promise that resolves to a string containing the query execution plan explanation.
214
+ */
215
+ async explainPlan(verbose = false) {
216
+ const inner = await this.getInner();
217
+ return inner.explainPlan(verbose);
218
+ }
219
+ /**
220
+ * Executes the query and returns the physical query plan annotated with runtime metrics.
221
+ *
222
+ * This is useful for debugging and performance analysis, as it shows how the query was executed
223
+ * and includes metrics such as elapsed time, rows processed, and I/O statistics.
224
+ *
225
+ * @example
226
+ * import * as lancedb from "@lancedb/lancedb"
227
+ *
228
+ * const db = await lancedb.connect("./.lancedb");
229
+ * const table = await db.createTable("my_table", [
230
+ * { vector: [1.1, 0.9], id: "1" },
231
+ * ]);
232
+ *
233
+ * const plan = await table.query().nearestTo([0.5, 0.2]).analyzePlan();
234
+ *
235
+ * Example output (with runtime metrics inlined):
236
+ * AnalyzeExec verbose=true, metrics=[]
237
+ * ProjectionExec: expr=[id@3 as id, vector@0 as vector, _distance@2 as _distance], metrics=[output_rows=1, elapsed_compute=3.292µs]
238
+ * Take: columns="vector, _rowid, _distance, (id)", metrics=[output_rows=1, elapsed_compute=66.001µs, batches_processed=1, bytes_read=8, iops=1, requests=1]
239
+ * CoalesceBatchesExec: target_batch_size=1024, metrics=[output_rows=1, elapsed_compute=3.333µs]
240
+ * GlobalLimitExec: skip=0, fetch=10, metrics=[output_rows=1, elapsed_compute=167ns]
241
+ * FilterExec: _distance@2 IS NOT NULL, metrics=[output_rows=1, elapsed_compute=8.542µs]
242
+ * SortExec: TopK(fetch=10), expr=[_distance@2 ASC NULLS LAST], metrics=[output_rows=1, elapsed_compute=63.25µs, row_replacements=1]
243
+ * KNNVectorDistance: metric=l2, metrics=[output_rows=1, elapsed_compute=114.333µs, output_batches=1]
244
+ * LanceScan: uri=/path/to/data, projection=[vector], row_id=true, row_addr=false, ordered=false, metrics=[output_rows=1, elapsed_compute=103.626µs, bytes_read=549, iops=2, requests=2]
245
+ *
246
+ * @param distributedMetrics - How distributed worker metrics are displayed for remote query plans.
247
+ * Defaults to `"aggregate"`.
248
+ * @returns A query execution plan with runtime metrics for each step.
249
+ */
250
+ async analyzePlan(distributedMetrics) {
251
+ const distributedMetricsMode = distributedMetrics ?? "aggregate";
252
+ const inner = await this.getInner();
253
+ return inner.analyzePlan(distributedMetricsMode);
254
+ }
255
+ /**
256
+ * Returns the schema of the output that will be returned by this query.
257
+ *
258
+ * This can be used to inspect the types and names of the columns that will be
259
+ * returned by the query before executing it.
260
+ *
261
+ * @returns An Arrow Schema describing the output columns.
262
+ */
263
+ async outputSchema() {
264
+ const inner = await this.getInner();
265
+ const schemaBuffer = await inner.outputSchema();
266
+ const schema = (0, arrow_1.tableFromIPC)(schemaBuffer).schema;
267
+ return schema;
268
+ }
269
+ }
270
+ exports.QueryBase = QueryBase;
271
+ class StandardQueryBase extends QueryBase {
272
+ constructor(inner) {
273
+ super(inner);
274
+ }
275
+ /**
276
+ * A filter statement to be applied to this query.
277
+ *
278
+ * The filter should be supplied as an SQL query string. For example:
279
+ * @example
280
+ * x > 10
281
+ * y > 0 AND y < 100
282
+ * x > 5 OR y = 'test'
283
+ *
284
+ * Filtering performance can often be improved by creating a scalar index
285
+ * on the filter column(s).
286
+ *
287
+ * Calling this multiple times combines the filters with a logical AND rather
288
+ * than replacing the previous filter.
289
+ */
290
+ where(predicate) {
291
+ this.doCall((inner) => inner.onlyIf(predicate));
292
+ return this;
293
+ }
294
+ /**
295
+ * A filter statement to be applied to this query.
296
+ * @see where
297
+ * @deprecated Use `where` instead
298
+ */
299
+ filter(predicate) {
300
+ return this.where(predicate);
301
+ }
302
+ fullTextSearch(query, options) {
303
+ let columns = null;
304
+ if (options) {
305
+ if (typeof options.columns === "string") {
306
+ columns = [options.columns];
307
+ }
308
+ else if (Array.isArray(options.columns)) {
309
+ columns = options.columns;
310
+ }
311
+ }
312
+ this.doCall((inner) => {
313
+ if (typeof query === "string") {
314
+ inner.fullTextSearch({
315
+ query: query,
316
+ columns: columns,
317
+ });
318
+ }
319
+ else {
320
+ inner.fullTextSearch({ query: query.inner });
321
+ }
322
+ });
323
+ return this;
324
+ }
325
+ /**
326
+ * Set the maximum number of results to return.
327
+ *
328
+ * By default, a plain search has no limit. If this method is not
329
+ * called then every valid row from the table will be returned.
330
+ */
331
+ limit(limit) {
332
+ this.doCall((inner) => inner.limit(limit));
333
+ return this;
334
+ }
335
+ /**
336
+ * Set the number of rows to skip before returning results.
337
+ *
338
+ * This is useful for pagination.
339
+ */
340
+ offset(offset) {
341
+ this.doCall((inner) => inner.offset(offset));
342
+ return this;
343
+ }
344
+ /**
345
+ * Sort the results by the specified column(s).
346
+ * @returns This query builder.
347
+ */
348
+ orderBy(ordering) {
349
+ const orderings = Array.isArray(ordering) ? ordering : [ordering];
350
+ const normalized = orderings.map((o) => ({
351
+ columnName: o.columnName,
352
+ ascending: o.ascending ?? true,
353
+ nullsFirst: o.nullsFirst ?? false,
354
+ }));
355
+ this.doCall((inner) => inner.orderBy(normalized));
356
+ return this;
357
+ }
358
+ /**
359
+ * Skip searching un-indexed data. This can make search faster, but will miss
360
+ * any data that is not yet indexed.
361
+ *
362
+ * Use {@link Table#optimize} to index all un-indexed data.
363
+ */
364
+ fastSearch() {
365
+ this.doCall((inner) => inner.fastSearch());
366
+ return this;
367
+ }
368
+ /**
369
+ * Control MemWAL read routing for this query.
370
+ *
371
+ * By default (unset), when the table carries a MemWAL write spec (see
372
+ * {@link Table#setLsmWriteSpec}), reads are routed through the LSM scanner so
373
+ * they also return data written via the `mergeInsert` LSM path that has not yet
374
+ * been compacted into the base table (the active/frozen in-memory memtables and
375
+ * the flushed generations), deduplicated by primary key; a table without a spec
376
+ * reads the base table.
377
+ *
378
+ * @param enable - `true` forces the LSM scanner and errors if the table has no
379
+ * MemWAL write spec. `false` bypasses the MemWAL and reads the base table only,
380
+ * even when a spec is present.
381
+ *
382
+ * Note: the LSM scanner does not support every query shape (e.g. reranking,
383
+ * hybrid search, `orderBy`). On a MemWAL table those shapes error unless
384
+ * `useLsm(false)` is set, because a base-only read would silently exclude
385
+ * un-compacted MemWAL data.
386
+ */
387
+ useLsm(enable) {
388
+ this.doCall((inner) => inner.useLsm(enable));
389
+ return this;
390
+ }
391
+ }
392
+ exports.StandardQueryBase = StandardQueryBase;
393
+ /**
394
+ * A builder used to construct a vector search
395
+ *
396
+ * This builder can be reused to execute the query many times.
397
+ *
398
+ * @see {@link Query#nearestTo}
399
+ *
400
+ * @hideconstructor
401
+ */
402
+ class VectorQuery extends StandardQueryBase {
403
+ /**
404
+ * @hidden
405
+ */
406
+ constructor(inner) {
407
+ super(inner);
408
+ }
409
+ /**
410
+ * @hidden
411
+ */
412
+ doVectorCall(fn) {
413
+ super.doCall(fn);
414
+ }
415
+ /**
416
+ * Set the number of partitions to search (probe)
417
+ *
418
+ * This argument is only used when the vector column has an IVF PQ index.
419
+ * If there is no index then this value is ignored.
420
+ *
421
+ * The IVF stage of IVF PQ divides the input into partitions (clusters) of
422
+ * related values.
423
+ *
424
+ * The partition whose centroids are closest to the query vector will be
425
+ * exhaustiely searched to find matches. This parameter controls how many
426
+ * partitions should be searched.
427
+ *
428
+ * Increasing this value will increase the recall of your query but will
429
+ * also increase the latency of your query. The default value is 20. This
430
+ * default is good for many cases but the best value to use will depend on
431
+ * your data and the recall that you need to achieve.
432
+ *
433
+ * For best results we recommend tuning this parameter with a benchmark against
434
+ * your actual data to find the smallest possible value that will still give
435
+ * you the desired recall.
436
+ *
437
+ * For more fine grained control over behavior when you have a very narrow filter
438
+ * you can use `minimumNprobes` and `maximumNprobes`. This method sets both
439
+ * the minimum and maximum to the same value.
440
+ */
441
+ nprobes(nprobes) {
442
+ this.doVectorCall((inner) => inner.nprobes(nprobes));
443
+ return this;
444
+ }
445
+ /**
446
+ * Set the minimum number of probes used.
447
+ *
448
+ * This controls the minimum number of partitions that will be searched. This
449
+ * parameter will impact every query against a vector index, regardless of the
450
+ * filter. See `nprobes` for more details. Higher values will increase recall
451
+ * but will also increase latency.
452
+ */
453
+ minimumNprobes(minimumNprobes) {
454
+ this.doVectorCall((inner) => inner.minimumNprobes(minimumNprobes));
455
+ return this;
456
+ }
457
+ /**
458
+ * Set the maximum number of probes used.
459
+ *
460
+ * This controls the maximum number of partitions that will be searched. If this
461
+ * number is greater than minimumNprobes then the excess partitions will _only_ be
462
+ * searched if we have not found enough results. This can be useful when there is
463
+ * a narrow filter to allow these queries to spend more time searching and avoid
464
+ * potential false negatives.
465
+ */
466
+ maximumNprobes(maximumNprobes) {
467
+ this.doVectorCall((inner) => inner.maximumNprobes(maximumNprobes));
468
+ return this;
469
+ }
470
+ /*
471
+ * Set the distance range to use
472
+ *
473
+ * Only rows with distances within range [lower_bound, upper_bound)
474
+ * will be returned.
475
+ *
476
+ * `undefined` means no lower or upper bound.
477
+ */
478
+ distanceRange(lowerBound, upperBound) {
479
+ this.doVectorCall((inner) => inner.distanceRange(lowerBound, upperBound));
480
+ return this;
481
+ }
482
+ /**
483
+ * Set the number of candidates to consider during the search
484
+ *
485
+ * This argument is only used when the vector column has an HNSW index.
486
+ * If there is no index then this value is ignored.
487
+ *
488
+ * Increasing this value will increase the recall of your query but will
489
+ * also increase the latency of your query. The default value is 1.5*limit.
490
+ */
491
+ ef(ef) {
492
+ this.doVectorCall((inner) => inner.ef(ef));
493
+ return this;
494
+ }
495
+ /**
496
+ * Set the vector column to query
497
+ *
498
+ * This controls which column is compared to the query vector supplied in
499
+ * the call to @see {@link Query#nearestTo}
500
+ *
501
+ * This parameter must be specified if the table has more than one column
502
+ * whose data type is a fixed-size-list of floats.
503
+ */
504
+ column(column) {
505
+ this.doVectorCall((inner) => inner.column(column));
506
+ return this;
507
+ }
508
+ /**
509
+ * Set the distance metric to use
510
+ *
511
+ * When performing a vector search we try and find the "nearest" vectors according
512
+ * to some kind of distance metric. This parameter controls which distance metric to
513
+ * use. See @see {@link IvfPqOptions.distanceType} for more details on the different
514
+ * distance metrics available.
515
+ *
516
+ * Note: if there is a vector index then the distance type used MUST match the distance
517
+ * type used to train the vector index. If this is not done then the results will be
518
+ * invalid.
519
+ *
520
+ * By default "l2" is used.
521
+ */
522
+ distanceType(distanceType) {
523
+ this.doVectorCall((inner) => inner.distanceType(distanceType));
524
+ return this;
525
+ }
526
+ /**
527
+ * A multiplier to control how many additional rows are taken during the refine step
528
+ *
529
+ * This argument is only used when the vector column has an IVF PQ index.
530
+ * If there is no index then this value is ignored.
531
+ *
532
+ * An IVF PQ index stores compressed (quantized) values. They query vector is compared
533
+ * against these values and, since they are compressed, the comparison is inaccurate.
534
+ *
535
+ * This parameter can be used to refine the results. It can improve both improve recall
536
+ * and correct the ordering of the nearest results.
537
+ *
538
+ * To refine results LanceDb will first perform an ANN search to find the nearest
539
+ * `limit` * `refine_factor` results. In other words, if `refine_factor` is 3 and
540
+ * `limit` is the default (10) then the first 30 results will be selected. LanceDb
541
+ * then fetches the full, uncompressed, values for these 30 results. The results are
542
+ * then reordered by the true distance and only the nearest 10 are kept.
543
+ *
544
+ * Note: there is a difference between calling this method with a value of 1 and never
545
+ * calling this method at all. Calling this method with any value will have an impact
546
+ * on your search latency. When you call this method with a `refine_factor` of 1 then
547
+ * LanceDb still needs to fetch the full, uncompressed, values so that it can potentially
548
+ * reorder the results.
549
+ *
550
+ * Note: if this method is NOT called then the distances returned in the _distance column
551
+ * will be approximate distances based on the comparison of the quantized query vector
552
+ * and the quantized result vectors. This can be considerably different than the true
553
+ * distance between the query vector and the actual uncompressed vector.
554
+ */
555
+ refineFactor(refineFactor) {
556
+ this.doVectorCall((inner) => inner.refineFactor(refineFactor));
557
+ return this;
558
+ }
559
+ /**
560
+ * If this is called then filtering will happen after the vector search instead of
561
+ * before.
562
+ *
563
+ * By default filtering will be performed before the vector search. This is how
564
+ * filtering is typically understood to work. This prefilter step does add some
565
+ * additional latency. Creating a scalar index on the filter column(s) can
566
+ * often improve this latency. However, sometimes a filter is too complex or scalar
567
+ * indices cannot be applied to the column. In these cases postfiltering can be
568
+ * used instead of prefiltering to improve latency.
569
+ *
570
+ * Post filtering applies the filter to the results of the vector search. This means
571
+ * we only run the filter on a much smaller set of data. However, it can cause the
572
+ * query to return fewer than `limit` results (or even no results) if none of the nearest
573
+ * results match the filter.
574
+ *
575
+ * Post filtering happens during the "refine stage" (described in more detail in
576
+ * @see {@link VectorQuery#refineFactor}). This means that setting a higher refine
577
+ * factor can often help restore some of the results lost by post filtering.
578
+ */
579
+ postfilter() {
580
+ this.doVectorCall((inner) => inner.postfilter());
581
+ return this;
582
+ }
583
+ /**
584
+ * If this is called then any vector index is skipped
585
+ *
586
+ * An exhaustive (flat) search will be performed. The query vector will
587
+ * be compared to every vector in the table. At high scales this can be
588
+ * expensive. However, this is often still useful. For example, skipping
589
+ * the vector index can give you ground truth results which you can use to
590
+ * calculate your recall to select an appropriate value for nprobes.
591
+ */
592
+ bypassVectorIndex() {
593
+ this.doVectorCall((inner) => inner.bypassVectorIndex());
594
+ return this;
595
+ }
596
+ /*
597
+ * Add a query vector to the search
598
+ *
599
+ * This method can be called multiple times to add multiple query vectors
600
+ * to the search. A column called `query_index` will be added to indicate the index
601
+ * of the query vector that produced the result. Flat searches share one table scan
602
+ * across the query vectors, avoiding the scan and memory amplification of running
603
+ * multiple queries concurrently. Indexed searches may still perform per-vector
604
+ * index work.
605
+ */
606
+ addQueryVector(vector) {
607
+ if (vector instanceof Promise) {
608
+ // Observe the promise as soon as it is accepted. The existing native
609
+ // query may still be pending, and delaying observation until it resolves
610
+ // can otherwise surface a fast rejection as unhandled.
611
+ const settledVector = vector.then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
612
+ const res = (async () => {
613
+ const inner = await this.getInner();
614
+ const outcome = await settledVector;
615
+ if (outcome.status === "rejected") {
616
+ throw outcome.reason;
617
+ }
618
+ addQueryVectorToNative(inner, outcome.value);
619
+ return inner;
620
+ })();
621
+ return new VectorQuery(res);
622
+ }
623
+ else {
624
+ this.doVectorCall((inner) => addQueryVectorToNative(inner, vector));
625
+ return this;
626
+ }
627
+ }
628
+ rerank(reranker) {
629
+ this.doVectorCall((inner) => inner.rerank(async (args) => {
630
+ const vecResults = await (0, arrow_1.fromBufferToRecordBatch)(args.vecResults);
631
+ const ftsResults = await (0, arrow_1.fromBufferToRecordBatch)(args.ftsResults);
632
+ const result = await reranker.rerankHybrid(args.query, vecResults, ftsResults);
633
+ const buffer = (0, arrow_1.fromRecordBatchToBuffer)(result);
634
+ return buffer;
635
+ }));
636
+ return this;
637
+ }
638
+ }
639
+ exports.VectorQuery = VectorQuery;
640
+ /**
641
+ * Create a string query whose vector/FTS routing is resolved against the active
642
+ * table schema when the query executes.
643
+ *
644
+ * @hidden
645
+ */
646
+ function createAutoQuery(table, query, columns, getVector) {
647
+ let cachedPreparation;
648
+ const snapshotRoute = async () => {
649
+ const snapshot = await table.querySnapshot();
650
+ const schema = (0, arrow_1.tableFromIPC)(await snapshot.schema()).schema;
651
+ return {
652
+ table: snapshot,
653
+ embeddingMetadata: schema.metadata.get("embedding_functions"),
654
+ };
655
+ };
656
+ const createInner = async () => {
657
+ const route = await snapshotRoute();
658
+ if (route.embeddingMetadata === undefined) {
659
+ const inner = route.table.query();
660
+ inner.fullTextSearch({ query, columns });
661
+ return inner;
662
+ }
663
+ const metadata = route.embeddingMetadata;
664
+ if (cachedPreparation?.metadata !== metadata) {
665
+ cachedPreparation = {
666
+ metadata,
667
+ vector: Promise.resolve().then(() => getVector(metadata)),
668
+ };
669
+ }
670
+ const preparation = cachedPreparation;
671
+ let vector;
672
+ try {
673
+ vector = await preparation.vector;
674
+ }
675
+ catch (error) {
676
+ if (cachedPreparation === preparation) {
677
+ cachedPreparation = undefined;
678
+ }
679
+ throw error;
680
+ }
681
+ return nearestToNative(route.table.query(), vector);
682
+ };
683
+ return new AutoQuery(createInner);
684
+ }
685
+ /**
686
+ * A query that returns a subset of the rows in the table.
687
+ *
688
+ * @hideconstructor
689
+ */
690
+ class TakeQuery extends QueryBase {
691
+ constructor(inner) {
692
+ super(inner);
693
+ }
694
+ /**
695
+ * Control MemWAL read routing for this take query.
696
+ *
697
+ * `false` bypasses the MemWAL and reads the base table only — the escape hatch,
698
+ * since take-by-row-id/offset is not supported on the LSM scanner and, on a
699
+ * MemWAL table, auto-routes to it and errors otherwise.
700
+ *
701
+ * @param enable - `false` reads the base table only.
702
+ */
703
+ useLsm(enable) {
704
+ this.doCall((inner) => inner.useLsm(enable));
705
+ return this;
706
+ }
707
+ }
708
+ exports.TakeQuery = TakeQuery;
709
+ /**
710
+ * A builder for automatic string searches.
711
+ *
712
+ * Automatic search determines whether to use full-text or vector search from
713
+ * the table revision selected for each execution. This builder exposes the
714
+ * common operations supported by both query families.
715
+ *
716
+ * @hideconstructor
717
+ */
718
+ class AutoQuery extends StandardQueryBase {
719
+ createInner;
720
+ calls = [];
721
+ /** @hidden */
722
+ constructor(createInner) {
723
+ super();
724
+ this.createInner = createInner;
725
+ }
726
+ /** @hidden */
727
+ doCall(fn) {
728
+ this.calls.push(fn);
729
+ }
730
+ /** @hidden */
731
+ async getInner() {
732
+ const calls = [...this.calls];
733
+ const inner = await this.createInner();
734
+ for (const call of calls) {
735
+ call(inner);
736
+ }
737
+ return inner;
738
+ }
739
+ }
740
+ exports.AutoQuery = AutoQuery;
741
+ /** A builder for LanceDB queries.
742
+ *
743
+ * @see {@link Table#query}, {@link Table#search}
744
+ *
745
+ * @hideconstructor
746
+ */
747
+ class Query extends StandardQueryBase {
748
+ /**
749
+ * @hidden
750
+ */
751
+ constructor(tbl) {
752
+ super(tbl.query());
753
+ }
754
+ /**
755
+ * Find the nearest vectors to the given query vector.
756
+ *
757
+ * This converts the query from a plain query to a vector query.
758
+ *
759
+ * This method will attempt to convert the input to the query vector
760
+ * expected by the embedding model. If the input cannot be converted
761
+ * then an error will be thrown.
762
+ *
763
+ * By default, there is no embedding model, and the input should be
764
+ * an array-like object of numbers (something that can be used as input
765
+ * to Float32Array.from)
766
+ *
767
+ * If there is only one vector column (a column whose data type is a
768
+ * fixed size list of floats) then the column does not need to be specified.
769
+ * If there is more than one vector column you must use
770
+ * @see {@link VectorQuery#column} to specify which column you would like
771
+ * to compare with.
772
+ *
773
+ * If no index has been created on the vector column then a vector query
774
+ * will perform a distance comparison between the query vector and every
775
+ * vector in the database and then sort the results. This is sometimes
776
+ * called a "flat search"
777
+ *
778
+ * For small databases, with a few hundred thousand vectors or less, this can
779
+ * be reasonably fast. In larger databases you should create a vector index
780
+ * on the column. If there is a vector index then an "approximate" nearest
781
+ * neighbor search (frequently called an ANN search) will be performed. This
782
+ * search is much faster, but the results will be approximate.
783
+ *
784
+ * The query can be further parameterized using the returned builder. There
785
+ * are various ANN search parameters that will let you fine tune your recall
786
+ * accuracy vs search latency.
787
+ *
788
+ * Vector searches always have a `limit`. If `limit` has not been called then
789
+ * a default `limit` of 10 will be used. @see {@link Query#limit}
790
+ */
791
+ nearestTo(vector) {
792
+ const inner = this.inner;
793
+ if (inner instanceof Promise) {
794
+ const nativeQuery = inner.then(async (resolvedInner) => nearestToNative(resolvedInner, await vector));
795
+ return new VectorQuery(nativeQuery);
796
+ }
797
+ if (vector instanceof Promise) {
798
+ return new VectorQuery(vector.then((resolvedVector) => nearestToNative(inner, resolvedVector)));
799
+ }
800
+ return new VectorQuery(nearestToNative(inner, vector));
801
+ }
802
+ nearestToText(query, columns) {
803
+ this.doCall((inner) => {
804
+ if (typeof query === "string") {
805
+ inner.fullTextSearch({
806
+ query: query,
807
+ columns: columns,
808
+ });
809
+ }
810
+ else {
811
+ inner.fullTextSearch({ query: query.inner });
812
+ }
813
+ });
814
+ return this;
815
+ }
816
+ }
817
+ exports.Query = Query;
818
+ /**
819
+ * Enum representing the types of full-text queries supported.
820
+ *
821
+ * - `Match`: Performs a full-text search for terms in the query string.
822
+ * - `MatchPhrase`: Searches for an exact phrase match in the text.
823
+ * - `Boost`: Boosts the relevance score of specific terms in the query.
824
+ * - `MultiMatch`: Searches across multiple fields for the query terms.
825
+ */
826
+ var FullTextQueryType;
827
+ (function (FullTextQueryType) {
828
+ FullTextQueryType["Match"] = "match";
829
+ FullTextQueryType["MatchPhrase"] = "match_phrase";
830
+ FullTextQueryType["Boost"] = "boost";
831
+ FullTextQueryType["MultiMatch"] = "multi_match";
832
+ FullTextQueryType["Boolean"] = "boolean";
833
+ })(FullTextQueryType || (exports.FullTextQueryType = FullTextQueryType = {}));
834
+ /**
835
+ * Enum representing the logical operators used in full-text queries.
836
+ *
837
+ * - `And`: All terms must match.
838
+ * - `Or`: At least one term must match.
839
+ */
840
+ var Operator;
841
+ (function (Operator) {
842
+ Operator["And"] = "AND";
843
+ Operator["Or"] = "OR";
844
+ })(Operator || (exports.Operator = Operator = {}));
845
+ /**
846
+ * Enum representing the occurrence of terms in full-text queries.
847
+ *
848
+ * - `Must`: The term must be present in the document.
849
+ * - `Should`: The term should contribute to the document score, but is not required.
850
+ * - `MustNot`: The term must not be present in the document.
851
+ */
852
+ var Occur;
853
+ (function (Occur) {
854
+ Occur["Should"] = "SHOULD";
855
+ Occur["Must"] = "MUST";
856
+ Occur["MustNot"] = "MUST_NOT";
857
+ })(Occur || (exports.Occur = Occur = {}));
858
+ // biome-ignore lint/suspicious/noExplicitAny: we want any here
859
+ function instanceOfFullTextQuery(obj) {
860
+ return obj != null && obj.inner instanceof native_1.JsFullTextQuery;
861
+ }
862
+ class MatchQuery {
863
+ /** @ignore */
864
+ inner;
865
+ /**
866
+ * Creates an instance of MatchQuery.
867
+ *
868
+ * @param query - The text query to search for.
869
+ * @param column - The name of the column to search within.
870
+ * @param options - Optional parameters for the match query.
871
+ * - `boost`: The boost factor for the query (default is 1.0).
872
+ * - `fuzziness`: The fuzziness level for the query (default is 0).
873
+ * - `maxExpansions`: The maximum number of terms to consider for fuzzy matching (default is 50).
874
+ * - `operator`: The logical operator to use for combining terms in the query (default is "OR").
875
+ * - `prefixLength`: The number of beginning characters being unchanged for fuzzy matching.
876
+ */
877
+ constructor(query, column, options) {
878
+ let fuzziness = options?.fuzziness;
879
+ if (fuzziness === undefined) {
880
+ fuzziness = 0;
881
+ }
882
+ this.inner = native_1.JsFullTextQuery.matchQuery(query, column, options?.boost ?? 1.0, fuzziness, options?.maxExpansions ?? 50, options?.operator ?? Operator.Or, options?.prefixLength ?? 0);
883
+ }
884
+ queryType() {
885
+ return FullTextQueryType.Match;
886
+ }
887
+ }
888
+ exports.MatchQuery = MatchQuery;
889
+ class PhraseQuery {
890
+ /** @ignore */
891
+ inner;
892
+ /**
893
+ * Creates an instance of `PhraseQuery`.
894
+ *
895
+ * @param query - The phrase to search for in the specified column.
896
+ * @param column - The name of the column to search within.
897
+ * @param options - Optional parameters for the phrase query.
898
+ * - `slop`: The maximum number of intervening unmatched positions allowed between words in the phrase (default is 0).
899
+ */
900
+ constructor(query, column, options) {
901
+ this.inner = native_1.JsFullTextQuery.phraseQuery(query, column, options?.slop ?? 0);
902
+ }
903
+ queryType() {
904
+ return FullTextQueryType.MatchPhrase;
905
+ }
906
+ }
907
+ exports.PhraseQuery = PhraseQuery;
908
+ class BoostQuery {
909
+ /** @ignore */
910
+ inner;
911
+ /**
912
+ * Creates an instance of BoostQuery.
913
+ * The boost returns documents that match the positive query,
914
+ * but penalizes those that match the negative query.
915
+ * the penalty is controlled by the `negativeBoost` parameter.
916
+ *
917
+ * @param positive - The positive query that boosts the relevance score.
918
+ * @param negative - The negative query that reduces the relevance score.
919
+ * @param options - Optional parameters for the boost query.
920
+ * - `negativeBoost`: The boost factor for the negative query (default is 0.0).
921
+ */
922
+ constructor(positive, negative, options) {
923
+ this.inner = native_1.JsFullTextQuery.boostQuery(positive.inner, negative.inner, options?.negativeBoost);
924
+ }
925
+ queryType() {
926
+ return FullTextQueryType.Boost;
927
+ }
928
+ }
929
+ exports.BoostQuery = BoostQuery;
930
+ class MultiMatchQuery {
931
+ /** @ignore */
932
+ inner;
933
+ /**
934
+ * Creates an instance of MultiMatchQuery.
935
+ *
936
+ * @param query - The text query to search for across multiple columns.
937
+ * @param columns - An array of column names to search within.
938
+ * @param options - Optional parameters for the multi-match query.
939
+ * - `boosts`: An array of boost factors for each column (default is 1.0 for all).
940
+ * - `operator`: The logical operator to use for combining terms in the query (default is "OR").
941
+ */
942
+ constructor(query, columns, options) {
943
+ this.inner = native_1.JsFullTextQuery.multiMatchQuery(query, columns, options?.boosts, options?.operator ?? Operator.Or);
944
+ }
945
+ queryType() {
946
+ return FullTextQueryType.MultiMatch;
947
+ }
948
+ }
949
+ exports.MultiMatchQuery = MultiMatchQuery;
950
+ class BooleanQuery {
951
+ /** @ignore */
952
+ inner;
953
+ /**
954
+ * Creates an instance of BooleanQuery.
955
+ *
956
+ * @param queries - An array of (Occur, FullTextQuery objects) to combine.
957
+ * Occur specifies whether the query must match, or should match.
958
+ */
959
+ constructor(queries) {
960
+ this.inner = native_1.JsFullTextQuery.booleanQuery(queries.map(([occur, query]) => [occur, query.inner]));
961
+ }
962
+ queryType() {
963
+ return FullTextQueryType.Boolean;
964
+ }
965
+ }
966
+ exports.BooleanQuery = BooleanQuery;