@@ -12,6 +12,13 @@ export async function ingestData(config, options) {
1212 throw new Error ( "Configuration missing. Run 'npx mongodb-rag init' first." ) ;
1313 }
1414
15+ const isDevelopment = process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
16+
17+ // Log the incoming config
18+ if ( isDevelopment ) {
19+ console . log ( 'Original config:' , JSON . stringify ( config , null , 2 ) ) ;
20+ }
21+
1522 // Restructure the config to match expected format
1623 const ragConfig = {
1724 mongodbUri : config . mongoUrl ,
@@ -32,6 +39,11 @@ export async function ingestData(config, options) {
3239 indexName : config . indexName
3340 } ;
3441
42+ // Log the restructured config
43+ if ( isDevelopment ) {
44+ console . log ( 'Restructured ragConfig:' , JSON . stringify ( ragConfig , null , 2 ) ) ;
45+ }
46+
3547 // Set environment variables from config if they're not already set
3648 if ( ! process . env . EMBEDDING_API_KEY && config . apiKey ) {
3749 process . env . EMBEDDING_API_KEY = config . apiKey ;
@@ -44,8 +56,20 @@ export async function ingestData(config, options) {
4456 }
4557
4658 try {
59+ if ( isDevelopment ) {
60+ console . log ( 'Creating MongoRAG instance with config...' ) ;
61+ }
62+
63+ const rag = new MongoRAG ( ragConfig ) ;
64+
65+ if ( isDevelopment ) {
66+ console . log ( 'Attempting to connect to MongoDB...' ) ;
67+ console . log ( 'MongoDB URI:' , ragConfig . mongodbUri ) ;
68+ }
69+
70+ await rag . connect ( ) ;
71+
4772 let documents = [ ] ;
48- const isDevelopment = process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
4973
5074 // Handle directory ingestion
5175 if ( options . directory ) {
@@ -89,9 +113,6 @@ export async function ingestData(config, options) {
89113 console . log ( chalk . blue ( `📊 Found ${ documents . length } documents to process` ) ) ;
90114 }
91115
92- const rag = new MongoRAG ( ragConfig ) ;
93- await rag . connect ( ) ;
94-
95116 const result = await rag . ingestBatch ( documents , {
96117 database : options . database || config . database ,
97118 collection : options . collection || config . collection
0 commit comments