@@ -1205,9 +1205,6 @@ exports.getGoogleSheets = (req, res) => {
12051205 ) ;
12061206} ;
12071207
1208- /**
1209- * Helper function to ensure vector search index exists for RAG Example
1210- */
12111208/**
12121209 * Helper function to ensure vector search index exists for RAG Example
12131210 */
@@ -1229,11 +1226,10 @@ async function ensureVectorIndex(db) {
12291226
12301227 // Ensure hash index exists
12311228 const indexes = await collection . listIndexes ( ) . toArray ( ) ;
1232- const hashIndexExists = indexes . some ( ( index ) => index . key && index . key [ 'metadata.fileHash' ] ) ;
1233-
1229+ const hashIndexExists = indexes . some ( ( index ) => index . key && index . key . fileHash === 1 ) ;
12341230 if ( ! hashIndexExists ) {
1235- await collection . createIndex ( { 'metadata. fileHash' : 1 } ) ;
1236- console . log ( 'Created index on metadata. fileHash' ) ;
1231+ await collection . createIndex ( { fileHash : 1 } ) ;
1232+ console . log ( 'Created index on fileHash' ) ;
12371233 }
12381234
12391235 // Check if vector search index exists
@@ -1300,9 +1296,9 @@ exports.getRag = async (req, res) => {
13001296 // List all files in MongoDB vector DB
13011297 let ingestedFiles = [ ] ;
13021298 try {
1303- const client = new MongoClient ( process . env . MONGODB_URI , { dbName : 'hackathonstarter_rag' } ) ;
1299+ const client = new MongoClient ( process . env . MONGODB_URI ) ;
13041300 await client . connect ( ) ;
1305- const db = client . db ( 'hackathonstarter_rag' ) ;
1301+ const db = client . db ( ) ;
13061302 const collection = await ensureVectorIndex ( db ) ;
13071303
13081304 ingestedFiles = await collection . distinct ( 'source' ) ;
@@ -1357,7 +1353,7 @@ exports.postRagIngest = async (req, res) => {
13571353
13581354 try {
13591355 await client . connect ( ) ;
1360- const db = client . db ( 'hackathonstarter_rag' ) ;
1356+ const db = client . db ( ) ;
13611357 const collection = await ensureVectorIndex ( db ) ;
13621358
13631359 // Process files sequentially using reduce
@@ -1402,7 +1398,7 @@ exports.postRagIngest = async (req, res) => {
14021398
14031399 const embeddings = new HuggingFaceInferenceEmbeddings ( {
14041400 apiKey : process . env . HUGGINGFACE_KEY ,
1405- model : process . env . HUGGINGFACE_EMBEDING_MODEL || 'sentence-transformers/all-MiniLM-L6-v2' ,
1401+ model : process . env . HUGGINGFACE_EMBEDING_MODEL ,
14061402 } ) ;
14071403
14081404 await MongoDBAtlasVectorSearch . fromDocuments ( chunksWithMetadata , embeddings , {
@@ -1421,9 +1417,13 @@ exports.postRagIngest = async (req, res) => {
14211417 }
14221418 } , Promise . resolve ( ) ) ;
14231419
1424- if ( processed . length > 0 ) {
1420+ if ( processed . length > 0 && skipped . length > 0 ) {
1421+ req . flash ( 'success' , {
1422+ msg : `Successfully ingested ${ processed . length } file(s): ${ processed . join ( ', ' ) } . Skipped ${ skipped . length } existing file(s): ${ skipped . join ( ', ' ) } ` ,
1423+ } ) ;
1424+ } else if ( processed . length > 0 ) {
14251425 req . flash ( 'success' , {
1426- msg : `Successfully ingested ${ processed . length } new file(s): ${ processed . join ( ', ' ) } ` ,
1426+ msg : `Successfully ingested ${ processed . length } file(s): ${ processed . join ( ', ' ) } ` ,
14271427 } ) ;
14281428 } else if ( skipped . length > 0 ) {
14291429 req . flash ( 'info' , {
@@ -1456,9 +1456,9 @@ exports.postRagAsk = async (req, res) => {
14561456 // Get list of ingested files for display
14571457 let ingestedFiles = [ ] ;
14581458 try {
1459- const client = new MongoClient ( process . env . MONGODB_URI , { dbName : 'hackathonstarter_rag' } ) ;
1459+ const client = new MongoClient ( process . env . MONGODB_URI ) ;
14601460 await client . connect ( ) ;
1461- const db = client . db ( 'hackathonstarter_rag' ) ;
1461+ const db = client . db ( ) ;
14621462 const collection = await ensureVectorIndex ( db ) ;
14631463
14641464 ingestedFiles = await collection . distinct ( 'source' ) ;
@@ -1467,7 +1467,7 @@ exports.postRagAsk = async (req, res) => {
14671467 // Setup vector store and embeddings
14681468 const embeddings = new HuggingFaceInferenceEmbeddings ( {
14691469 apiKey : process . env . HUGGINGFACE_KEY ,
1470- model : process . env . HUGGINGFACE_EMBEDING_MODEL || 'BAAI/bge-large-en-v1.5' ,
1470+ model : process . env . HUGGINGFACE_EMBEDING_MODEL ,
14711471 } ) ;
14721472 const vectorStore = new MongoDBAtlasVectorSearch ( embeddings , {
14731473 collection,
0 commit comments