Spaces:
Sleeping
Sleeping
Download backend/src/services/knowledgeBaseService.js from edichat/edi.chat.test: direct link, hf CLI and curl.
- Browser
- Download file 31.3 kB
-
https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/backend/src/services/knowledgeBaseService.js
- Command line
-
hf download hf://spaces/edichat/edi.chat.test/backend/src/services/knowledgeBaseService.js
-
curl -L -o knowledgeBaseService.js https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/backend/src/services/knowledgeBaseService.js
31.3 kB
| const logger = require('../utils/logger'); | |
| const { redisUtils } = require('../utils/redis'); | |
| class KnowledgeBaseService { | |
| constructor() { | |
| this.ugaKnowledgeBase = this.initializeUGAKnowledge(); | |
| this.athensKnowledgeBase = this.initializeAthensKnowledge(); | |
| this.studentLifeKnowledge = this.initializeStudentLifeKnowledge(); | |
| } | |
| initializeUGAKnowledge() { | |
| return { | |
| // University Overview | |
| overview: { | |
| founded: 1785, | |
| type: 'Public Research University', | |
| motto: 'To teach, to serve, and to inquire into the nature of things', | |
| mascot: 'Hairy Dawg (English Bulldog)', | |
| colors: ['Red', 'Black'], | |
| nickname: 'Bulldogs', | |
| enrollment: '39,000+ students', | |
| campusSize: '762 acres', | |
| ranking: 'Top 20 public university', | |
| president: 'Jere Morehead', | |
| established: 'First state-chartered university in the United States' | |
| }, | |
| // Academic Structure | |
| academics: { | |
| colleges: [ | |
| { | |
| name: 'Franklin College of Arts and Sciences', | |
| dean: 'Departmental structure varies', | |
| programs: ['Liberal Arts', 'Sciences', 'Mathematics', 'English', 'History', 'Psychology'], | |
| notable: 'Largest college at UGA' | |
| }, | |
| { | |
| name: 'Terry College of Business', | |
| programs: ['Accounting', 'Finance', 'Management', 'Marketing', 'Real Estate'], | |
| ranking: 'Top-ranked business school', | |
| facilities: ['Correll Hall', 'Brooks Hall'] | |
| }, | |
| { | |
| name: 'College of Engineering', | |
| programs: ['Aerospace', 'Agricultural', 'Biological', 'Chemical', 'Civil', 'Computer Science', 'Electrical', 'Environmental'], | |
| facilities: ['Driftmier Engineering Center', 'Boyd Graduate Studies Research Center'] | |
| }, | |
| { | |
| name: 'College of Education', | |
| programs: ['Elementary Education', 'Secondary Education', 'Special Education', 'Educational Psychology'], | |
| facilities: ['Aderhold Hall', 'River\'s Crossing'] | |
| }, | |
| { | |
| name: 'College of Journalism and Mass Communication', | |
| programs: ['Journalism', 'Advertising', 'Public Relations', 'Digital Media'], | |
| ranking: 'Top journalism school nationally', | |
| facilities: ['Grady College Building'] | |
| }, | |
| { | |
| name: 'College of Agricultural and Environmental Sciences', | |
| programs: ['Agriculture', 'Environmental Science', 'Food Science', 'Landscape Architecture'], | |
| facilities: ['Conner Hall', 'Food Science Building'] | |
| }, | |
| { | |
| name: 'College of Veterinary Medicine', | |
| programs: ['Doctor of Veterinary Medicine', 'Veterinary Technology'], | |
| ranking: 'Top veterinary school', | |
| facilities: ['Veterinary Medicine Complex'] | |
| }, | |
| { | |
| name: 'College of Pharmacy', | |
| programs: ['Doctor of Pharmacy', 'Pharmaceutical Sciences'], | |
| facilities: ['Pharmacy South Building'] | |
| }, | |
| { | |
| name: 'School of Law', | |
| programs: ['Juris Doctor', 'Master of Laws'], | |
| ranking: 'Highly ranked law school', | |
| facilities: ['Hirsch Hall', 'Rusk Hall'] | |
| }, | |
| { | |
| name: 'College of Public Health', | |
| programs: ['Public Health', 'Epidemiology', 'Health Policy'], | |
| facilities: ['Health Sciences Campus'] | |
| }, | |
| { | |
| name: 'School of Social Work', | |
| programs: ['Bachelor of Social Work', 'Master of Social Work'], | |
| facilities: ['Tucker Hall'] | |
| }, | |
| { | |
| name: 'College of Family and Consumer Sciences', | |
| programs: ['Human Development', 'Nutrition', 'Fashion Merchandising'], | |
| facilities: ['Dawson Hall'] | |
| } | |
| ], | |
| semesterSystem: { | |
| fall: 'August - December', | |
| spring: 'January - May', | |
| summer: 'May - August', | |
| maymester: 'May intensive session', | |
| winterSession: 'December/January short courses' | |
| }, | |
| graduationRequirements: { | |
| undergraduate: { | |
| totalHours: 120, | |
| coreRequirements: 'Areas A-F (42 hours)', | |
| majorRequirements: 'Varies by program (30-60 hours)', | |
| electiveHours: 'Remaining hours', | |
| residencyRequirement: '30 hours at UGA', | |
| gpaRequirement: '2.0 minimum' | |
| } | |
| }, | |
| honors: { | |
| honorsProgram: 'Honors Program for high-achieving students', | |
| foundationFellows: 'Premier scholarship program', | |
| ramseyScholars: 'Leadership and service scholarship', | |
| bernardRamseyHonorsScholarship: 'Full-ride academic scholarship' | |
| } | |
| }, | |
| // Campus Facilities | |
| facilities: { | |
| libraries: [ | |
| { | |
| name: 'University of Georgia Libraries', | |
| mainLibrary: 'Main Library', | |
| specialLibraries: [ | |
| 'Miller Learning Center (MLC)', | |
| 'Science Library', | |
| 'Law Library', | |
| 'Veterinary Medicine Library', | |
| 'Map and Government Information Library' | |
| ], | |
| services: ['Research assistance', 'Interlibrary loans', 'Study spaces', 'Computer labs', 'Printing services'], | |
| hours: 'Varies by location, some 24/7 during semester' | |
| } | |
| ], | |
| recreation: { | |
| ramseyCenter: { | |
| name: 'Ramsey Student Center', | |
| facilities: [ | |
| 'Fitness equipment and weights', | |
| '25-yard swimming pool', | |
| 'Basketball courts', | |
| 'Racquetball courts', | |
| 'Rock climbing wall', | |
| 'Group fitness studios', | |
| 'Outdoor recreation equipment rental' | |
| ], | |
| hours: 'M-F: 5:30 AM - 12:00 AM, weekends vary', | |
| programs: ['Group fitness classes', 'Intramural sports', 'Personal training'] | |
| }, | |
| outdoorRecreation: { | |
| programs: ['Hiking trips', 'Camping', 'Kayaking', 'Rock climbing'], | |
| equipment: 'Rental equipment available' | |
| } | |
| }, | |
| studentCenters: { | |
| tasteCenter: { | |
| name: 'Tate Student Center', | |
| services: ['Dining', 'Bookstore', 'Student organizations', 'Event spaces'], | |
| dining: ['Food court', 'Restaurants', 'Starbucks'] | |
| } | |
| }, | |
| technology: { | |
| wifi: 'UGA-WiFi available campus-wide', | |
| computerLabs: 'Available in MLC, libraries, and academic buildings', | |
| printing: 'PawPrints system for printing', | |
| software: 'Free software available to students' | |
| } | |
| }, | |
| // Athletics | |
| athletics: { | |
| conference: 'Southeastern Conference (SEC)', | |
| colors: 'Red and Black', | |
| mascot: 'Uga (English Bulldog lineage)', | |
| fightSong: 'Hail to Georgia', | |
| venues: { | |
| football: 'Sanford Stadium (capacity: 92,746)', | |
| basketball: 'Stegeman Coliseum', | |
| baseball: 'Foley Field', | |
| soccer: 'Turner Soccer Complex', | |
| tennis: 'Dan Magill Tennis Complex', | |
| golf: 'University of Georgia Golf Course' | |
| }, | |
| traditions: [ | |
| 'The Dawg Walk', | |
| 'Calling the Dawgs', | |
| 'Between the Hedges (Sanford Stadium)', | |
| 'The Georgia-Florida game (World\'s Largest Outdoor Cocktail Party)', | |
| 'Clean, Old-Fashioned Hate (Georgia vs. Georgia Tech)' | |
| ], | |
| championships: { | |
| football: ['1942', '1980', '2021 National Champions'], | |
| baseball: 'Multiple College World Series appearances', | |
| gymnastics: 'Multiple national championships', | |
| tennis: 'Multiple national championships' | |
| } | |
| }, | |
| // Student Organizations | |
| studentLife: { | |
| greekLife: { | |
| ifcChapters: 30, | |
| panhellenicChapters: 25, | |
| nphcChapters: 9, | |
| multiculturalChapters: 15, | |
| participation: 'About 25% of students' | |
| }, | |
| studentOrganizations: { | |
| total: '600+ organizations', | |
| categories: [ | |
| 'Academic and Professional', | |
| 'Cultural and Ethnic', | |
| 'Religious and Spiritual', | |
| 'Service and Philanthropy', | |
| 'Sports and Recreation', | |
| 'Arts and Performance', | |
| 'Special Interest', | |
| 'Student Government' | |
| ] | |
| }, | |
| traditions: [ | |
| 'Ring Ceremony', | |
| 'Homecoming', | |
| 'SpringFest', | |
| 'Dawg Days (orientation)', | |
| 'Arch ceremonies' | |
| ] | |
| }, | |
| // Notable Programs | |
| notablePrograms: { | |
| studyAbroad: { | |
| programs: '100+ programs in 50+ countries', | |
| notable: ['Costa Rica', 'Oxford', 'Cortona Italy', 'Ramallah'] | |
| }, | |
| research: { | |
| status: 'R1: Doctoral Universities – Very High Research Activity', | |
| opportunities: 'Undergraduate research opportunities available', | |
| centers: ['Center for Undergraduate Research Opportunities (CURO)'] | |
| }, | |
| sustainability: { | |
| initiatives: ['Campus sustainability', 'LEED certified buildings', 'Recycling programs'], | |
| rating: 'Green campus designation' | |
| } | |
| }, | |
| // Campus Landmarks | |
| landmarks: [ | |
| { | |
| name: 'The Arch', | |
| significance: 'Iconic entrance to North Campus', | |
| tradition: 'Students traditionally don\'t walk under it until graduation' | |
| }, | |
| { | |
| name: 'Chapel Bell', | |
| significance: 'Historic bell tower', | |
| tradition: 'Rings after football victories' | |
| }, | |
| { | |
| name: 'Sanford Stadium', | |
| significance: '92,746 capacity football stadium', | |
| nickname: 'Between the Hedges' | |
| }, | |
| { | |
| name: 'North Campus', | |
| significance: 'Historic heart of campus', | |
| features: ['The Arch', 'Old College', 'Chapel'] | |
| }, | |
| { | |
| name: 'State Botanical Garden', | |
| significance: '313-acre botanical garden', | |
| features: ['Visitor Center', 'Conservatory', 'Nature trails'] | |
| } | |
| ], | |
| // Academic Calendar Key Dates | |
| importantDates: { | |
| fall2024: { | |
| orientation: 'August 12-16', | |
| classesBegin: 'August 19', | |
| laborDay: 'September 2 (no classes)', | |
| fallBreak: 'October 10-11', | |
| thanksgiving: 'November 25-29', | |
| classesEnd: 'December 6', | |
| finalsWeek: 'December 9-16', | |
| commencement: 'December 20' | |
| }, | |
| spring2025: { | |
| classesBegin: 'January 13', | |
| mlkDay: 'January 20 (no classes)', | |
| springBreak: 'March 10-14', | |
| classesEnd: 'April 25', | |
| finalsWeek: 'April 28 - May 5', | |
| commencement: 'May 9-10' | |
| } | |
| } | |
| }; | |
| } | |
| initializeAthensKnowledge() { | |
| return { | |
| // City Overview | |
| overview: { | |
| location: 'Northeast Georgia, 70 miles northeast of Atlanta', | |
| population: '127,000 (city), 215,000 (metro area)', | |
| established: 1806, | |
| nickname: 'Classic City', | |
| climate: 'Humid subtropical', | |
| geography: 'Rolling hills, part of Piedmont region' | |
| }, | |
| // Neighborhoods and Areas | |
| neighborhoods: { | |
| downtown: { | |
| description: 'Historic downtown area with shops, restaurants, and entertainment', | |
| landmarks: ['Georgia Theatre', 'Classic Center', 'City Hall'], | |
| nightlife: ['Bars', 'Live music venues', 'Restaurants'], | |
| events: ['AthFest', 'Twilight Criterium', 'First Friday'] | |
| }, | |
| northside: { | |
| description: 'Upscale residential area', | |
| features: ['Historic homes', 'Tree-lined streets', 'Close to campus'] | |
| }, | |
| eastside: { | |
| description: 'Diverse area with mix of students and locals', | |
| features: ['Affordable housing', 'Local businesses', 'Easy campus access'] | |
| }, | |
| westside: { | |
| description: 'Growing area with new developments', | |
| features: ['Shopping centers', 'Chain restaurants', 'Apartments'] | |
| }, | |
| southside: { | |
| description: 'Mix of residential and commercial', | |
| features: ['Shopping', 'Restaurants', 'Business district'] | |
| }, | |
| fivePoints: { | |
| description: 'Popular student area', | |
| features: ['Bars', 'Restaurants', 'Student housing', 'Late-night food'] | |
| }, | |
| normaltown: { | |
| description: 'Hip neighborhood east of downtown', | |
| features: ['Local shops', 'Restaurants', 'Music venues', 'Art galleries'] | |
| } | |
| }, | |
| // Transportation | |
| transportation: { | |
| publicTransit: { | |
| athensTransit: { | |
| routes: '25 bus routes', | |
| campusTransit: 'Free campus bus system', | |
| hours: 'Varies by route', | |
| fare: 'Free for UGA students with ID' | |
| } | |
| }, | |
| parking: { | |
| downtown: 'Limited street parking, paid parking decks', | |
| campus: 'Permit required, various zones', | |
| tips: 'Use transit when possible, carpool' | |
| }, | |
| biking: { | |
| infrastructure: 'Growing bike lane network', | |
| campusPolicy: 'Bikes allowed on campus with registration', | |
| rentalOptions: 'Bike rental programs available' | |
| }, | |
| walkability: 'Very walkable downtown and campus areas' | |
| }, | |
| // Dining and Food | |
| dining: { | |
| categories: { | |
| southern: ['The National', 'Mama\'s Boy', 'Weaver D\'s'], | |
| pizza: ['Mellow Mushroom', 'Your Pie', 'Little Italy'], | |
| mexican: ['Tlaloc', 'Cali N Tito\'s', 'Taco Stand'], | |
| asian: ['Tsing Tao', 'Golden Dragon', 'Sushi Huku'], | |
| coffee: ['Jittery Joe\'s', 'Walker\'s Coffee', 'Starbucks locations'], | |
| barbecue: ['Fresh Air BBQ', 'Smokin\' Pig'], | |
| breakfast: ['Mama\'s Boy', 'The Grit', 'Flying Biscuit'], | |
| lateNight: ['Gumby\'s Pizza', 'Cookout', 'Taco Bell'] | |
| }, | |
| studentFavorites: [ | |
| 'Mama\'s Boy (brunch)', | |
| 'The Grit (vegetarian)', | |
| 'Mellow Mushroom (pizza)', | |
| 'Jittery Joe\'s (coffee)', | |
| 'Cookout (late night)' | |
| ], | |
| campusEating: 'Multiple dining halls and food courts on campus' | |
| }, | |
| // Entertainment and Nightlife | |
| entertainment: { | |
| venues: { | |
| music: [ | |
| 'Georgia Theatre (historic venue)', | |
| 'The Foundry (live music)', | |
| '40 Watt Club (indie music)', | |
| 'Normaltown Hall', | |
| 'Flicker Theatre & Bar' | |
| ], | |
| bars: [ | |
| 'Creature Comforts Brewing', | |
| 'The World Famous', | |
| 'Copper Creek', | |
| 'Allgood Lounge', | |
| 'Cloud Bar' | |
| ], | |
| activities: [ | |
| 'State Botanical Garden', | |
| 'Sandy Creek Park', | |
| 'Bear Hollow Zoo', | |
| 'North Oconee River Greenway' | |
| ] | |
| }, | |
| events: { | |
| athFest: 'Annual music and arts festival', | |
| twilightCriterium: 'Annual bike race downtown', | |
| wildRumpus: 'Halloween parade', | |
| firstFriday: 'Monthly downtown event' | |
| } | |
| }, | |
| // Shopping | |
| shopping: { | |
| malls: ['Beechwood Promenade', 'The Georgia Square Mall'], | |
| downtown: ['Local boutiques', 'Record stores', 'Gift shops'], | |
| studentNecessities: ['Walmart', 'Target', 'Publix', 'Kroger'], | |
| bookstores: ['UGA Bookstore', 'Jackson Street Books', 'Avid Bookshop'] | |
| }, | |
| // Weather and Climate | |
| weather: { | |
| spring: 'Mild, 60-75°F, occasional rain', | |
| summer: 'Hot and humid, 75-85°F, thunderstorms', | |
| fall: 'Pleasant, 50-70°F, perfect for football', | |
| winter: 'Mild, 35-55°F, occasional snow', | |
| tips: [ | |
| 'Bring umbrella for sudden showers', | |
| 'Layer clothing for temperature changes', | |
| 'Summer can be very humid' | |
| ] | |
| }, | |
| // Healthcare | |
| healthcare: { | |
| hospitals: ['Athens Regional Medical Center', 'St. Mary\'s Sacred Heart Hospital'], | |
| campusHealth: ['University Health Center', 'Counseling services'], | |
| urgentCare: 'Multiple urgent care facilities', | |
| pharmacies: ['CVS', 'Walgreens', 'Campus pharmacy'] | |
| }, | |
| // Local Culture | |
| culture: { | |
| music: { | |
| heritage: 'Birthplace of R.E.M. and B-52s', | |
| scene: 'Vibrant indie and alternative music scene', | |
| venues: 'Multiple live music venues' | |
| }, | |
| arts: { | |
| galleries: ['Lyndon House Arts Center', 'Various downtown galleries'], | |
| theater: ['Theatre UGA', 'Town & Gown Theatre'], | |
| festivals: ['AthFest', 'Human Rights Festival'] | |
| }, | |
| sports: { | |
| professional: 'No major pro teams (Atlanta teams popular)', | |
| college: 'UGA Bulldogs dominate local sports culture', | |
| recreation: 'Intramural and club sports popular' | |
| } | |
| } | |
| }; | |
| } | |
| initializeStudentLifeKnowledge() { | |
| return { | |
| // Housing Options | |
| housing: { | |
| onCampus: { | |
| traditional: [ | |
| 'Brumby Hall', 'Creswell Hall', 'Russell Hall', | |
| 'Church Hall', 'Oglethorpe House', 'Lipscomb Hall' | |
| ], | |
| suiteStyle: [ | |
| 'East Campus Village', 'Reed Hall', 'Boggs Hall' | |
| ], | |
| apartmentStyle: [ | |
| 'University Village', 'Village Summit' | |
| ], | |
| special: [ | |
| 'Language immersion floors', | |
| 'Honors housing', | |
| 'Living-learning communities' | |
| ] | |
| }, | |
| offCampus: { | |
| popular: [ | |
| 'The Standard', 'The Connection', 'University Courtyard', | |
| 'Campus Lodge', 'Athens Green', 'Reserve at Athens' | |
| ], | |
| neighborhoods: [ | |
| 'Five Points area (party scene)', | |
| 'Boulevard area (close to campus)', | |
| 'Baxter area (quieter)' | |
| ], | |
| tips: [ | |
| 'Start looking early for good options', | |
| 'Consider distance to campus', | |
| 'Budget for utilities and parking' | |
| ] | |
| } | |
| }, | |
| // Academic Life | |
| academicLife: { | |
| studySpots: { | |
| libraries: [ | |
| 'Miller Learning Center (24/7 during semester)', | |
| 'Main Library (quiet study)', | |
| 'Science Library (group study)' | |
| ], | |
| campus: [ | |
| 'Tate Student Center', | |
| 'Memorial Hall', | |
| 'Various academic buildings' | |
| ], | |
| offCampus: [ | |
| 'Jittery Joe\'s', | |
| 'Walker\'s Coffee', | |
| 'Various cafes downtown' | |
| ] | |
| }, | |
| academicSupport: { | |
| tutoring: 'Free tutoring in DAWGhaus', | |
| writingCenter: 'Free writing assistance', | |
| advisors: 'Academic advisors in each college', | |
| disabilities: 'Disability Resource Center', | |
| mentalHealth: 'Counseling and Psychological Services' | |
| } | |
| }, | |
| // Social Life | |
| socialLife: { | |
| greekLife: { | |
| participation: 'About 25% of students', | |
| rush: 'Fall and spring rush periods', | |
| benefits: 'Social connections, leadership, philanthropy', | |
| costs: 'Dues vary by chapter ($1000-3000+ per semester)' | |
| }, | |
| clubs: { | |
| academic: 'Professional organizations for each major', | |
| special: 'Chess club, outdoor club, gaming groups', | |
| cultural: 'International student organizations', | |
| service: 'Habitat for Humanity, various volunteer groups', | |
| sports: 'Intramural sports, club teams' | |
| }, | |
| dating: { | |
| apps: ['Popular dating apps used'], | |
| events: 'Mixers, formals, campus events', | |
| culture: 'Generally friendly dating scene' | |
| } | |
| }, | |
| // Campus Traditions | |
| traditions: { | |
| academic: { | |
| orientation: 'Dawg Days for new students', | |
| ringCeremony: 'Junior year tradition', | |
| graduation: 'Walking under the Arch' | |
| }, | |
| athletic: { | |
| gamedays: 'Tailgating culture, red and black everywhere', | |
| chants: 'Calling the Dawgs, Go Dawgs Sic \'Em', | |
| rivals: 'Georgia Tech (Clean Old-Fashioned Hate), Auburn, Florida' | |
| }, | |
| social: { | |
| springfest: 'Annual spring concert and festival', | |
| homecoming: 'Week of events and football game', | |
| halloween: 'Wild Rumpus parade downtown' | |
| } | |
| }, | |
| // Practical Information | |
| practicalInfo: { | |
| banking: { | |
| campus: 'BB&T branch on campus', | |
| local: 'Various banks downtown and around town', | |
| atms: 'Available throughout campus and town' | |
| }, | |
| employment: { | |
| onCampus: 'Work-study jobs, student assistant positions', | |
| offCampus: 'Restaurants, retail, tutoring opportunities', | |
| internships: 'Career Center helps with placement' | |
| }, | |
| safety: { | |
| campus: 'UGA Police patrol 24/7', | |
| escort: 'Campus escort service available', | |
| emergency: 'Blue light emergency phones throughout campus', | |
| downtown: 'Generally safe but use common sense' | |
| }, | |
| technology: { | |
| internet: 'High-speed WiFi throughout campus', | |
| computers: 'Computer labs and printing available', | |
| software: 'Free software for students', | |
| support: 'EITS provides tech support' | |
| } | |
| }, | |
| // Seasonal Activities | |
| seasonalActivities: { | |
| fall: { | |
| activities: [ | |
| 'Football games and tailgating', | |
| 'Homecoming events', | |
| 'Fall festivals', | |
| 'Perfect weather for outdoor activities' | |
| ] | |
| }, | |
| winter: { | |
| activities: [ | |
| 'Basketball games', | |
| 'Indoor activities', | |
| 'Holiday events', | |
| 'Study abroad fair' | |
| ] | |
| }, | |
| spring: { | |
| activities: [ | |
| 'SpringFest', | |
| 'Baseball games', | |
| 'Outdoor recreation', | |
| 'Graduation events' | |
| ] | |
| }, | |
| summer: { | |
| activities: [ | |
| 'Summer classes', | |
| 'Internships', | |
| 'Research opportunities', | |
| 'Fewer crowds on campus' | |
| ] | |
| } | |
| }, | |
| // Health and Wellness | |
| healthWellness: { | |
| physicalHealth: { | |
| campusHealth: 'University Health Center', | |
| fitness: 'Ramsey Student Center', | |
| nutrition: 'Healthy dining options available', | |
| recreation: 'Intramural sports, outdoor programs' | |
| }, | |
| mentalHealth: { | |
| counseling: 'Free counseling services', | |
| support: 'Support groups available', | |
| crisis: '24/7 crisis support available', | |
| stress: 'Stress management programs' | |
| } | |
| } | |
| }; | |
| } | |
| // Query methods | |
| async queryKnowledgeBase(query, category = 'all') { | |
| try { | |
| const cacheKey = `kb:${category}:${query.toLowerCase().replace(/\s+/g, '_')}`; | |
| // Check cache first | |
| const cached = await redisUtils.get(cacheKey); | |
| if (cached) { | |
| return cached; | |
| } | |
| const results = []; | |
| const queryLower = query.toLowerCase(); | |
| // Search UGA knowledge | |
| if (category === 'all' || category === 'uga') { | |
| const ugaResults = this.searchUGAKnowledge(queryLower); | |
| results.push(...ugaResults); | |
| } | |
| // Search Athens knowledge | |
| if (category === 'all' || category === 'athens') { | |
| const athensResults = this.searchAthensKnowledge(queryLower); | |
| results.push(...athensResults); | |
| } | |
| // Search student life knowledge | |
| if (category === 'all' || category === 'studentlife') { | |
| const studentResults = this.searchStudentLifeKnowledge(queryLower); | |
| results.push(...studentResults); | |
| } | |
| // Score and rank results | |
| const scoredResults = this.scoreResults(results, queryLower); | |
| const topResults = scoredResults.slice(0, 5); | |
| // Cache results for 30 minutes | |
| await redisUtils.setex(cacheKey, 1800, topResults); | |
| return topResults; | |
| } catch (error) { | |
| logger.error('Knowledge base query error:', error); | |
| return []; | |
| } | |
| } | |
| searchUGAKnowledge(query) { | |
| const results = []; | |
| // Search through different sections | |
| this.searchSection(this.ugaKnowledgeBase.overview, query, 'UGA Overview', results); | |
| this.searchSection(this.ugaKnowledgeBase.academics, query, 'Academics', results); | |
| this.searchSection(this.ugaKnowledgeBase.facilities, query, 'Campus Facilities', results); | |
| this.searchSection(this.ugaKnowledgeBase.athletics, query, 'Athletics', results); | |
| this.searchSection(this.ugaKnowledgeBase.studentLife, query, 'Student Life', results); | |
| return results; | |
| } | |
| searchAthensKnowledge(query) { | |
| const results = []; | |
| this.searchSection(this.athensKnowledgeBase.neighborhoods, query, 'Athens Neighborhoods', results); | |
| this.searchSection(this.athensKnowledgeBase.dining, query, 'Athens Dining', results); | |
| this.searchSection(this.athensKnowledgeBase.entertainment, query, 'Athens Entertainment', results); | |
| this.searchSection(this.athensKnowledgeBase.transportation, query, 'Athens Transportation', results); | |
| return results; | |
| } | |
| searchStudentLifeKnowledge(query) { | |
| const results = []; | |
| this.searchSection(this.studentLifeKnowledge.housing, query, 'Student Housing', results); | |
| this.searchSection(this.studentLifeKnowledge.academicLife, query, 'Academic Life', results); | |
| this.searchSection(this.studentLifeKnowledge.socialLife, query, 'Social Life', results); | |
| this.searchSection(this.studentLifeKnowledge.practicalInfo, query, 'Practical Information', results); | |
| return results; | |
| } | |
| searchSection(section, query, sectionName, results) { | |
| const searchInObject = (obj, path = '') => { | |
| for (const [key, value] of Object.entries(obj)) { | |
| const currentPath = path ? `${path}.${key}` : key; | |
| if (typeof value === 'string') { | |
| if (value.toLowerCase().includes(query) || key.toLowerCase().includes(query)) { | |
| results.push({ | |
| section: sectionName, | |
| path: currentPath, | |
| content: value, | |
| type: 'text', | |
| relevance: this.calculateRelevance(query, value + ' ' + key) | |
| }); | |
| } | |
| } else if (Array.isArray(value)) { | |
| value.forEach((item, index) => { | |
| if (typeof item === 'string') { | |
| if (item.toLowerCase().includes(query) || key.toLowerCase().includes(query)) { | |
| results.push({ | |
| section: sectionName, | |
| path: `${currentPath}[${index}]`, | |
| content: item, | |
| type: 'list_item', | |
| relevance: this.calculateRelevance(query, item + ' ' + key) | |
| }); | |
| } | |
| } else if (typeof item === 'object') { | |
| searchInObject(item, `${currentPath}[${index}]`); | |
| } | |
| }); | |
| } else if (typeof value === 'object' && value !== null) { | |
| searchInObject(value, currentPath); | |
| } | |
| } | |
| }; | |
| searchInObject(section); | |
| } | |
| calculateRelevance(query, text) { | |
| const queryWords = query.toLowerCase().split(' '); | |
| const textLower = text.toLowerCase(); | |
| let score = 0; | |
| queryWords.forEach(word => { | |
| if (textLower.includes(word)) { | |
| // Exact word match gets higher score | |
| const regex = new RegExp(`\\b${word}\\b`, 'gi'); | |
| const exactMatches = (textLower.match(regex) || []).length; | |
| score += exactMatches * 2; | |
| // Partial matches get lower score | |
| const partialMatches = textLower.split(word).length - 1; | |
| score += (partialMatches - exactMatches) * 0.5; | |
| } | |
| }); | |
| // Boost score for shorter text (more relevant) | |
| score = score * (1 + (100 / Math.max(text.length, 100))); | |
| return score; | |
| } | |
| scoreResults(results, query) { | |
| return results | |
| .sort((a, b) => b.relevance - a.relevance) | |
| .map(result => ({ | |
| ...result, | |
| snippet: this.createSnippet(result.content, query) | |
| })); | |
| } | |
| createSnippet(text, query, maxLength = 150) { | |
| const queryIndex = text.toLowerCase().indexOf(query.toLowerCase()); | |
| if (queryIndex === -1) { | |
| return text.length > maxLength ? text.substring(0, maxLength) + '...' : text; | |
| } | |
| const start = Math.max(0, queryIndex - 50); | |
| const end = Math.min(text.length, queryIndex + query.length + 50); | |
| let snippet = text.substring(start, end); | |
| if (start > 0) snippet = '...' + snippet; | |
| if (end < text.length) snippet = snippet + '...'; | |
| return snippet; | |
| } | |
| // Get contextual information based on user profile | |
| getContextualInfo(user, topic) { | |
| const context = { | |
| userRole: user.role, | |
| userCollege: user.college, | |
| userMajor: user.major, | |
| userClassification: user.classification | |
| }; | |
| // Provide personalized information based on user context | |
| switch (topic) { | |
| case 'housing': | |
| return this.getHousingContext(context); | |
| case 'dining': | |
| return this.getDiningContext(context); | |
| case 'academics': | |
| return this.getAcademicContext(context); | |
| default: | |
| return this.getGeneralContext(context); | |
| } | |
| } | |
| getHousingContext(context) { | |
| if (context.userClassification === 'freshman') { | |
| return { | |
| recommendation: 'Traditional residence halls recommended for first-year students', | |
| options: ['Brumby Hall', 'Creswell Hall', 'Russell Hall'], | |
| tips: ['Apply early', 'Consider living-learning communities', 'Traditional halls help with socialization'] | |
| }; | |
| } | |
| return { | |
| recommendation: 'Various options available based on preference and budget', | |
| options: ['On-campus apartments', 'Off-campus housing', 'Greek housing'] | |
| }; | |
| } | |
| getDiningContext(context) { | |
| return { | |
| campusOptions: 'Multiple dining halls and food courts', | |
| localFavorites: ['Mama\'s Boy', 'The Grit', 'Mellow Mushroom'], | |
| budgetTips: ['Use meal plan efficiently', 'Cook in apartment kitchens', 'Look for student discounts'] | |
| }; | |
| } | |
| getAcademicContext(context) { | |
| const academicInfo = { | |
| general: 'UGA offers comprehensive academic support services' | |
| }; | |
| if (context.userCollege) { | |
| academicInfo.collegeSpecific = `Information specific to ${context.userCollege}`; | |
| } | |
| if (context.userMajor) { | |
| academicInfo.majorSpecific = `Resources for ${context.userMajor} students`; | |
| } | |
| return academicInfo; | |
| } | |
| getGeneralContext(context) { | |
| return { | |
| campusLife: 'Rich campus life with 600+ student organizations', | |
| location: 'Athens, Georgia - vibrant college town', | |
| athletics: 'SEC athletics, strong Bulldog pride' | |
| }; | |
| } | |
| } | |
| module.exports = new KnowledgeBaseService(); |