speedkey 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.
@@ -0,0 +1,409 @@
1
+ /**
2
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
+ */
4
+ import { DecoderOption, GlideRecord, GlideReturnType, GlideString, GlideClient, GlideClusterClient, Field, FtAggregateOptions, FtCreateOptions, FtSearchOptions } from "..";
5
+ /** Response type of {@link GlideFt.info | ft.info} command. */
6
+ export type FtInfoReturnType = Record<string, GlideString | number | GlideString[] | Record<string, GlideString | Record<string, GlideString | number>[]>>;
7
+ /**
8
+ * Response type for the {@link GlideFt.search | ft.search} command.
9
+ */
10
+ export type FtSearchReturnType = [
11
+ number,
12
+ GlideRecord<GlideRecord<GlideString>>
13
+ ];
14
+ /**
15
+ * Response type for the {@link GlideFt.aggregate | ft.aggregate} command.
16
+ */
17
+ export type FtAggregateReturnType = GlideRecord<GlideReturnType>[];
18
+ /** Module for Vector Search commands. */
19
+ export declare class GlideFt {
20
+ /**
21
+ * Creates an index and initiates a backfill of that index.
22
+ *
23
+ * @param client - The client to execute the command.
24
+ * @param indexName - The index name for the index to be created.
25
+ * @param schema - The fields of the index schema, specifying the fields and their types.
26
+ * @param options - (Optional) Options for the `FT.CREATE` command. See {@link FtCreateOptions}.
27
+ * @returns If the index is successfully created, returns "OK".
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Example usage of FT.CREATE to create a 6-dimensional JSON index using the HNSW algorithm
32
+ * await GlideFt.create(client, "json_idx1", [{
33
+ * type: "VECTOR",
34
+ * name: "$.vec",
35
+ * alias: "VEC",
36
+ * attributes: {
37
+ * algorithm: "HNSW",
38
+ * type: "FLOAT32",
39
+ * dimension: 6,
40
+ * distanceMetric: "L2",
41
+ * numberOfEdges: 32,
42
+ * },
43
+ * }], {
44
+ * dataType: "JSON",
45
+ * prefixes: ["json:"]
46
+ * });
47
+ * ```
48
+ */
49
+ static create(client: GlideClient | GlideClusterClient, indexName: GlideString, schema: Field[], options?: FtCreateOptions): Promise<"OK">;
50
+ /**
51
+ * Deletes an index and associated content. Indexed document keys are unaffected.
52
+ *
53
+ * @param client - The client to execute the command.
54
+ * @param indexName - The index name.
55
+ * @returns "OK"
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Example usage of FT.DROPINDEX to drop an index
60
+ * await GlideFt.dropindex(client, "json_idx1"); // "OK"
61
+ * ```
62
+ */
63
+ static dropindex(client: GlideClient | GlideClusterClient, indexName: GlideString): Promise<"OK">;
64
+ /**
65
+ * Lists all indexes.
66
+ *
67
+ * @param client - The client to execute the command.
68
+ * @param options - (Optional) See {@link DecoderOption}.
69
+ * @returns An array of index names.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * console.log(await GlideFt.list(client)); // Output: ["index1", "index2"]
74
+ * ```
75
+ */
76
+ static list(client: GlideClient | GlideClusterClient, options?: DecoderOption): Promise<GlideString[]>;
77
+ /**
78
+ * Runs a search query on an index, and perform aggregate transformations on the results.
79
+ *
80
+ * @param client - The client to execute the command.
81
+ * @param indexName - The index name.
82
+ * @param query - The text query to search.
83
+ * @param options - Additional parameters for the command - see {@link FtAggregateOptions} and {@link DecoderOption}.
84
+ * @returns Results of the last stage of the pipeline.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const options: FtAggregateOptions = {
89
+ * loadFields: ["__key"],
90
+ * clauses: [
91
+ * {
92
+ * type: "GROUPBY",
93
+ * properties: ["@condition"],
94
+ * reducers: [
95
+ * {
96
+ * function: "TOLIST",
97
+ * args: ["__key"],
98
+ * name: "bicycles",
99
+ * },
100
+ * ],
101
+ * },
102
+ * ],
103
+ * };
104
+ * const result = await GlideFt.aggregate(client, "myIndex", "*", options);
105
+ * console.log(result); // Output:
106
+ * // [
107
+ * // [
108
+ * // {
109
+ * // key: "condition",
110
+ * // value: "refurbished"
111
+ * // },
112
+ * // {
113
+ * // key: "bicycles",
114
+ * // value: [ "bicycle:9" ]
115
+ * // }
116
+ * // ],
117
+ * // [
118
+ * // {
119
+ * // key: "condition",
120
+ * // value: "used"
121
+ * // },
122
+ * // {
123
+ * // key: "bicycles",
124
+ * // value: [ "bicycle:1", "bicycle:2", "bicycle:3" ]
125
+ * // }
126
+ * // ],
127
+ * // [
128
+ * // {
129
+ * // key: "condition",
130
+ * // value: "new"
131
+ * // },
132
+ * // {
133
+ * // key: "bicycles",
134
+ * // value: [ "bicycle:0", "bicycle:5" ]
135
+ * // }
136
+ * // ]
137
+ * // ]
138
+ * ```
139
+ */
140
+ static aggregate(client: GlideClient | GlideClusterClient, indexName: GlideString, query: GlideString, options?: DecoderOption & FtAggregateOptions): Promise<FtAggregateReturnType>;
141
+ /**
142
+ * Returns information about a given index.
143
+ *
144
+ * @param client - The client to execute the command.
145
+ * @param indexName - The index name.
146
+ * @param options - (Optional) See {@link DecoderOption}.
147
+ * @returns Nested maps with info about the index. See example for more details.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const info = await GlideFt.info(client, "myIndex");
152
+ * console.log(info); // Output:
153
+ * // {
154
+ * // index_name: 'myIndex',
155
+ * // index_status: 'AVAILABLE',
156
+ * // key_type: 'JSON',
157
+ * // creation_timestamp: 1728348101728771,
158
+ * // key_prefixes: [ 'json:' ],
159
+ * // num_indexed_vectors: 0,
160
+ * // space_usage: 653471,
161
+ * // num_docs: 0,
162
+ * // vector_space_usage: 653471,
163
+ * // index_degradation_percentage: 0,
164
+ * // fulltext_space_usage: 0,
165
+ * // current_lag: 0,
166
+ * // fields: [
167
+ * // {
168
+ * // identifier: '$.vec',
169
+ * // type: 'VECTOR',
170
+ * // field_name: 'VEC',
171
+ * // option: '',
172
+ * // vector_params: {
173
+ * // data_type: 'FLOAT32',
174
+ * // initial_capacity: 1000,
175
+ * // current_capacity: 1000,
176
+ * // distance_metric: 'L2',
177
+ * // dimension: 6,
178
+ * // block_size: 1024,
179
+ * // algorithm: 'FLAT'
180
+ * // }
181
+ * // },
182
+ * // {
183
+ * // identifier: 'name',
184
+ * // type: 'TEXT',
185
+ * // field_name: 'name',
186
+ * // option: ''
187
+ * // },
188
+ * // ]
189
+ * // }
190
+ * ```
191
+ */
192
+ static info(client: GlideClient | GlideClusterClient, indexName: GlideString, options?: DecoderOption): Promise<FtInfoReturnType>;
193
+ /**
194
+ * Parse a query and return information about how that query was parsed.
195
+ *
196
+ * @param client - The client to execute the command.
197
+ * @param indexName - The index name.
198
+ * @param query - The text query to search. It is the same as the query passed as
199
+ * an argument to {@link search | FT.SEARCH} or {@link aggregate | FT.AGGREGATE}.
200
+ * @param options - (Optional) See {@link DecoderOption}.
201
+ * @returns A query execution plan.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const result = GlideFt.explain(client, "myIndex", "@price:[0 10]");
206
+ * console.log(result); // Output: "Field {\n\tprice\n\t0\n\t10\n}"
207
+ * ```
208
+ */
209
+ static explain(client: GlideClient | GlideClusterClient, indexName: GlideString, query: GlideString, options?: DecoderOption): Promise<GlideString>;
210
+ /**
211
+ * Parse a query and return information about how that query was parsed.
212
+ * Same as {@link explain | FT.EXPLAIN}, except that the results are
213
+ * displayed in a different format.
214
+ *
215
+ * @param client - The client to execute the command.
216
+ * @param indexName - The index name.
217
+ * @param query - The text query to search. It is the same as the query passed as
218
+ * an argument to {@link search | FT.SEARCH} or {@link aggregate | FT.AGGREGATE}.
219
+ * @param options - (Optional) See {@link DecoderOption}.
220
+ * @returns A query execution plan.
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const result = GlideFt.explaincli(client, "myIndex", "@price:[0 10]");
225
+ * console.log(result); // Output: ["Field {", "price", "0", "10", "}"]
226
+ * ```
227
+ */
228
+ static explaincli(client: GlideClient | GlideClusterClient, indexName: GlideString, query: GlideString, options?: DecoderOption): Promise<GlideString[]>;
229
+ /**
230
+ * Uses the provided query expression to locate keys within an index. Once located, the count
231
+ * and/or content of indexed fields within those keys can be returned.
232
+ *
233
+ * @param client - The client to execute the command.
234
+ * @param indexName - The index name to search into.
235
+ * @param query - The text query to search.
236
+ * @param options - (Optional) See {@link FtSearchOptions} and {@link DecoderOption}.
237
+ * @returns A two-element array, where the first element is the number of documents in the result set, and the
238
+ * second element has the format: `GlideRecord<GlideRecord<GlideString>>`:
239
+ * a mapping between document names and a map of their attributes.
240
+ *
241
+ * If `count` or `limit` with values `{offset: 0, count: 0}` is
242
+ * set, the command returns array with only one element: the number of documents.
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * //
247
+ * const vector = Buffer.alloc(24);
248
+ * const result = await GlideFt.search(client, "json_idx1", "*=>[KNN 2 @VEC $query_vec]", {params: [{key: "query_vec", value: vector}]});
249
+ * console.log(result); // Output:
250
+ * // [
251
+ * // 2,
252
+ * // [
253
+ * // {
254
+ * // key: "json:2",
255
+ * // value: [
256
+ * // {
257
+ * // key: "$",
258
+ * // value: '{"vec":[1.1,1.2,1.3,1.4,1.5,1.6]}',
259
+ * // },
260
+ * // {
261
+ * // key: "__VEC_score",
262
+ * // value: "11.1100006104",
263
+ * // },
264
+ * // ],
265
+ * // },
266
+ * // {
267
+ * // key: "json:0",
268
+ * // value: [
269
+ * // {
270
+ * // key: "$",
271
+ * // value: '{"vec":[1,2,3,4,5,6]}',
272
+ * // },
273
+ * // {
274
+ * // key: "__VEC_score",
275
+ * // value: "91",
276
+ * // },
277
+ * // ],
278
+ * // },
279
+ * // ],
280
+ * // ]
281
+ * ```
282
+ */
283
+ static search(client: GlideClient | GlideClusterClient, indexName: GlideString, query: GlideString, options?: FtSearchOptions & DecoderOption): Promise<FtSearchReturnType>;
284
+ /**
285
+ * Runs a search query and collects performance profiling information.
286
+ *
287
+ * @param client - The client to execute the command.
288
+ * @param indexName - The index name.
289
+ * @param query - The text query to search.
290
+ * @param options - (Optional) See {@link FtSearchOptions} and {@link DecoderOption}. Additionally:
291
+ * - `limited` (Optional) - Either provide a full verbose output or some brief version.
292
+ *
293
+ * @returns A two-element array. The first element contains results of the search query being profiled, the
294
+ * second element stores profiling information.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * // Example of running profile on a search query
299
+ * const vector = Buffer.alloc(24);
300
+ * const result = await GlideFt.profileSearch(client, "json_idx1", "*=>[KNN 2 @VEC $query_vec]", {params: [{key: "query_vec", value: vector}]});
301
+ * console.log(result); // Output:
302
+ * // result[0] contains `FT.SEARCH` response with the given query
303
+ * // result[1] contains profiling data as a `Record<string, number>`
304
+ * ```
305
+ */
306
+ static profileSearch(client: GlideClient | GlideClusterClient, indexName: GlideString, query: GlideString, options?: DecoderOption & FtSearchOptions & {
307
+ limited?: boolean;
308
+ }): Promise<[FtSearchReturnType, Record<string, number>]>;
309
+ /**
310
+ * Runs an aggregate query and collects performance profiling information.
311
+ *
312
+ * @param client - The client to execute the command.
313
+ * @param indexName - The index name.
314
+ * @param query - The text query to search.
315
+ * @param options - (Optional) See {@link FtAggregateOptions} and {@link DecoderOption}. Additionally:
316
+ * - `limited` (Optional) - Either provide a full verbose output or some brief version.
317
+ *
318
+ * @returns A two-element array. The first element contains results of the aggregate query being profiled, the
319
+ * second element stores profiling information.
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * // Example of running profile on an aggregate query
324
+ * const options: FtAggregateOptions = {
325
+ * loadFields: ["__key"],
326
+ * clauses: [
327
+ * {
328
+ * type: "GROUPBY",
329
+ * properties: ["@condition"],
330
+ * reducers: [
331
+ * {
332
+ * function: "TOLIST",
333
+ * args: ["__key"],
334
+ * name: "bicycles",
335
+ * },
336
+ * ],
337
+ * },
338
+ * ],
339
+ * };
340
+ * const result = await GlideFt.profileAggregate(client, "myIndex", "*", options);
341
+ * console.log(result); // Output:
342
+ * // result[0] contains `FT.AGGREGATE` response with the given query
343
+ * // result[1] contains profiling data as a `Record<string, number>`
344
+ * ```
345
+ */
346
+ static profileAggregate(client: GlideClient | GlideClusterClient, indexName: GlideString, query: GlideString, options?: DecoderOption & FtAggregateOptions & {
347
+ limited?: boolean;
348
+ }): Promise<[FtAggregateReturnType, Record<string, number>]>;
349
+ /**
350
+ * Adds an alias for an index. The new alias name can be used anywhere that an index name is required.
351
+ *
352
+ * @param client - The client to execute the command.
353
+ * @param indexName - The alias to be added to the index.
354
+ * @param alias - The index name for which the alias has to be added.
355
+ * @returns `"OK"`
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * // Example usage of FT.ALIASADD to add an alias for an index.
360
+ * await GlideFt.aliasadd(client, "index", "alias"); // "OK"
361
+ * ```
362
+ */
363
+ static aliasadd(client: GlideClient | GlideClusterClient, indexName: GlideString, alias: GlideString): Promise<"OK">;
364
+ /**
365
+ * Deletes an existing alias for an index.
366
+ *
367
+ * @param client - The client to execute the command.
368
+ * @param alias - The existing alias to be deleted for an index.
369
+ * @returns `"OK"`
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * // Example usage of FT.ALIASDEL to delete an existing alias.
374
+ * await GlideFt.aliasdel(client, "alias"); // "OK"
375
+ * ```
376
+ */
377
+ static aliasdel(client: GlideClient | GlideClusterClient, alias: GlideString): Promise<"OK">;
378
+ /**
379
+ * Updates an existing alias to point to a different physical index. This command only affects future references to the alias.
380
+ *
381
+ * @param client - The client to execute the command.
382
+ * @param alias - The alias name. This alias will now be pointed to a different index.
383
+ * @param indexName - The index name for which an existing alias has to updated.
384
+ * @returns `"OK"`
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * // Example usage of FT.ALIASUPDATE to update an alias to point to a different index.
389
+ * await GlideFt.aliasupdate(client, "newAlias", "index"); // "OK"
390
+ * ```
391
+ */
392
+ static aliasupdate(client: GlideClient | GlideClusterClient, alias: GlideString, indexName: GlideString): Promise<"OK">;
393
+ /**
394
+ * List the index aliases.
395
+ *
396
+ * @param client - The client to execute the command.
397
+ * @param options - (Optional) See {@link DecoderOption}.
398
+ * @returns A map of index aliases for indices being aliased.
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * // Example usage of FT._ALIASLIST to query index aliases
403
+ * const result = await GlideFt.aliaslist(client);
404
+ * console.log(result); // Output:
405
+ * //[{"key": "alias1", "value": "index1"}, {"key": "alias2", "value": "index2"}]
406
+ * ```
407
+ */
408
+ static aliaslist(client: GlideClient | GlideClusterClient, options?: DecoderOption): Promise<GlideRecord<GlideString>>;
409
+ }