redis-vl 0.1.0-beta.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.
- package/LICENSE +22 -0
- package/README.md +212 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +87 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes/search-index.d.ts +368 -0
- package/dist/indexes/search-index.d.ts.map +1 -0
- package/dist/indexes/search-index.js +475 -0
- package/dist/indexes/search-index.js.map +1 -0
- package/dist/query/base.d.ts +51 -0
- package/dist/query/base.d.ts.map +1 -0
- package/dist/query/base.js +6 -0
- package/dist/query/base.js.map +1 -0
- package/dist/query/index.d.ts +7 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +7 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/vector.d.ts +199 -0
- package/dist/query/vector.d.ts.map +1 -0
- package/dist/query/vector.js +198 -0
- package/dist/query/vector.js.map +1 -0
- package/dist/redis/index-info-parser.d.ts +25 -0
- package/dist/redis/index-info-parser.d.ts.map +1 -0
- package/dist/redis/index-info-parser.js +301 -0
- package/dist/redis/index-info-parser.js.map +1 -0
- package/dist/redis/schema-types.d.ts +81 -0
- package/dist/redis/schema-types.d.ts.map +1 -0
- package/dist/redis/schema-types.js +18 -0
- package/dist/redis/schema-types.js.map +1 -0
- package/dist/redis/utils.d.ts +7 -0
- package/dist/redis/utils.d.ts.map +1 -0
- package/dist/redis/utils.js +221 -0
- package/dist/redis/utils.js.map +1 -0
- package/dist/schema/fields.d.ts +163 -0
- package/dist/schema/fields.d.ts.map +1 -0
- package/dist/schema/fields.js +304 -0
- package/dist/schema/fields.js.map +1 -0
- package/dist/schema/index.d.ts +8 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +8 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/schema.d.ts +247 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/schema.js +403 -0
- package/dist/schema/schema.js.map +1 -0
- package/dist/schema/types.d.ts +56 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +62 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/storage/base-storage.d.ts +107 -0
- package/dist/storage/base-storage.d.ts.map +1 -0
- package/dist/storage/base-storage.js +187 -0
- package/dist/storage/base-storage.js.map +1 -0
- package/dist/storage/hash-storage.d.ts +29 -0
- package/dist/storage/hash-storage.d.ts.map +1 -0
- package/dist/storage/hash-storage.js +122 -0
- package/dist/storage/hash-storage.js.map +1 -0
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +4 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/json-storage.d.ts +19 -0
- package/dist/storage/json-storage.d.ts.map +1 -0
- package/dist/storage/json-storage.js +81 -0
- package/dist/storage/json-storage.js.map +1 -0
- package/dist/utils/distance.d.ts +92 -0
- package/dist/utils/distance.d.ts.map +1 -0
- package/dist/utils/distance.js +98 -0
- package/dist/utils/distance.js.map +1 -0
- package/dist/vectorizers/base-vectorizer.d.ts +88 -0
- package/dist/vectorizers/base-vectorizer.d.ts.map +1 -0
- package/dist/vectorizers/base-vectorizer.js +32 -0
- package/dist/vectorizers/base-vectorizer.js.map +1 -0
- package/dist/vectorizers/huggingface-vectorizer.d.ts +103 -0
- package/dist/vectorizers/huggingface-vectorizer.d.ts.map +1 -0
- package/dist/vectorizers/huggingface-vectorizer.js +142 -0
- package/dist/vectorizers/huggingface-vectorizer.js.map +1 -0
- package/dist/vectorizers/index.d.ts +10 -0
- package/dist/vectorizers/index.d.ts.map +1 -0
- package/dist/vectorizers/index.js +10 -0
- package/dist/vectorizers/index.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Search Index
|
|
3
|
+
* Main search index class for managing Redis search indexes.
|
|
4
|
+
*/
|
|
5
|
+
import { IndexSchema } from '../schema/schema.js';
|
|
6
|
+
import { buildRedisVLSchemaFromRedisIndexInfo } from '../redis/index-info-parser.js';
|
|
7
|
+
import { HashStorage, JsonStorage } from '../storage/index.js';
|
|
8
|
+
import { RedisVLError, SchemaValidationError } from '../errors.js';
|
|
9
|
+
import { VectorQuery } from '../query/vector.js';
|
|
10
|
+
import { DISTANCE_NORMALIZERS } from '../utils/distance.js';
|
|
11
|
+
/**
|
|
12
|
+
* SearchIndex class for managing Redis vector search indices.
|
|
13
|
+
*
|
|
14
|
+
* This class provides methods to create, manage, and query Redis search indices.
|
|
15
|
+
* Users create their own Redis client and pass it to the constructor.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { createClient } from 'redis';
|
|
20
|
+
* import { SearchIndex, IndexSchema, StorageType } from 'redis-vl';
|
|
21
|
+
*
|
|
22
|
+
* const client = createClient();
|
|
23
|
+
* await client.connect();
|
|
24
|
+
*
|
|
25
|
+
* const schema = new IndexSchema({
|
|
26
|
+
* index: { name: 'my-index', prefix: 'doc', storageType: StorageType.HASH }
|
|
27
|
+
* });
|
|
28
|
+
* schema.addField({ name: 'title', type: 'text' });
|
|
29
|
+
*
|
|
30
|
+
* const searchIndex = new SearchIndex(schema, client);
|
|
31
|
+
* await searchIndex.create();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class SearchIndex {
|
|
35
|
+
/**
|
|
36
|
+
* The index schema defining the structure and fields.
|
|
37
|
+
*/
|
|
38
|
+
schema;
|
|
39
|
+
/**
|
|
40
|
+
* The Redis client instance.
|
|
41
|
+
*/
|
|
42
|
+
client;
|
|
43
|
+
/**
|
|
44
|
+
* Internal storage handler for data operations.
|
|
45
|
+
*/
|
|
46
|
+
storage;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to validate documents against schema when loading.
|
|
49
|
+
* Can be overridden per load() call.
|
|
50
|
+
*/
|
|
51
|
+
validateOnLoad;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new SearchIndex instance.
|
|
54
|
+
*
|
|
55
|
+
* @param schema - The index schema
|
|
56
|
+
* @param client - Redis client instance (created by user)
|
|
57
|
+
* @param validateOnLoad - Whether to validate documents on load (default: false)
|
|
58
|
+
* @throws {Error} If schema is not a valid IndexSchema instance
|
|
59
|
+
* @throws {Error} If client is not provided
|
|
60
|
+
*/
|
|
61
|
+
constructor(schema, client, validateOnLoad = false) {
|
|
62
|
+
if (!(schema instanceof IndexSchema)) {
|
|
63
|
+
throw new RedisVLError('Must provide a valid IndexSchema object');
|
|
64
|
+
}
|
|
65
|
+
if (!client) {
|
|
66
|
+
throw new RedisVLError('Must provide a valid Redis client');
|
|
67
|
+
}
|
|
68
|
+
this.schema = schema;
|
|
69
|
+
this.client = client;
|
|
70
|
+
this.validateOnLoad = validateOnLoad;
|
|
71
|
+
// Initialize appropriate storage based on storage type
|
|
72
|
+
const isJson = this.schema.index.storageType.toLowerCase() === 'json';
|
|
73
|
+
this.storage = isJson ? new JsonStorage(schema) : new HashStorage(schema);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Load an existing index from Redis by name.
|
|
77
|
+
*
|
|
78
|
+
* This method fetches the index metadata using FT.INFO and reconstructs
|
|
79
|
+
* the IndexSchema from the stored information.
|
|
80
|
+
*
|
|
81
|
+
* @param name - Name of the existing index in Redis
|
|
82
|
+
* @param client - Redis client instance
|
|
83
|
+
* @param validateOnLoad - Whether to validate documents on load (default: false)
|
|
84
|
+
* @returns SearchIndex instance with reconstructed schema
|
|
85
|
+
* @throws {RedisVLError} If index doesn't exist or cannot be loaded
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Load an existing index
|
|
90
|
+
* const index = await SearchIndex.fromExisting('my-index', client);
|
|
91
|
+
*
|
|
92
|
+
* // Use the loaded index
|
|
93
|
+
* const docs = await index.fetchMany(['key1', 'key2']);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
static async fromExisting(name, client, validateOnLoad = false) {
|
|
97
|
+
let info;
|
|
98
|
+
try {
|
|
99
|
+
// Fetch index info from Redis
|
|
100
|
+
info = await client.ft.info(name);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
104
|
+
throw new RedisVLError(`Failed to load index '${name}' via FT.INFO: ${message}`, {
|
|
105
|
+
cause: error,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Convert to IndexSchema
|
|
109
|
+
// The parser accepts the raw return type from client.ft.info()
|
|
110
|
+
const schema = buildRedisVLSchemaFromRedisIndexInfo(info);
|
|
111
|
+
// Create SearchIndex with reconstructed schema
|
|
112
|
+
return new SearchIndex(schema, client, validateOnLoad);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the index name from the schema.
|
|
116
|
+
*/
|
|
117
|
+
get name() {
|
|
118
|
+
return this.schema.index.name;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Convert schema fields to Redis field schema format.
|
|
122
|
+
* Each field class knows how to convert itself via the toRedisField() method.
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
convertFieldsToRedisSchema() {
|
|
126
|
+
const redisSchema = {};
|
|
127
|
+
const isJson = this.schema.index.storageType.toLowerCase() === 'json';
|
|
128
|
+
for (const field of Object.values(this.schema.fields)) {
|
|
129
|
+
// Determine the field key for Redis schema
|
|
130
|
+
let key;
|
|
131
|
+
if (isJson) {
|
|
132
|
+
// For JSON storage, use the path (which should already have $. prefix)
|
|
133
|
+
key = field.path || field.name;
|
|
134
|
+
// Safety check: ensure path starts with $.
|
|
135
|
+
if (!key.startsWith('$.')) {
|
|
136
|
+
key = `$.${key}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// For HASH storage, use the field name directly
|
|
141
|
+
key = field.name;
|
|
142
|
+
}
|
|
143
|
+
// Converts each field to Redis format
|
|
144
|
+
redisSchema[key] = field.toRedisField(isJson);
|
|
145
|
+
}
|
|
146
|
+
return redisSchema;
|
|
147
|
+
}
|
|
148
|
+
getVectorScoreAlias(query) {
|
|
149
|
+
return query instanceof VectorQuery ? query.scoreAlias : null;
|
|
150
|
+
}
|
|
151
|
+
getVectorDistanceNormalizer(query) {
|
|
152
|
+
if (!(query instanceof VectorQuery) || !query.normalizeDistance) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const vectorField = this.schema.fields[query.vectorField];
|
|
156
|
+
const metricFromSchema = vectorField?.type === 'vector'
|
|
157
|
+
? vectorField.attrs.distanceMetric
|
|
158
|
+
: undefined;
|
|
159
|
+
const distanceMetric = (metricFromSchema ?? query.distanceMetric ?? 'COSINE').toUpperCase();
|
|
160
|
+
return DISTANCE_NORMALIZERS[distanceMetric] || null;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create the index in Redis.
|
|
164
|
+
*
|
|
165
|
+
* @param options - Creation options
|
|
166
|
+
* @throws {Error} If no fields are defined for the index
|
|
167
|
+
* @returns The result from Redis FT.CREATE command
|
|
168
|
+
*/
|
|
169
|
+
async create(options = {}) {
|
|
170
|
+
const { overwrite = false, drop = false } = options;
|
|
171
|
+
// Check that fields are defined
|
|
172
|
+
const fields = Object.values(this.schema.fields);
|
|
173
|
+
if (fields.length === 0) {
|
|
174
|
+
throw new SchemaValidationError('No fields defined for index');
|
|
175
|
+
}
|
|
176
|
+
// Check if index already exists
|
|
177
|
+
if (await this.exists()) {
|
|
178
|
+
if (!overwrite) {
|
|
179
|
+
// Index exists and we're not overwriting - do nothing
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Delete existing index
|
|
183
|
+
await this.delete({ drop });
|
|
184
|
+
}
|
|
185
|
+
// Create the index using Redis FT.CREATE
|
|
186
|
+
const fieldSchema = this.convertFieldsToRedisSchema();
|
|
187
|
+
return this.client.ft.create(this.name, fieldSchema, {
|
|
188
|
+
ON: this.schema.index.storageType.toUpperCase(),
|
|
189
|
+
PREFIX: this.schema.index.prefix,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Check if the index exists in Redis.
|
|
194
|
+
*
|
|
195
|
+
* @returns True if the index exists, false otherwise
|
|
196
|
+
*/
|
|
197
|
+
async exists() {
|
|
198
|
+
try {
|
|
199
|
+
// Try to get index info - if it exists, this will succeed
|
|
200
|
+
await this.client.ft.info(this.name);
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// If index doesn't exist, FT.INFO will throw an error
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Delete the index from Redis.
|
|
210
|
+
*
|
|
211
|
+
* @param options - Deletion options
|
|
212
|
+
* @returns The result from Redis FT.DROPINDEX command
|
|
213
|
+
*/
|
|
214
|
+
async delete(options = {}) {
|
|
215
|
+
const { drop = false } = options;
|
|
216
|
+
if (drop) {
|
|
217
|
+
// Drop index and associated data
|
|
218
|
+
return this.client.ft.dropIndex(this.name, { DD: true });
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// Drop index only, keep data
|
|
222
|
+
return this.client.ft.dropIndex(this.name);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get information about the index.
|
|
227
|
+
*
|
|
228
|
+
* @returns Index information from Redis
|
|
229
|
+
*/
|
|
230
|
+
async info() {
|
|
231
|
+
return this.client.ft.info(this.name);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Load documents into the index.
|
|
235
|
+
*
|
|
236
|
+
* This method handles:
|
|
237
|
+
* - Auto-generating keys using ULID if no idField or keys provided
|
|
238
|
+
* - Extracting IDs from documents using idField
|
|
239
|
+
* - Using explicit keys if provided
|
|
240
|
+
* - Preprocessing documents before storage
|
|
241
|
+
* - Setting TTL on documents
|
|
242
|
+
* - Supporting both HASH and JSON storage types
|
|
243
|
+
* - Batching operations using Redis pipelining for performance
|
|
244
|
+
* - Optional schema validation
|
|
245
|
+
*
|
|
246
|
+
* @param data - Array of documents to load
|
|
247
|
+
* @param options - Load options
|
|
248
|
+
* @returns Array of keys that were loaded
|
|
249
|
+
* @throws {Error} If keys length doesn't match data length
|
|
250
|
+
* @throws {Error} If idField is not found in a document
|
|
251
|
+
* @throws {SchemaValidationError} If validation fails when validateOnLoad is enabled
|
|
252
|
+
* @throws {RedisVLError} If there's an error loading data to Redis
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // Auto-generate keys
|
|
257
|
+
* const keys = await index.load([
|
|
258
|
+
* { title: 'Doc 1', score: 100 },
|
|
259
|
+
* { title: 'Doc 2', score: 200 }
|
|
260
|
+
* ]);
|
|
261
|
+
*
|
|
262
|
+
* // Use idField
|
|
263
|
+
* const keys = await index.load(
|
|
264
|
+
* [{ id: 'user1', name: 'John' }],
|
|
265
|
+
* { idField: 'id' }
|
|
266
|
+
* );
|
|
267
|
+
*
|
|
268
|
+
* // Use explicit keys
|
|
269
|
+
* const keys = await index.load(
|
|
270
|
+
* [{ name: 'John' }],
|
|
271
|
+
* { keys: ['user:1'] }
|
|
272
|
+
* );
|
|
273
|
+
*
|
|
274
|
+
* // With preprocessing, TTL, and validation
|
|
275
|
+
* const keys = await index.load(
|
|
276
|
+
* [{ name: 'John' }],
|
|
277
|
+
* {
|
|
278
|
+
* ttl: 3600,
|
|
279
|
+
* batchSize: 100,
|
|
280
|
+
* validateOnLoad: true,
|
|
281
|
+
* preprocess: (doc) => ({ ...doc, timestamp: Date.now() })
|
|
282
|
+
* }
|
|
283
|
+
* );
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
async load(data, options = {}) {
|
|
287
|
+
// Use instance-level validateOnLoad setting if not overridden in options
|
|
288
|
+
const validateOnLoad = options.validateOnLoad ?? this.validateOnLoad;
|
|
289
|
+
try {
|
|
290
|
+
return await this.storage.write(this.client, data, { ...options, validateOnLoad });
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
if (error instanceof SchemaValidationError) {
|
|
294
|
+
// Re-throw validation errors as-is with detailed information
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
// Wrap other errors as general RedisVL errors
|
|
298
|
+
throw new RedisVLError(`Failed to load data: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Fetch a single document by key.
|
|
303
|
+
*
|
|
304
|
+
* @param key - The document key (without prefix)
|
|
305
|
+
* @returns The document or null if not found
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const doc = await index.fetch('123');
|
|
310
|
+
*/
|
|
311
|
+
async fetch(key) {
|
|
312
|
+
try {
|
|
313
|
+
// Normalize prefix (use first prefix if array)
|
|
314
|
+
const prefix = Array.isArray(this.schema.index.prefix)
|
|
315
|
+
? this.schema.index.prefix[0]
|
|
316
|
+
: this.schema.index.prefix;
|
|
317
|
+
// Build full key with prefix and separator
|
|
318
|
+
// Normalize prefix by removing trailing separator to avoid double separators (e.g. ::)
|
|
319
|
+
const normalizedPrefix = prefix.endsWith(this.schema.index.keySeparator)
|
|
320
|
+
? prefix.slice(0, -this.schema.index.keySeparator.length)
|
|
321
|
+
: prefix;
|
|
322
|
+
const fullKey = normalizedPrefix
|
|
323
|
+
? `${normalizedPrefix}${this.schema.index.keySeparator}${key}`
|
|
324
|
+
: key;
|
|
325
|
+
// Fetch using storage layer
|
|
326
|
+
const results = await this.storage.get(this.client, [fullKey]);
|
|
327
|
+
// Return first result (or null)
|
|
328
|
+
return results[0];
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
throw new RedisVLError(`Failed to fetch document: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Fetch multiple documents by keys.
|
|
336
|
+
* Uses pipelining for efficient batch retrieval.
|
|
337
|
+
*
|
|
338
|
+
* @param keys - Array of document keys (without prefix)
|
|
339
|
+
* @param batchSize - Number of commands per pipeline batch (default: 200)
|
|
340
|
+
* @returns Array of documents (null for missing keys)
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const docs = await index.fetchMany(['123', '456', '789']);
|
|
345
|
+
*/
|
|
346
|
+
async fetchMany(keys, batchSize = 200) {
|
|
347
|
+
try {
|
|
348
|
+
if (!keys || keys.length === 0) {
|
|
349
|
+
return [];
|
|
350
|
+
}
|
|
351
|
+
// Normalize prefix (use first prefix if array)
|
|
352
|
+
const prefix = Array.isArray(this.schema.index.prefix)
|
|
353
|
+
? this.schema.index.prefix[0]
|
|
354
|
+
: this.schema.index.prefix;
|
|
355
|
+
// Build full keys with prefix and separator
|
|
356
|
+
// Normalize prefix by removing trailing separator to avoid double separators (e.g. ::)
|
|
357
|
+
const normalizedPrefix = prefix.endsWith(this.schema.index.keySeparator)
|
|
358
|
+
? prefix.slice(0, -this.schema.index.keySeparator.length)
|
|
359
|
+
: prefix;
|
|
360
|
+
const fullKeys = normalizedPrefix
|
|
361
|
+
? keys.map((key) => `${normalizedPrefix}${this.schema.index.keySeparator}${key}`)
|
|
362
|
+
: keys;
|
|
363
|
+
// Fetch using storage layer with pipelining
|
|
364
|
+
return await this.storage.get(this.client, fullKeys, batchSize);
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
throw new RedisVLError(`Failed to fetch documents: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Execute a search query against the index
|
|
372
|
+
*
|
|
373
|
+
* @param query - Query object (VectorQuery, FilterQuery, etc.)
|
|
374
|
+
* @param options - Optional query execution options
|
|
375
|
+
* @returns Search results with documents and scores
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```typescript
|
|
379
|
+
* import { VectorQuery } from 'redis-vl';
|
|
380
|
+
*
|
|
381
|
+
* // Vector similarity search
|
|
382
|
+
* const query = new VectorQuery({
|
|
383
|
+
* vector: embedding,
|
|
384
|
+
* vectorField: 'embedding',
|
|
385
|
+
* topK: 10,
|
|
386
|
+
* returnFields: ['title', 'content']
|
|
387
|
+
* });
|
|
388
|
+
*
|
|
389
|
+
* const results = await index.search(query);
|
|
390
|
+
* console.log(`Found ${results.total} results`);
|
|
391
|
+
*
|
|
392
|
+
* results.documents.forEach((doc) => {
|
|
393
|
+
* console.log(`${doc.value.title} (score: ${doc.score})`);
|
|
394
|
+
* });
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* // Vector search with metadata filtering
|
|
400
|
+
* const query = new VectorQuery({
|
|
401
|
+
* vector: embedding,
|
|
402
|
+
* vectorField: 'embedding',
|
|
403
|
+
* filter: '@category:{electronics}',
|
|
404
|
+
* topK: 5
|
|
405
|
+
* });
|
|
406
|
+
*
|
|
407
|
+
* const results = await index.search(query);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
async search(query, options) {
|
|
411
|
+
try {
|
|
412
|
+
const queryString = query.buildQuery();
|
|
413
|
+
const params = query.buildParams();
|
|
414
|
+
const scoreAlias = this.getVectorScoreAlias(query);
|
|
415
|
+
const normalizer = this.getVectorDistanceNormalizer(query);
|
|
416
|
+
// Build FT.SEARCH options
|
|
417
|
+
const searchOptions = {
|
|
418
|
+
PARAMS: params,
|
|
419
|
+
DIALECT: options?.dialect ?? 2, // DIALECT 2 required for KNN
|
|
420
|
+
};
|
|
421
|
+
// Add RETURN fields if specified
|
|
422
|
+
// For VectorQuery, always include the score field (vector_distance by default)
|
|
423
|
+
if (query.returnFields && query.returnFields.length > 0) {
|
|
424
|
+
const returnFields = [...query.returnFields];
|
|
425
|
+
if (scoreAlias && !returnFields.includes(scoreAlias)) {
|
|
426
|
+
returnFields.push(scoreAlias);
|
|
427
|
+
}
|
|
428
|
+
searchOptions.RETURN = returnFields;
|
|
429
|
+
}
|
|
430
|
+
// Add pagination
|
|
431
|
+
if (query.limit !== undefined || query.offset !== undefined) {
|
|
432
|
+
const offset = query.offset ?? 0;
|
|
433
|
+
const limit = query.limit ?? 10;
|
|
434
|
+
searchOptions.LIMIT = { from: offset, size: limit };
|
|
435
|
+
}
|
|
436
|
+
// Add sorting if specified
|
|
437
|
+
if (options?.sortBy) {
|
|
438
|
+
searchOptions.SORTBY = options.sortBy;
|
|
439
|
+
if (options.sortOrder) {
|
|
440
|
+
searchOptions.SORTBY = {
|
|
441
|
+
BY: options.sortBy,
|
|
442
|
+
DIRECTION: options.sortOrder,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// Execute search
|
|
447
|
+
const response = await this.client.ft.search(this.schema.index.name, queryString, searchOptions);
|
|
448
|
+
// Transform response to SearchResult format
|
|
449
|
+
const documents = response.documents.map((doc) => {
|
|
450
|
+
const value = doc.value;
|
|
451
|
+
const scoreValue = scoreAlias ? value[scoreAlias] : undefined;
|
|
452
|
+
let score = typeof scoreValue === 'string'
|
|
453
|
+
? parseFloat(scoreValue)
|
|
454
|
+
: scoreValue;
|
|
455
|
+
// Apply normalization if needed
|
|
456
|
+
if (score !== undefined && normalizer) {
|
|
457
|
+
score = normalizer(score);
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
id: doc.id,
|
|
461
|
+
value: value,
|
|
462
|
+
score,
|
|
463
|
+
};
|
|
464
|
+
});
|
|
465
|
+
return {
|
|
466
|
+
total: response.total,
|
|
467
|
+
documents,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
throw new RedisVLError(`Failed to execute search query: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=search-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-index.js","sourceRoot":"","sources":["../../src/indexes/search-index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,oCAAoC,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAe,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AA0F5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,WAAW;IACpB;;OAEG;IACa,MAAM,CAAc;IAEpC;;OAEG;IACc,MAAM,CAAqC;IAE5D;;OAEG;IACc,OAAO,CAAc;IAEtC;;;OAGG;IACc,cAAc,CAAU;IAEzC;;;;;;;;OAQG;IACH,YACI,MAAmB,EACnB,MAA0C,EAC1C,cAAc,GAAG,KAAK;QAEtB,IAAI,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,YAAY,CAAC,yCAAyC,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,YAAY,CAAC,mCAAmC,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,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,SAAS,CAAC;gBAC9D,IAAI,KAAK,GACL,OAAO,UAAU,KAAK,QAAQ;oBAC1B,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;oBACxB,CAAC,CAAE,UAAiC,CAAC;gBAE7C,gCAAgC;gBAChC,IAAI,KAAK,KAAK,SAAS,IAAI,UAAU,EAAE,CAAC;oBACpC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;gBAC9B,CAAC;gBAED,OAAO;oBACH,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,KAAK,EAAE,KAAU;oBACjB,KAAK;iBACR,CAAC;YACN,CAAC,CAAC,CAAC;YAEH,OAAO;gBACH,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,SAAS;aACZ,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,YAAY,CAClB,mCAAmC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC3F,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,CACxD,CAAC;QACN,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Query
|
|
3
|
+
* Query builders for Redis search operations.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base interface for all query types
|
|
7
|
+
*/
|
|
8
|
+
export interface BaseQuery {
|
|
9
|
+
/** Fields to return in results */
|
|
10
|
+
returnFields?: string[];
|
|
11
|
+
/** Number of results to return */
|
|
12
|
+
limit?: number;
|
|
13
|
+
/** Offset for pagination */
|
|
14
|
+
offset?: number;
|
|
15
|
+
/** Build the Redis query string */
|
|
16
|
+
buildQuery(): string;
|
|
17
|
+
/** Build the query parameters for Redis */
|
|
18
|
+
buildParams(): Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Search result document with optional score
|
|
22
|
+
*/
|
|
23
|
+
export interface SearchDocument<T = Record<string, unknown>> {
|
|
24
|
+
/** Document fields */
|
|
25
|
+
value: T;
|
|
26
|
+
/** Relevance score (for vector search) */
|
|
27
|
+
score?: number;
|
|
28
|
+
/** Document ID */
|
|
29
|
+
id: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Search result structure
|
|
33
|
+
*/
|
|
34
|
+
export interface SearchResult<T = Record<string, unknown>> {
|
|
35
|
+
/** Total number of results */
|
|
36
|
+
total: number;
|
|
37
|
+
/** Retrieved documents */
|
|
38
|
+
documents: SearchDocument<T>[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for query execution
|
|
42
|
+
*/
|
|
43
|
+
export interface QueryOptions {
|
|
44
|
+
/** Redis DIALECT version (default: 2 for KNN) */
|
|
45
|
+
dialect?: number;
|
|
46
|
+
/** Sort by field */
|
|
47
|
+
sortBy?: string;
|
|
48
|
+
/** Sort order */
|
|
49
|
+
sortOrder?: 'ASC' | 'DESC';
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/query/base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,mCAAmC;IACnC,UAAU,IAAI,MAAM,CAAC;IAErB,2CAA2C;IAC3C,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvD,sBAAsB;IACtB,KAAK,EAAE,CAAC,CAAC;IAET,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,kBAAkB;IAClB,EAAE,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IAEd,0BAA0B;IAC1B,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,oBAAoB;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,iBAAiB;IACjB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/query/base.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|