@sparkleideas/memory 3.0.0-alpha.7
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/README.md +249 -0
- package/benchmarks/cache-hit-rate.bench.ts +535 -0
- package/benchmarks/hnsw-indexing.bench.ts +552 -0
- package/benchmarks/memory-write.bench.ts +469 -0
- package/benchmarks/vector-search.bench.ts +449 -0
- package/docs/AGENTDB-INTEGRATION.md +388 -0
- package/docs/CROSS_PLATFORM.md +505 -0
- package/docs/WINDOWS_SUPPORT.md +422 -0
- package/examples/agentdb-example.ts +345 -0
- package/examples/cross-platform-usage.ts +326 -0
- package/framework/benchmark.ts +112 -0
- package/package.json +42 -0
- package/src/agentdb-adapter.ts +1037 -0
- package/src/agentdb-backend.test.ts +339 -0
- package/src/agentdb-backend.ts +1016 -0
- package/src/agents/architect.yaml +11 -0
- package/src/agents/coder.yaml +11 -0
- package/src/agents/reviewer.yaml +10 -0
- package/src/agents/security-architect.yaml +10 -0
- package/src/agents/tester.yaml +10 -0
- package/src/application/commands/delete-memory.command.ts +172 -0
- package/src/application/commands/store-memory.command.ts +103 -0
- package/src/application/index.ts +36 -0
- package/src/application/queries/search-memory.query.ts +237 -0
- package/src/application/services/memory-application-service.ts +236 -0
- package/src/cache-manager.ts +516 -0
- package/src/database-provider.test.ts +364 -0
- package/src/database-provider.ts +511 -0
- package/src/domain/entities/memory-entry.ts +289 -0
- package/src/domain/index.ts +35 -0
- package/src/domain/repositories/memory-repository.interface.ts +120 -0
- package/src/domain/services/memory-domain-service.ts +403 -0
- package/src/hnsw-index.ts +1013 -0
- package/src/hybrid-backend.test.ts +399 -0
- package/src/hybrid-backend.ts +694 -0
- package/src/index.ts +515 -0
- package/src/infrastructure/index.ts +23 -0
- package/src/infrastructure/repositories/hybrid-memory-repository.ts +516 -0
- package/src/migration.ts +669 -0
- package/src/query-builder.ts +542 -0
- package/src/sqlite-backend.ts +732 -0
- package/src/sqljs-backend.ts +763 -0
- package/src/tmp.json +0 -0
- package/src/types.ts +727 -0
- package/tmp.json +0 -0
- package/tsconfig.json +11 -0
- package/verify-cross-platform.ts +170 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector Search Benchmark
|
|
3
|
+
*
|
|
4
|
+
* Target: <1ms (150x faster than current ~150ms)
|
|
5
|
+
*
|
|
6
|
+
* Measures vector similarity search performance including
|
|
7
|
+
* linear search baseline vs HNSW optimized search.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { benchmark, BenchmarkRunner, formatTime, meetsTarget } from '../framework/benchmark.js';
|
|
11
|
+
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Vector Operations
|
|
14
|
+
// ============================================================================
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generate a random vector of specified dimension
|
|
18
|
+
*/
|
|
19
|
+
function generateVector(dimension: number): Float32Array {
|
|
20
|
+
const vector = new Float32Array(dimension);
|
|
21
|
+
for (let i = 0; i < dimension; i++) {
|
|
22
|
+
vector[i] = Math.random() * 2 - 1;
|
|
23
|
+
}
|
|
24
|
+
return normalizeVector(vector);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Normalize a vector to unit length
|
|
29
|
+
*/
|
|
30
|
+
function normalizeVector(vector: Float32Array): Float32Array {
|
|
31
|
+
let sum = 0;
|
|
32
|
+
for (let i = 0; i < vector.length; i++) {
|
|
33
|
+
sum += vector[i]! * vector[i]!;
|
|
34
|
+
}
|
|
35
|
+
const magnitude = Math.sqrt(sum);
|
|
36
|
+
if (magnitude > 0) {
|
|
37
|
+
for (let i = 0; i < vector.length; i++) {
|
|
38
|
+
vector[i]! /= magnitude;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return vector;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Calculate cosine similarity between two vectors
|
|
46
|
+
*/
|
|
47
|
+
function cosineSimilarity(a: Float32Array, b: Float32Array): number {
|
|
48
|
+
let dot = 0;
|
|
49
|
+
for (let i = 0; i < a.length; i++) {
|
|
50
|
+
dot += a[i]! * b[i]!;
|
|
51
|
+
}
|
|
52
|
+
return dot;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Calculate Euclidean distance between two vectors
|
|
57
|
+
*/
|
|
58
|
+
function euclideanDistance(a: Float32Array, b: Float32Array): number {
|
|
59
|
+
let sum = 0;
|
|
60
|
+
for (let i = 0; i < a.length; i++) {
|
|
61
|
+
const diff = a[i]! - b[i]!;
|
|
62
|
+
sum += diff * diff;
|
|
63
|
+
}
|
|
64
|
+
return Math.sqrt(sum);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Search Implementations
|
|
69
|
+
// ============================================================================
|
|
70
|
+
|
|
71
|
+
interface SearchResult {
|
|
72
|
+
id: number;
|
|
73
|
+
score: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Linear (brute-force) search - O(n)
|
|
78
|
+
*/
|
|
79
|
+
function linearSearch(
|
|
80
|
+
query: Float32Array,
|
|
81
|
+
vectors: Float32Array[],
|
|
82
|
+
k: number
|
|
83
|
+
): SearchResult[] {
|
|
84
|
+
const scores: SearchResult[] = vectors.map((v, i) => ({
|
|
85
|
+
id: i,
|
|
86
|
+
score: cosineSimilarity(query, v),
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
scores.sort((a, b) => b.score - a.score);
|
|
90
|
+
return scores.slice(0, k);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Simple HNSW-like graph for approximate nearest neighbors
|
|
95
|
+
* Simplified implementation for benchmarking
|
|
96
|
+
*/
|
|
97
|
+
class SimpleHNSW {
|
|
98
|
+
private vectors: Float32Array[] = [];
|
|
99
|
+
private graph: Map<number, number[]> = new Map();
|
|
100
|
+
private entryPoint = 0;
|
|
101
|
+
private readonly maxConnections = 16;
|
|
102
|
+
private readonly efConstruction = 100;
|
|
103
|
+
|
|
104
|
+
add(vector: Float32Array): number {
|
|
105
|
+
const id = this.vectors.length;
|
|
106
|
+
this.vectors.push(vector);
|
|
107
|
+
|
|
108
|
+
if (id === 0) {
|
|
109
|
+
this.graph.set(id, []);
|
|
110
|
+
return id;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Find nearest neighbors using current graph
|
|
114
|
+
const neighbors = this.searchLayer(vector, this.entryPoint, this.efConstruction);
|
|
115
|
+
|
|
116
|
+
// Connect to nearest neighbors
|
|
117
|
+
const connections = neighbors
|
|
118
|
+
.slice(0, this.maxConnections)
|
|
119
|
+
.map((r) => r.id);
|
|
120
|
+
this.graph.set(id, connections);
|
|
121
|
+
|
|
122
|
+
// Add reverse connections
|
|
123
|
+
for (const neighborId of connections) {
|
|
124
|
+
const neighborConnections = this.graph.get(neighborId) || [];
|
|
125
|
+
if (neighborConnections.length < this.maxConnections) {
|
|
126
|
+
neighborConnections.push(id);
|
|
127
|
+
this.graph.set(neighborId, neighborConnections);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return id;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
search(query: Float32Array, k: number, ef = 50): SearchResult[] {
|
|
135
|
+
if (this.vectors.length === 0) return [];
|
|
136
|
+
|
|
137
|
+
const results = this.searchLayer(query, this.entryPoint, Math.max(k, ef));
|
|
138
|
+
return results.slice(0, k);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private searchLayer(
|
|
142
|
+
query: Float32Array,
|
|
143
|
+
entryPoint: number,
|
|
144
|
+
ef: number
|
|
145
|
+
): SearchResult[] {
|
|
146
|
+
const visited = new Set<number>();
|
|
147
|
+
const candidates: SearchResult[] = [
|
|
148
|
+
{ id: entryPoint, score: cosineSimilarity(query, this.vectors[entryPoint]!) },
|
|
149
|
+
];
|
|
150
|
+
const results: SearchResult[] = [...candidates];
|
|
151
|
+
|
|
152
|
+
visited.add(entryPoint);
|
|
153
|
+
|
|
154
|
+
while (candidates.length > 0) {
|
|
155
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
156
|
+
const current = candidates.shift()!;
|
|
157
|
+
|
|
158
|
+
const neighbors = this.graph.get(current.id) || [];
|
|
159
|
+
for (const neighborId of neighbors) {
|
|
160
|
+
if (visited.has(neighborId)) continue;
|
|
161
|
+
visited.add(neighborId);
|
|
162
|
+
|
|
163
|
+
const score = cosineSimilarity(query, this.vectors[neighborId]!);
|
|
164
|
+
results.push({ id: neighborId, score });
|
|
165
|
+
candidates.push({ id: neighborId, score });
|
|
166
|
+
|
|
167
|
+
if (results.length > ef) {
|
|
168
|
+
results.sort((a, b) => b.score - a.score);
|
|
169
|
+
results.length = ef;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (candidates.length > ef) {
|
|
174
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
175
|
+
candidates.length = ef;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
results.sort((a, b) => b.score - a.score);
|
|
180
|
+
return results;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
get size(): number {
|
|
184
|
+
return this.vectors.length;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Benchmark Suite
|
|
190
|
+
// ============================================================================
|
|
191
|
+
|
|
192
|
+
export async function runVectorSearchBenchmarks(): Promise<void> {
|
|
193
|
+
const runner = new BenchmarkRunner('Vector Search');
|
|
194
|
+
|
|
195
|
+
console.log('\n--- Vector Search Benchmarks ---\n');
|
|
196
|
+
|
|
197
|
+
const dimensions = 384; // Common embedding dimension
|
|
198
|
+
const k = 10; // Number of results to return
|
|
199
|
+
|
|
200
|
+
// Prepare test data
|
|
201
|
+
console.log('Preparing test data...');
|
|
202
|
+
|
|
203
|
+
// Small dataset (1,000 vectors)
|
|
204
|
+
const smallDataset = Array.from({ length: 1000 }, () => generateVector(dimensions));
|
|
205
|
+
const smallHNSW = new SimpleHNSW();
|
|
206
|
+
for (const v of smallDataset) {
|
|
207
|
+
smallHNSW.add(v);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Medium dataset (10,000 vectors)
|
|
211
|
+
const mediumDataset = Array.from({ length: 10000 }, () => generateVector(dimensions));
|
|
212
|
+
const mediumHNSW = new SimpleHNSW();
|
|
213
|
+
for (const v of mediumDataset) {
|
|
214
|
+
mediumHNSW.add(v);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Query vector
|
|
218
|
+
const query = generateVector(dimensions);
|
|
219
|
+
|
|
220
|
+
console.log('Test data prepared.\n');
|
|
221
|
+
|
|
222
|
+
// Benchmark 1: Linear Search - 1,000 vectors
|
|
223
|
+
const linear1kResult = await runner.run(
|
|
224
|
+
'linear-search-1k',
|
|
225
|
+
async () => {
|
|
226
|
+
linearSearch(query, smallDataset, k);
|
|
227
|
+
},
|
|
228
|
+
{ iterations: 100 }
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
console.log(`Linear Search (1k vectors): ${formatTime(linear1kResult.mean)}`);
|
|
232
|
+
|
|
233
|
+
// Benchmark 2: HNSW Search - 1,000 vectors
|
|
234
|
+
const hnsw1kResult = await runner.run(
|
|
235
|
+
'hnsw-search-1k',
|
|
236
|
+
async () => {
|
|
237
|
+
smallHNSW.search(query, k);
|
|
238
|
+
},
|
|
239
|
+
{ iterations: 500 }
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
console.log(`HNSW Search (1k vectors): ${formatTime(hnsw1kResult.mean)}`);
|
|
243
|
+
const speedup1k = linear1kResult.mean / hnsw1kResult.mean;
|
|
244
|
+
console.log(` Speedup: ${speedup1k.toFixed(1)}x`);
|
|
245
|
+
|
|
246
|
+
// Benchmark 3: Linear Search - 10,000 vectors
|
|
247
|
+
const linear10kResult = await runner.run(
|
|
248
|
+
'linear-search-10k',
|
|
249
|
+
async () => {
|
|
250
|
+
linearSearch(query, mediumDataset, k);
|
|
251
|
+
},
|
|
252
|
+
{ iterations: 20 }
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
console.log(`Linear Search (10k vectors): ${formatTime(linear10kResult.mean)}`);
|
|
256
|
+
|
|
257
|
+
// Benchmark 4: HNSW Search - 10,000 vectors
|
|
258
|
+
const hnsw10kResult = await runner.run(
|
|
259
|
+
'hnsw-search-10k',
|
|
260
|
+
async () => {
|
|
261
|
+
mediumHNSW.search(query, k);
|
|
262
|
+
},
|
|
263
|
+
{ iterations: 200 }
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
console.log(`HNSW Search (10k vectors): ${formatTime(hnsw10kResult.mean)}`);
|
|
267
|
+
const speedup10k = linear10kResult.mean / hnsw10kResult.mean;
|
|
268
|
+
console.log(` Speedup: ${speedup10k.toFixed(1)}x`);
|
|
269
|
+
|
|
270
|
+
// Check target
|
|
271
|
+
const target = meetsTarget('vector-search', hnsw10kResult.mean);
|
|
272
|
+
console.log(` Target (<1ms): ${target.met ? 'PASS' : 'FAIL'}`);
|
|
273
|
+
|
|
274
|
+
// Benchmark 5: Cosine Similarity Calculation
|
|
275
|
+
const v1 = generateVector(dimensions);
|
|
276
|
+
const v2 = generateVector(dimensions);
|
|
277
|
+
|
|
278
|
+
const cosineResult = await runner.run(
|
|
279
|
+
'cosine-similarity',
|
|
280
|
+
async () => {
|
|
281
|
+
cosineSimilarity(v1, v2);
|
|
282
|
+
},
|
|
283
|
+
{ iterations: 10000 }
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
console.log(`Cosine Similarity: ${formatTime(cosineResult.mean)}`);
|
|
287
|
+
|
|
288
|
+
// Benchmark 6: Euclidean Distance Calculation
|
|
289
|
+
const euclideanResult = await runner.run(
|
|
290
|
+
'euclidean-distance',
|
|
291
|
+
async () => {
|
|
292
|
+
euclideanDistance(v1, v2);
|
|
293
|
+
},
|
|
294
|
+
{ iterations: 10000 }
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
console.log(`Euclidean Distance: ${formatTime(euclideanResult.mean)}`);
|
|
298
|
+
|
|
299
|
+
// Benchmark 7: Vector Normalization
|
|
300
|
+
const normResult = await runner.run(
|
|
301
|
+
'vector-normalization',
|
|
302
|
+
async () => {
|
|
303
|
+
const v = new Float32Array(dimensions);
|
|
304
|
+
for (let i = 0; i < dimensions; i++) {
|
|
305
|
+
v[i] = Math.random();
|
|
306
|
+
}
|
|
307
|
+
normalizeVector(v);
|
|
308
|
+
},
|
|
309
|
+
{ iterations: 5000 }
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
console.log(`Vector Normalization: ${formatTime(normResult.mean)}`);
|
|
313
|
+
|
|
314
|
+
// Benchmark 8: Batch Search (5 queries)
|
|
315
|
+
const queries = Array.from({ length: 5 }, () => generateVector(dimensions));
|
|
316
|
+
|
|
317
|
+
const batchSearchResult = await runner.run(
|
|
318
|
+
'batch-search-5-queries',
|
|
319
|
+
async () => {
|
|
320
|
+
for (const q of queries) {
|
|
321
|
+
smallHNSW.search(q, k);
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
{ iterations: 100 }
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
console.log(`Batch Search (5 queries): ${formatTime(batchSearchResult.mean)}`);
|
|
328
|
+
|
|
329
|
+
// Benchmark 9: Parallel Batch Search
|
|
330
|
+
const parallelBatchResult = await runner.run(
|
|
331
|
+
'parallel-batch-search',
|
|
332
|
+
async () => {
|
|
333
|
+
await Promise.all(queries.map((q) => Promise.resolve(smallHNSW.search(q, k))));
|
|
334
|
+
},
|
|
335
|
+
{ iterations: 100 }
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
console.log(`Parallel Batch Search: ${formatTime(parallelBatchResult.mean)}`);
|
|
339
|
+
|
|
340
|
+
// Summary
|
|
341
|
+
console.log('\n--- Summary ---');
|
|
342
|
+
console.log(`1k vectors: Linear ${formatTime(linear1kResult.mean)} -> HNSW ${formatTime(hnsw1kResult.mean)} (${speedup1k.toFixed(1)}x)`);
|
|
343
|
+
console.log(`10k vectors: Linear ${formatTime(linear10kResult.mean)} -> HNSW ${formatTime(hnsw10kResult.mean)} (${speedup10k.toFixed(1)}x)`);
|
|
344
|
+
console.log(`\nProjected for 100k vectors: ~${((speedup10k * 10)).toFixed(0)}x improvement`);
|
|
345
|
+
console.log(`Projected for 1M vectors: ~${((speedup10k * 100)).toFixed(0)}x improvement`);
|
|
346
|
+
|
|
347
|
+
// Print full results
|
|
348
|
+
runner.printResults();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ============================================================================
|
|
352
|
+
// Vector Search Optimization Strategies
|
|
353
|
+
// ============================================================================
|
|
354
|
+
|
|
355
|
+
export const vectorSearchOptimizations = {
|
|
356
|
+
/**
|
|
357
|
+
* HNSW Indexing: Hierarchical Navigable Small World graphs
|
|
358
|
+
*/
|
|
359
|
+
hnswIndexing: {
|
|
360
|
+
description: 'Use HNSW for O(log n) approximate nearest neighbor search',
|
|
361
|
+
expectedImprovement: '150x-12500x',
|
|
362
|
+
implementation: `
|
|
363
|
+
import { HNSW } from '@sparkleideas/agentdb';
|
|
364
|
+
|
|
365
|
+
const index = new HNSW({
|
|
366
|
+
dimensions: 384,
|
|
367
|
+
maxElements: 1000000,
|
|
368
|
+
efConstruction: 200,
|
|
369
|
+
M: 16,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
index.addItems(vectors);
|
|
373
|
+
const results = index.search(query, k);
|
|
374
|
+
`,
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* SIMD Operations: Use SIMD for vector math
|
|
379
|
+
*/
|
|
380
|
+
simdOperations: {
|
|
381
|
+
description: 'Use SIMD instructions for parallel vector operations',
|
|
382
|
+
expectedImprovement: '4-8x',
|
|
383
|
+
implementation: `
|
|
384
|
+
// Use typed arrays and native SIMD when available
|
|
385
|
+
function dotProductSIMD(a: Float32Array, b: Float32Array): number {
|
|
386
|
+
// Node.js will use SIMD when available
|
|
387
|
+
let sum = 0;
|
|
388
|
+
for (let i = 0; i < a.length; i += 4) {
|
|
389
|
+
sum += a[i] * b[i] + a[i+1] * b[i+1] + a[i+2] * b[i+2] + a[i+3] * b[i+3];
|
|
390
|
+
}
|
|
391
|
+
return sum;
|
|
392
|
+
}
|
|
393
|
+
`,
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Quantization: Use int8 instead of float32
|
|
398
|
+
*/
|
|
399
|
+
quantization: {
|
|
400
|
+
description: 'Quantize vectors to int8 for 4x memory savings and faster ops',
|
|
401
|
+
expectedImprovement: '2-4x speed, 4x memory',
|
|
402
|
+
implementation: `
|
|
403
|
+
function quantize(vector: Float32Array): Int8Array {
|
|
404
|
+
const quantized = new Int8Array(vector.length);
|
|
405
|
+
for (let i = 0; i < vector.length; i++) {
|
|
406
|
+
quantized[i] = Math.round(vector[i] * 127);
|
|
407
|
+
}
|
|
408
|
+
return quantized;
|
|
409
|
+
}
|
|
410
|
+
`,
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Batch Processing: Process multiple queries together
|
|
415
|
+
*/
|
|
416
|
+
batchProcessing: {
|
|
417
|
+
description: 'Process multiple queries in a single batch for better cache utilization',
|
|
418
|
+
expectedImprovement: '2-5x',
|
|
419
|
+
implementation: `
|
|
420
|
+
async function batchSearch(queries: Float32Array[], k: number): Promise<SearchResult[][]> {
|
|
421
|
+
// Process all queries together for better cache locality
|
|
422
|
+
return queries.map(q => index.search(q, k));
|
|
423
|
+
}
|
|
424
|
+
`,
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Pre-filtering: Reduce search space with metadata filters
|
|
429
|
+
*/
|
|
430
|
+
preFiltering: {
|
|
431
|
+
description: 'Use metadata filters to reduce the search space before vector search',
|
|
432
|
+
expectedImprovement: '2-10x',
|
|
433
|
+
implementation: `
|
|
434
|
+
function filteredSearch(query: Float32Array, filter: Filter, k: number): SearchResult[] {
|
|
435
|
+
// First apply metadata filter
|
|
436
|
+
const candidates = applyFilter(filter);
|
|
437
|
+
// Then search only within filtered candidates
|
|
438
|
+
return searchWithinCandidates(query, candidates, k);
|
|
439
|
+
}
|
|
440
|
+
`,
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// Run if executed directly
|
|
445
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
446
|
+
runVectorSearchBenchmarks().catch(console.error);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export default runVectorSearchBenchmarks;
|