mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
feat: refresh vector cache on complete
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { refreshVectorCache } from '../../search/vector/vectorSearch';
|
||||
import type { HydratedIndexItem } from '../types';
|
||||
import vectorWorker from './vectorWorker.ts?inlineWorker';
|
||||
import type { SearchResult } from 'embeddia';
|
||||
@@ -66,6 +67,10 @@ export class VectorWorkerManager {
|
||||
case 'progress':
|
||||
if (this.progressCallback) {
|
||||
this.progressCallback(data);
|
||||
|
||||
if (data.status === 'complete') {
|
||||
refreshVectorCache();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -134,15 +134,12 @@ export async function performSearch(
|
||||
dynamicIdToItemMap: Map<string, HydratedIndexItem>,
|
||||
showRecentFirst: boolean,
|
||||
): Promise<CombinedResult[]> {
|
||||
const startTime = performance.now();
|
||||
|
||||
// Get all results first
|
||||
const commandResults = searchCommands(
|
||||
commandsFuse,
|
||||
query,
|
||||
commandIdToItemMap,
|
||||
);
|
||||
const commandEndTime = performance.now();
|
||||
const dynamicResults = searchDynamicItems(
|
||||
dynamicContentFuse,
|
||||
query,
|
||||
@@ -150,23 +147,12 @@ export async function performSearch(
|
||||
10,
|
||||
showRecentFirst,
|
||||
);
|
||||
const fuseEndTime = performance.now();
|
||||
|
||||
// Get vector results in parallel
|
||||
let vectorResults: VectorSearchResult[] = [];
|
||||
try {
|
||||
vectorResults = await searchVectors(query, 10);
|
||||
} catch (e) {}
|
||||
const vectorEndTime = performance.now();
|
||||
|
||||
console.log("Vector results:", vectorResults);
|
||||
|
||||
// Log timings
|
||||
console.log(`Command search took ${commandEndTime - startTime} milliseconds`);
|
||||
console.log(
|
||||
`Dynamic search took ${fuseEndTime - commandEndTime} milliseconds`,
|
||||
);
|
||||
console.log(`Vector search took ${vectorEndTime - fuseEndTime} milliseconds`);
|
||||
|
||||
// Create a map to store our final results, using ID as key to avoid duplicates
|
||||
const resultMap = new Map<string, CombinedResult>();
|
||||
|
||||
@@ -30,4 +30,10 @@ export async function searchVectors(query: string, topK: number = 10): Promise<V
|
||||
});
|
||||
|
||||
return results as VectorSearchResult[];
|
||||
}
|
||||
|
||||
export async function refreshVectorCache() {
|
||||
if (!vectorIndex) await initVectorSearch();
|
||||
vectorIndex!.clearIndexedDBCache();
|
||||
vectorIndex!.preloadIndexedDB();
|
||||
}
|
||||
Reference in New Issue
Block a user