Skip to content

[Add]: Add pop-up block for notification in vscode-extension & add mcp prompt #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions packages/chrome-extension/src/stubs/milvus-vectordb-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ export class MilvusRestfulVectorDatabase {
return result;
} catch (error) {
console.error(`❌ Milvus REST API request failed to ${url}:`, error);

// Enhance error messages for common issues
if (error instanceof TypeError && error.message.includes('fetch')) {
throw new Error(`Network error: Unable to connect to Milvus server at ${this.config.address}. Please check the server address and ensure it's running.`);
}

throw error;
}
}
Expand Down Expand Up @@ -174,8 +174,8 @@ export class MilvusRestfulVectorDatabase {
}
};

// Create collection
await this.makeRequest('/collections/create', 'POST', collectionSchema);
// Create collection with limit check
await createCollectionWithLimitCheck(this.makeRequest.bind(this), collectionSchema);

// Create index
await this.createIndex(collectionName);
Expand Down Expand Up @@ -280,7 +280,7 @@ export class MilvusRestfulVectorDatabase {
limit: topK,
outputFields: [
"content",
"relativePath",
"relativePath",
"startLine",
"endLine",
"fileExtension",
Expand Down Expand Up @@ -323,7 +323,7 @@ export class MilvusRestfulVectorDatabase {
});

// Filter by threshold if provided
const filteredResults = options?.threshold !== undefined
const filteredResults = options?.threshold !== undefined
? results.filter(result => result.score >= options.threshold!)
: results;

Expand Down Expand Up @@ -366,11 +366,40 @@ export class MilvusRestfulVectorDatabase {

// Extract entity count from response (may vary based on Milvus version)
const entityCount = response.data?.numEntities || response.data?.entityCount || 0;

return { entityCount };
} catch (error) {
console.error(`❌ Failed to get collection stats for '${collectionName}':`, error);
return { entityCount: 0 };
}
}
}

/**
* Special error type for collection limit exceeded
* This allows us to distinguish it from other errors
*/
export const COLLECTION_LIMIT_MESSAGE = "[Error]: Your Zilliz Cloud account has hit its collection limit. To continue creating collections, you'll need to expand your capacity. We recommend visiting https://zilliz.com/pricing to explore options for dedicated or serverless clusters.";

/**
* Wrapper function to handle collection creation with limit detection
* This is the single point where collection limit errors are detected and handled
*/
async function createCollectionWithLimitCheck(
makeRequestFn: (endpoint: string, method: 'GET' | 'POST', data?: any) => Promise<any>,
collectionSchema: any
): Promise<void> {
try {
await makeRequestFn('/collections/create', 'POST', collectionSchema);
} catch (error: any) {
// Check if the error message contains the collection limit exceeded pattern
const errorMessage = error.message || error.toString() || '';
console.error(`❌ Error creating collection:`, errorMessage);
if (/exceeded the limit number of collections/i.test(errorMessage)) {
// Throw the exact message string, not an Error object
throw COLLECTION_LIMIT_MESSAGE;
}
// Re-throw other errors as-is
throw error;
}
}
31 changes: 26 additions & 5 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ export class CodeContext {
async indexCodebase(
codebasePath: string,
progressCallback?: (progress: { phase: string; current: number; total: number; percentage: number }) => void
): Promise<{ indexedFiles: number; totalChunks: number }> {
): Promise<{ indexedFiles: number; totalChunks: number; status: 'completed' | 'limit_reached' }> {
console.log(`🚀 Starting to index codebase: ${codebasePath}`);

// 1. Check and prepare vector collection
progressCallback?.({ phase: 'Preparing collection...', current: 0, total: 100, percentage: 0 });
console.log(`Debug2: Preparing vector collection for codebase`);
await this.prepareCollection(codebasePath);

// 2. Recursively traverse codebase to get all supported files
Expand All @@ -146,7 +147,7 @@ export class CodeContext {

if (codeFiles.length === 0) {
progressCallback?.({ phase: 'No files to index', current: 100, total: 100, percentage: 100 });
return { indexedFiles: 0, totalChunks: 0 };
return { indexedFiles: 0, totalChunks: 0, status: 'completed' };
}

// 3. Process each file with streaming chunk processing
Expand Down Expand Up @@ -183,7 +184,8 @@ export class CodeContext {

return {
indexedFiles: result.processedFiles,
totalChunks: result.totalChunks
totalChunks: result.totalChunks,
status: result.status
};
}

Expand Down Expand Up @@ -393,6 +395,7 @@ export class CodeContext {
*/
private async prepareCollection(codebasePath: string): Promise<void> {
// Create new collection
console.log(`🔧 Preparing vector collection for codebase: ${codebasePath}`);
const collectionName = this.getCollectionName(codebasePath);

// For Ollama embeddings, ensure dimension is detected before creating collection
Expand Down Expand Up @@ -463,13 +466,15 @@ export class CodeContext {
filePaths: string[],
codebasePath: string,
onFileProcessed?: (filePath: string, fileIndex: number, totalFiles: number) => void
): Promise<{ processedFiles: number; totalChunks: number }> {
): Promise<{ processedFiles: number; totalChunks: number; status: 'completed' | 'limit_reached' }> {
const EMBEDDING_BATCH_SIZE = Math.max(1, parseInt(process.env.EMBEDDING_BATCH_SIZE || '100', 10));
const CHUNK_LIMIT = 450000;
console.log(`🔧 Using EMBEDDING_BATCH_SIZE: ${EMBEDDING_BATCH_SIZE}`);

let chunkBuffer: Array<{ chunk: CodeChunk; codebasePath: string }> = [];
let processedFiles = 0;
let totalChunks = 0;
let limitReached = false;

for (let i = 0; i < filePaths.length; i++) {
const filePath = filePaths[i];
Expand All @@ -496,16 +501,28 @@ export class CodeContext {
try {
await this.processChunkBuffer(chunkBuffer);
} catch (error) {
// TODO:
console.error(`❌ Failed to process chunk batch: ${error}`);
} finally {
chunkBuffer = []; // Always clear buffer, even on failure
}
}

// Check if chunk limit is reached
if (totalChunks >= CHUNK_LIMIT) {
console.warn(`⚠️ Chunk limit of ${CHUNK_LIMIT} reached. Stopping indexing.`);
limitReached = true;
break; // Exit the inner loop (over chunks)
}
}

processedFiles++;
onFileProcessed?.(filePath, i + 1, filePaths.length);

if (limitReached) {
break; // Exit the outer loop (over files)
}

} catch (error) {
console.warn(`⚠️ Skipping file ${filePath}: ${error}`);
}
Expand All @@ -521,7 +538,11 @@ export class CodeContext {
}
}

return { processedFiles, totalChunks };
return {
processedFiles,
totalChunks,
status: limitReached ? 'limit_reached' : 'completed'
};
}

/**
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/vectordb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export interface VectorDatabase {
query(collectionName: string, filter: string, outputFields: string[]): Promise<Record<string, any>[]>;
}

/**
* Special error message for collection limit exceeded
* This allows us to distinguish it from other errors across all Milvus implementations
*/
export const COLLECTION_LIMIT_MESSAGE = "[Error]: Your Zilliz Cloud account has hit its collection limit. To continue creating collections, you'll need to expand your capacity. We recommend visiting https://zilliz.com/pricing to explore options for dedicated or serverless clusters.";

// Implementation class exports
export * from './milvus-restful-vectordb';
export * from './milvus-vectordb';
export { MilvusRestfulVectorDatabase, MilvusRestfulConfig } from './milvus-restful-vectordb';
export { MilvusVectorDatabase, MilvusConfig } from './milvus-vectordb';
26 changes: 24 additions & 2 deletions packages/core/src/vectordb/milvus-restful-vectordb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VectorDatabase, VectorDocument, SearchOptions, VectorSearchResult } from './index';
import { VectorDatabase, VectorDocument, SearchOptions, VectorSearchResult, COLLECTION_LIMIT_MESSAGE } from './index';

export interface MilvusRestfulConfig {
address: string;
Expand All @@ -8,6 +8,28 @@ export interface MilvusRestfulConfig {
database?: string;
}

/**
* Wrapper function to handle collection creation with limit detection
* This is the single point where collection limit errors are detected and handled
*/
async function createCollectionWithLimitCheck(
makeRequestFn: (endpoint: string, method: 'GET' | 'POST', data?: any) => Promise<any>,
collectionSchema: any
): Promise<void> {
try {
await makeRequestFn('/collections/create', 'POST', collectionSchema);
} catch (error: any) {
// Check if the error message contains the collection limit exceeded pattern
const errorMessage = error.message || error.toString() || '';
if (/exceeded the limit number of collections/i.test(errorMessage)) {
// Throw the exact message string, not an Error object
throw COLLECTION_LIMIT_MESSAGE;
}
// Re-throw other errors as-is
throw error;
}
}

/**
* Milvus Vector Database implementation using REST API
* This implementation is designed for environments where gRPC is not available,
Expand Down Expand Up @@ -145,7 +167,7 @@ export class MilvusRestfulVectorDatabase implements VectorDatabase {
};

// Step 1: Create collection with schema
await this.makeRequest('/collections/create', 'POST', collectionSchema);
await createCollectionWithLimitCheck(this.makeRequest.bind(this), collectionSchema);

// Step 2: Create index for vector field (separate API call)
await this.createIndex(collectionName);
Expand Down
33 changes: 29 additions & 4 deletions packages/core/src/vectordb/milvus-vectordb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
VectorDatabase,
VectorDocument,
SearchOptions,
VectorSearchResult
VectorSearchResult,
COLLECTION_LIMIT_MESSAGE
} from './index';

export interface MilvusConfig {
Expand All @@ -14,6 +15,28 @@ export interface MilvusConfig {
ssl?: boolean;
}

/**
* Wrapper function to handle collection creation with limit detection for gRPC client
* This is the single point where collection limit errors are detected and handled
*/
async function createCollectionWithLimitCheck(
client: MilvusClient,
createCollectionParams: any
): Promise<void> {
try {
await client.createCollection(createCollectionParams);
} catch (error: any) {
// Check if the error message contains the collection limit exceeded pattern
const errorMessage = error.message || error.toString() || '';
if (/exceeded the limit number of collections/i.test(errorMessage)) {
// Throw the exact message string, not an Error object
throw COLLECTION_LIMIT_MESSAGE;
}
// Re-throw other errors as-is
throw error;
}
}

export class MilvusVectorDatabase implements VectorDatabase {
private client: MilvusClient;
private config: MilvusConfig;
Expand All @@ -33,7 +56,8 @@ export class MilvusVectorDatabase implements VectorDatabase {


async createCollection(collectionName: string, dimension: number, description?: string): Promise<void> {

console.log('Beginning collection creation:', collectionName);
console.log('Collection dimension:', dimension);
const schema = [
{
name: 'id',
Expand Down Expand Up @@ -90,7 +114,7 @@ export class MilvusVectorDatabase implements VectorDatabase {
fields: schema,
};

await this.client.createCollection(createCollectionParams);
await createCollectionWithLimitCheck(this.client, createCollectionParams);

// Create index
const indexParams = {
Expand Down Expand Up @@ -128,6 +152,7 @@ export class MilvusVectorDatabase implements VectorDatabase {
}

async insert(collectionName: string, documents: VectorDocument[]): Promise<void> {
console.log('Inserting documents into collection:', collectionName);
const data = documents.map(doc => ({
id: doc.id,
vector: doc.vector,
Expand Down Expand Up @@ -200,4 +225,4 @@ export class MilvusVectorDatabase implements VectorDatabase {
throw error;
}
}
}
}
Loading