File tree Expand file tree Collapse file tree 5 files changed +25
-12
lines changed
Expand file tree Collapse file tree 5 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -8,15 +8,16 @@ const {
88 MONGODB_DATABASE ,
99 MONGODB_DOCKER_PORT ,
1010 // Traditional environment variables
11- DB_HOST = 'localhost' ,
11+ DB_HOST ,
1212 DB_PORT = 27017 ,
1313 DB_NAME = 'pa-wildflower-selector' ,
1414 DB_USER ,
1515 DB_PASSWORD
1616} = process . env ;
1717
1818// Use Docker variables if available, fall back to traditional ones
19- const host = DB_HOST || 'mongodb' ; // Use 'mongodb' as default in Docker
19+ // Default to 'mongodb' (Docker mode) unless DB_HOST is explicitly 'localhost'
20+ const host = DB_HOST === 'localhost' ? 'localhost' : ( DB_HOST || 'mongodb' ) ;
2021const port = MONGODB_DOCKER_PORT || DB_PORT ;
2122const dbName = MONGODB_DATABASE || DB_NAME ;
2223const user = MONGODB_USER || DB_USER ;
Original file line number Diff line number Diff line change 1- const { pipeline } = require ( '@xenova/transformers' ) ;
2-
3- // Cache the model to avoid reloading
1+ // Cache the transformers module and model to avoid reloading
2+ let transformersModule = null ;
43let embeddingModel = null ;
54
5+ /**
6+ * Get the transformers module using dynamic import (required for ES modules)
7+ */
8+ async function getTransformersModule ( ) {
9+ if ( ! transformersModule ) {
10+ transformersModule = await import ( '@xenova/transformers' ) ;
11+ }
12+ return transformersModule ;
13+ }
14+
615/**
716 * Initialize the embedding model
817 * Uses a lightweight sentence transformer model optimized for search
918 */
1019async function getEmbeddingModel ( ) {
1120 if ( ! embeddingModel ) {
1221 console . log ( 'Loading embedding model...' ) ;
22+ const { pipeline } = await getTransformersModule ( ) ;
1323 embeddingModel = await pipeline (
1424 'feature-extraction' ,
1525 'Xenova/all-MiniLM-L6-v2' // Lightweight model, ~80MB, good for semantic search
Original file line number Diff line number Diff line change @@ -16,15 +16,16 @@ const {
1616 MONGODB_DATABASE ,
1717 MONGODB_DOCKER_PORT ,
1818 // Traditional environment variables
19- DB_HOST = 'localhost' ,
19+ DB_HOST ,
2020 DB_PORT = 27017 ,
2121 DB_NAME = 'pa-wildflower-selector' ,
2222 DB_USER ,
2323 DB_PASSWORD
2424} = process . env ;
2525
2626// Use Docker variables if available, fall back to traditional ones
27- const host = DB_HOST || 'mongodb' ; // Use 'mongodb' as default in Docker
27+ // Default to 'mongodb' (Docker mode) unless DB_HOST is explicitly 'localhost'
28+ const host = DB_HOST === 'localhost' ? 'localhost' : ( DB_HOST || 'mongodb' ) ;
2829const port = MONGODB_DOCKER_PORT || DB_PORT ;
2930const dbName = MONGODB_DATABASE || DB_NAME ;
3031const user = MONGODB_USER || DB_USER ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const requiredEnvVars = [
2020
2121// MongoDB connection variables
2222const {
23- DB_HOST = 'localhost' ,
23+ DB_HOST ,
2424 MONGODB_USER ,
2525 MONGODB_PASSWORD ,
2626 MONGODB_DATABASE ,
@@ -31,8 +31,8 @@ const {
3131 DB_PASSWORD
3232} = process . env ;
3333
34- // Detect mode
35- const host = DB_HOST || 'mongodb' ;
34+ // Detect mode - default to Docker unless explicitly localhost
35+ const host = DB_HOST === 'localhost' ? 'localhost' : ( DB_HOST || 'mongodb' ) ;
3636const isDockerMode = host === 'mongodb' ;
3737const mode = isDockerMode ? 'Docker' : 'Local' ;
3838
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ const {
2222 LINODE_BUCKET_NAME ,
2323 LINODE_ENDPOINT_URL = 'https://us-east-1.linodeobjects.com' ,
2424 // MongoDB connection settings
25- DB_HOST = 'localhost' ,
25+ DB_HOST ,
2626 DB_PORT = 27017 ,
2727 MONGODB_USER ,
2828 MONGODB_PASSWORD ,
@@ -40,7 +40,8 @@ if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !LINODE_BUCKET_NAME) {
4040}
4141
4242// MongoDB connection settings
43- const host = DB_HOST ;
43+ // Default to 'mongodb' (Docker mode) unless DB_HOST is explicitly 'localhost'
44+ const host = DB_HOST === 'localhost' ? 'localhost' : ( DB_HOST || 'mongodb' ) ;
4445const port = MONGODB_DOCKER_PORT || DB_PORT ;
4546const user = MONGODB_USER || DB_USER ;
4647const password = MONGODB_PASSWORD || DB_PASSWORD ;
You can’t perform that action at this time.
0 commit comments