@@ -21,46 +21,24 @@ export class LanceDBStorageProvider implements VectorStorageProvider {
2121
2222 try {
2323 this . storagePath = storagePath ;
24-
25- // Ensure directory exists
2624 await fs . mkdir ( storagePath , { recursive : true } ) ;
2725
28- // Dynamic import to avoid issues at require time
2926 const lancedb = await import ( '@lancedb/lancedb' ) ;
30-
31- // Connect to database
3227 this . db = await lancedb . connect ( storagePath ) ;
3328
34- // Check if table exists and has valid schema
29+ // Check if table exists and validate schema
3530 const tableNames = await this . db . tableNames ( ) ;
3631 if ( tableNames . includes ( 'code_chunks' ) ) {
3732 this . table = await this . db . openTable ( 'code_chunks' ) ;
3833
39- // Validate schema has vector column (required for semantic search)
40- try {
41- const schema = await this . table . schema ( ) ;
42- const hasVectorColumn = schema . fields . some ( ( f : any ) => f . name === 'vector' ) ;
43-
44- if ( ! hasVectorColumn ) {
45- console . error ( 'Stale index detected (missing vector column). Rebuilding...' ) ;
46- await this . db . dropTable ( 'code_chunks' ) ;
47- this . table = null ;
48- throw new IndexCorruptedError ( 'LanceDB index corrupted: missing vector column' ) ;
49- } else {
50- console . error ( 'Opened existing LanceDB table' ) ;
51- }
52- } catch ( schemaError ) {
53- if ( schemaError instanceof IndexCorruptedError ) {
54- throw schemaError ;
55- }
56- // If schema check fails, table is likely corrupted - drop and rebuild
57- console . error ( 'Failed to validate table schema, rebuilding index...' ) ;
58- await this . db . dropTable ( 'code_chunks' ) ;
59- this . table = null ;
60- throw new IndexCorruptedError ( 'LanceDB index corrupted: schema validation failed' ) ;
34+ const schema = await this . table . schema ( ) ;
35+ const hasVectorColumn = schema . fields . some ( ( f : any ) => f . name === 'vector' ) ;
36+
37+ if ( ! hasVectorColumn ) {
38+ throw new IndexCorruptedError ( 'LanceDB index corrupted: missing vector column' ) ;
6139 }
40+ console . error ( 'Opened existing LanceDB table' ) ;
6241 } else {
63- // Table missing entirely - not necessarily an error during initialization
6442 this . table = null ;
6543 }
6644
@@ -127,7 +105,6 @@ export class LanceDBStorageProvider implements VectorStorageProvider {
127105 filters ?: SearchFilters
128106 ) : Promise < VectorSearchResult [ ] > {
129107 if ( ! this . initialized || ! this . table ) {
130- // If table is missing, throw so auto-heal can fix it
131108 throw new IndexCorruptedError ( 'LanceDB index corrupted: no table available for search' ) ;
132109 }
133110
@@ -183,18 +160,13 @@ export class LanceDBStorageProvider implements VectorStorageProvider {
183160 distance : result . _distance || 0
184161 } ) ) ;
185162 } catch ( error ) {
186- if ( error instanceof Error && error . message . includes ( 'No vector column' ) ) {
187- throw new IndexCorruptedError ( 'LanceDB index corrupted: missing vector column' ) ;
188- }
189- console . error ( 'Failed to search:' , error ) ;
190- // For other errors, we throw IndexCorruptedError to be safe and trigger auto-heal
191- // if it looks like a database issue
192- if (
193- error instanceof Error &&
194- ( error . message . includes ( 'LanceDB' ) || error . message . includes ( 'Arrow' ) )
195- ) {
196- throw new IndexCorruptedError ( `LanceDB runtime error: ${ error . message } ` ) ;
163+ // Only trigger auto-heal for verified corruption patterns
164+ if ( error instanceof Error && error . message . toLowerCase ( ) . includes ( 'no vector column' ) ) {
165+ throw new IndexCorruptedError ( `LanceDB index corrupted: ${ error . message } ` ) ;
197166 }
167+
168+ // Transient errors - log and gracefully degrade
169+ console . error ( '[LanceDB] Search error:' , error instanceof Error ? error . message : error ) ;
198170 return [ ] ;
199171 }
200172 }
@@ -223,8 +195,7 @@ export class LanceDBStorageProvider implements VectorStorageProvider {
223195 }
224196
225197 try {
226- const result = await this . table . countRows ( ) ;
227- return result ;
198+ return await this . table . countRows ( ) ;
228199 } catch ( error ) {
229200 console . error ( 'Failed to count rows:' , error ) ;
230201 return 0 ;
0 commit comments