fix collection creation validation (#130)

Signed-off-by: ChengZi <chen.zhang@zilliz.com>
This commit is contained in:
Cheney Zhang
2025-08-07 17:01:35 +08:00
committed by GitHub
parent 26f20dc2c3
commit 08b440cffe
2 changed files with 31 additions and 17 deletions

View File

@@ -735,7 +735,10 @@ export class Context {
await this.processChunkBuffer(chunkBuffer);
} catch (error) {
const searchType = isHybrid === true ? 'hybrid' : 'regular';
console.error(`❌ Failed to process chunk batch for ${searchType}: ${error}`);
console.error(`❌ Failed to process chunk batch for ${searchType}:`, error);
if (error instanceof Error) {
console.error('Stack trace:', error.stack);
}
} finally {
chunkBuffer = []; // Always clear buffer, even on failure
}
@@ -768,7 +771,10 @@ export class Context {
try {
await this.processChunkBuffer(chunkBuffer);
} catch (error) {
console.error(`❌ Failed to process final chunk batch for ${searchType}: ${error}`);
console.error(`❌ Failed to process final chunk batch for ${searchType}:`, error);
if (error instanceof Error) {
console.error('Stack trace:', error.stack);
}
}
}

View File

@@ -199,6 +199,11 @@ export class ToolHandlers {
};
}
//Check if the snapshot and cloud index are in sync
if (this.snapshotManager.getIndexedCodebases().includes(absolutePath) !== await this.context.hasIndex(absolutePath)) {
console.warn(`[INDEX-VALIDATION] ❌ Snapshot and cloud index mismatch: ${absolutePath}`);
}
// Check if already indexed (unless force is true)
if (!forceReindex && this.snapshotManager.getIndexedCodebases().includes(absolutePath)) {
return {
@@ -210,28 +215,31 @@ export class ToolHandlers {
};
}
// If force reindex and codebase is already indexed, remove it from indexed list
if (forceReindex && this.snapshotManager.getIndexedCodebases().includes(absolutePath)) {
console.log(`[FORCE-REINDEX] 🔄 Removing '${absolutePath}' from indexed list for re-indexing`);
this.snapshotManager.removeIndexedCodebase(absolutePath);
// If force reindex and codebase is already indexed, remove it
if (forceReindex) {
if (this.snapshotManager.getIndexedCodebases().includes(absolutePath)) {
console.log(`[FORCE-REINDEX] 🔄 Removing '${absolutePath}' from indexed list for re-indexing`);
this.snapshotManager.removeIndexedCodebase(absolutePath);
}
if (await this.context.hasIndex(absolutePath)) {
console.log(`[FORCE-REINDEX] 🔄 Clearing index for '${absolutePath}'`);
await this.context.clearIndex(absolutePath);
}
}
// CRITICAL: Pre-index collection creation validation
try {
console.log(`[INDEX-VALIDATION] 🔍 Validating collection creation capability`);
// Check if collection can be created (this will be handled entirely by context.ts)
const hasExistingIndex = await this.context.hasIndex(absolutePath);
if (hasExistingIndex && forceReindex) {
console.log(`[INDEX-VALIDATION] Force reindex enabled, existing index will be cleared`);
await this.context.clearIndex(absolutePath);
console.log(`[INDEX-VALIDATION] ✅ Existing index cleared for re-indexing`);
} else if (hasExistingIndex) {
console.log(`[INDEX-VALIDATION] Index already exists for this codebase`);
//dummy collection name
const collectionName = `dummy_collection_${Date.now()}`;
await this.context.getVectorDatabase().createCollection(collectionName, 128);
if (await this.context.getVectorDatabase().hasCollection(collectionName)) {
console.log(`[INDEX-VALIDATION] Dummy collection created successfully`);
await this.context.getVectorDatabase().dropCollection(collectionName);
} else {
console.log(`[INDEX-VALIDATION] ❌ Dummy collection creation failed`);
}
console.log(`[INDEX-VALIDATION] ✅ Collection creation validation completed`);
} catch (validationError: any) {
const errorMessage = typeof validationError === 'string' ? validationError :
(validationError instanceof Error ? validationError.message : String(validationError));