Skip to content

Commit 202e836

Browse files
committed
Fix RAG accuracy issues and update personal information
1 parent 65cdc37 commit 202e836

File tree

7 files changed

+350
-274
lines changed

7 files changed

+350
-274
lines changed

backend/app.py

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,49 +57,91 @@ def chat():
5757
'success': False
5858
}), 500
5959

60-
# Use RAG system to search for relevant context
60+
# Get personal information for use in prompts
61+
personal_info = rag_system.get_personal_info()
62+
63+
# --- Step 1: Get Profile Summary for Initial Context ---
64+
profile_summary = rag_system.get_summary_document()
65+
66+
# --- Step 2: Create a Refined Search Query using the LLM ---
67+
query_refiner_prompt = f"""
68+
You are a world-class AI research assistant. Your task is to refine a user's question into a highly effective search query for a vector database.
69+
The user is asking about a person named {personal_info['name']}.
70+
Here is a high-level summary of their profile:
71+
---
72+
{profile_summary}
73+
---
74+
Based on this summary and the user's original question, generate a concise and focused search query.
75+
The query should be a statement or a question that is likely to find the most relevant and specific details in the knowledge base.
76+
For example, if the user asks "tell me about your projects", a good refined query might be "Detailed descriptions of projects like AI and Education, Boston Police Department Budget Analysis, and Machine-Vision Based Assistance System".
77+
Do not answer the user's question, only generate the search query.
78+
79+
User's Original Question: "{message}"
80+
Refined Search Query:
81+
"""
82+
6183
try:
62-
relevant_context = rag_system.search_relevant_context(message, k=3)
63-
print(f"🔍 Retrieved {len(relevant_context.split('Relevant Information'))} relevant contexts")
84+
query_refiner_response = client.chat.completions.create(
85+
model="gpt-4o-mini",
86+
messages=[{"role": "system", "content": query_refiner_prompt}],
87+
temperature=0,
88+
max_tokens=100
89+
)
90+
refined_query = query_refiner_response.choices[0].message.content.strip()
91+
print(f"🧠 Refined Search Query: {refined_query}")
6492
except Exception as e:
65-
print(f"⚠️ RAG search failed: {e}")
66-
relevant_context = "Unable to retrieve relevant information"
67-
68-
# Get personal information
69-
personal_info = rag_system.get_personal_info()
93+
print(f"⚠️ Query refinement failed: {e}. Falling back to original query.")
94+
refined_query = message
95+
96+
# --- Step 3: Use the Refined Query to Search for Detailed Context ---
97+
try:
98+
relevant_context = rag_system.search_relevant_context(refined_query, k=4)
99+
print("Retrieved relevant context: ", relevant_context)
100+
except Exception as e:
101+
print(f"⚠️ RAG search failed with refined query: {e}")
102+
relevant_context = "Unable to retrieve relevant information from the knowledge base."
70103

71-
# Build system prompt
72-
system_prompt = f"""You are {personal_info['name']}'s AI assistant. Answer questions about {personal_info['name']} based on the following relevant information retrieved from the knowledge base:
104+
# --- Step 4: Generate the Final Answer ---
105+
final_answer_prompt = f"""You are {personal_info['name']}'s helpful and professional AI assistant.
106+
Your goal is to provide a comprehensive and accurate answer based on the provided information.
107+
108+
First, here is a high-level summary of {personal_info['name']}'s profile for your general understanding:
109+
<SUMMARY>
110+
{profile_summary}
111+
</SUMMARY>
112+
113+
Now, here is the user's question and the specific, detailed information retrieved from the knowledge base to help you answer it:
114+
<USER_QUESTION>
115+
{message}
116+
</USER_QUESTION>
73117
74-
RELEVANT CONTEXT:
118+
<DETAILED_CONTEXT>
75119
{relevant_context}
120+
</DETAILED_CONTEXT>
76121
77122
INSTRUCTIONS:
78-
- Answer questions based on the relevant context above
79-
- If the context doesn't contain enough information, acknowledge the limitation
80-
- Keep responses conversational, helpful, and professional
81-
- Provide specific details from the context when relevant
82-
- If asked about something not covered in the context, offer related information you do have
83-
- Always respond in the same language as the user's question
123+
- Synthesize the information from both the SUMMARY and the DETAILED_CONTEXT to formulate your final answer.
124+
- Answer the user's question directly and accurately based *only* on the information provided.
125+
- If the detailed context does not contain the answer, you can rely on the summary. If neither contains the answer, state that you don't have enough information.
126+
- Always respond in the same language as the user's question.
84127
"""
85128

86-
# Call OpenAI API
87-
response = client.chat.completions.create(
129+
# Call OpenAI API for the final answer
130+
final_response = client.chat.completions.create(
88131
model="gpt-4o-mini",
89132
messages=[
90-
{"role": "system", "content": system_prompt},
91-
{"role": "user", "content": message}
133+
{"role": "system", "content": final_answer_prompt}
92134
],
93-
temperature=0.7,
94-
max_tokens=500,
135+
temperature=0.5,
136+
max_tokens=1000,
95137
)
96138

97-
ai_response = response.choices[0].message.content
139+
ai_response = final_response.choices[0].message.content
98140

99141
return jsonify({
100142
'response': ai_response,
101143
'success': True,
102-
'context_used': relevant_context[:200] + "..." if len(relevant_context) > 200 else relevant_context
144+
'refined_query': refined_query
103145
})
104146

105147
except Exception as e:

backend/personal_data.json

Lines changed: 77 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,110 @@
11
{
22
"basic": {
3-
"name": "Your Name",
4-
"title": "Your Professional Title",
5-
"email": "your.email@example.com",
6-
"location": "Your Location",
7-
"summary": "I am a passionate professional with experience in developing innovative solutions. I specialize in modern technologies and have a strong background in software development and cloud platforms."
3+
"name": "Spectual",
4+
"title": "AI Engineer / ML Engineer",
5+
"email": "ukubird@gmail.com",
6+
"location": "Boston, MA",
7+
"summary": "A Master's student in Computer Science at Boston University with a background in AI. Experienced in developing end-to-end AI pipelines, computer vision, and machine learning algorithms. Proven ability to lead research teams and deliver full-featured software solutions. Honored with multiple scholarships and holder of a patent in flood disaster prediction."
88
},
99
"skills": {
10-
"programmingLanguages": ["Python", "JavaScript", "TypeScript", "Java"],
11-
"mlFrameworks": ["TensorFlow", "PyTorch", "Scikit-learn"],
12-
"cloudPlatforms": ["AWS", "Google Cloud Platform", "Azure"],
13-
"tools": ["Docker", "Kubernetes", "Git", "Jenkins"],
14-
"specialties": ["Software Development", "Machine Learning", "Cloud Computing", "DevOps"]
10+
"professional": "Proficient in Python, Pytorch, Machine Learning techniques. Experience in LLM Application (Agent, RAG), Data Science, Computer Vision techniques and Git-based collaborative workflows.",
11+
"familiar": "Java",
12+
"languages": ["English (Advanced)", "Chinese (Native)"]
1513
},
1614
"experience": [
1715
{
18-
"title": "Senior Software Engineer",
19-
"company": "Tech Company",
20-
"duration": "2022 - Present",
16+
"title": "AI Engineer Intern (Incoming)",
17+
"company": "DIET of Harvard University",
18+
"duration": "Sep 2025 – Dec 2025",
19+
"description": "It's an AI Engineer / Machine Learning Engineer internship position at The Department of Digital Infrastructure and Emerging Technology (DIET) of Harvard University. The role is responsible for developing AI-based solutions and deploying reliable machine learning models for the Harvard Arts Museum.",
2120
"responsibilities": [
22-
"Lead development initiatives for core products, improving user engagement by 25%",
23-
"Built and deployed scalable applications using modern frameworks and cloud services",
24-
"Mentored junior engineers and established best practices for development",
25-
"Collaborated with cross-functional teams to deliver high-quality products"
21+
"Developing an end-to-end AI pipeline to assist in the identification of stolen ancient coins using image segmentation, embedding-based retrieval, and auction data integration.",
22+
"Designing and testing a scalable prototype bot combining computer vision (OpenCV, PyTorch) and data processing (pandas, NumPy) to match museum records with external auction listings.",
23+
"Implementing automated scripts to ingest, clean, and align multimodal datasets from internal archives and public databases, enabling model training and evaluation."
2624
],
27-
"achievements": [
28-
"Reduced application response time by 40% through optimization",
29-
"Implemented CI/CD pipeline for automated testing and deployment",
30-
"Led migration to cloud-based infrastructure"
31-
]
25+
"achievements": []
3226
},
3327
{
34-
"title": "Software Engineer",
35-
"company": "Innovation Solutions",
36-
"duration": "2020 - 2022",
28+
"title": "Machine Learning Engineer Intern",
29+
"company": "Institute of Artificial Intelligence, Nanjing Normal University",
30+
"duration": "Aug 2023 - Jun 2024",
31+
"description": "It's a Machine Learning Engineer internship position at the Institute of Artificial Intelligence of Nanjing Normal University. The role is responsible for developing machine learning models or computer vision models and deploying industrial models for real-world applications.",
3732
"responsibilities": [
38-
"Developed web applications and APIs for various business needs",
39-
"Worked with large datasets and optimized application performance",
40-
"Implemented data pipelines for real-time processing",
41-
"Conducted research on latest technologies and best practices"
33+
"Independently developed a diffraction-pattern recognition algorithm using computer vision and deep learning-based target segmentation techniques to automate RHEED image analysis.",
34+
"Designed and implemented a full-featured software, and led a research team to investigate technical solutions and optimize performance.",
35+
"Led end-to-end algorithm design and implemented a image processing pipeline for automated analysis."
4236
],
43-
"achievements": [
44-
"Achieved 95% test coverage on critical applications",
45-
"Reduced data processing time by 60% through pipeline optimization",
46-
"Published 2 technical articles on software development"
47-
]
48-
},
49-
{
50-
"title": "Junior Developer",
51-
"company": "Startup Inc",
52-
"duration": "2019 - 2020",
53-
"responsibilities": [
54-
"Analyzed business requirements and built software solutions",
55-
"Created user interfaces and backend services",
56-
"Performed code reviews and participated in agile development",
57-
"Collaborated with product teams to understand requirements"
58-
],
59-
"achievements": [
60-
"Improved application performance by 30%",
61-
"Identified and fixed critical bugs leading to 15% user satisfaction increase",
62-
"Automated testing processes saving 20 hours per week"
63-
]
37+
"achievements": []
6438
}
6539
],
6640
"projects": [
6741
{
68-
"name": "AI-Powered Chatbot Platform",
69-
"description": "Built an intelligent chatbot using NLP and transformer models that handles customer inquiries with 90% accuracy. The system can understand context, maintain conversation history, and provide personalized responses.",
70-
"technologies": ["Python", "Transformers", "FastAPI", "Docker", "Redis"],
71-
"impact": "Reduced customer service workload by 60% and improved customer satisfaction scores",
72-
"duration": "6 months",
73-
"role": "Lead Developer"
42+
"name": "AI and Education",
43+
"role": "Model Architect/Product Designer",
44+
"adviser": "Dr. Mostow, Carnegie Mellon University",
45+
"description": "Led the team to design modular AI solutions for educational applications, focusing on model architecture and content generation pipelines. Published a paper at the International Conference on Machine Learning and Automation.",
46+
"technologies": ["AI Model Architecture", "Product Design", "Content Generation"],
47+
"impact": "Published paper 'A Comprehensive Investigation for ChatGPT's Applications in Education' at the International Conference on Machine Learning and Automation, October 18, 2023, Oxford, UK.",
48+
"duration": "",
49+
"role_description": "Led the team to design modular AI solutions for educational applications, focusing on model architecture and content generation pipelines."
7450
},
7551
{
76-
"name": "Cloud-Native Application",
77-
"description": "Developed a scalable web application using microservices architecture, reducing deployment time by 60%. The system uses containerization and orchestration for high availability.",
78-
"technologies": ["Docker", "Kubernetes", "Node.js", "MongoDB", "AWS"],
79-
"impact": "Improved system reliability and reduced infrastructure costs by 40%",
80-
"duration": "8 months",
81-
"role": "Technical Lead"
52+
"name": "Boston Police Department Budget Analysis",
53+
"role": "Data Scientist/Analyst",
54+
"duration": "Feb 2025-April 2025",
55+
"description": "Performed data cleaning, exploratory data analysis and visualization on BPD budget and payroll records to uncover trends in overtime spending and departmental allocations. Built and evaluated machine learning models to predict future overtime expenditures.",
56+
"technologies": ["Data Cleaning", "Pandas", "NumPy", "Scikit-learn", "Data Visualization"],
57+
"impact": "Uncovered trends in overtime spending and departmental allocations; built predictive models for future expenditures.",
58+
"role_description": "Led a collaborative team using GitHub for version control and task delegation; managed workflow and ensured smooth coordination across project components."
8259
},
8360
{
84-
"name": "Data Analytics Dashboard",
85-
"description": "Created a comprehensive analytics dashboard for business intelligence, increasing data visibility by 20%. The system uses modern data visualization and real-time processing.",
86-
"technologies": ["React", "Python", "Apache Spark", "Redis", "PostgreSQL"],
87-
"impact": "Generated $5M additional revenue through data-driven insights",
88-
"duration": "4 months",
89-
"role": "Full Stack Developer"
61+
"name": "Machine-Vision Based Assistance System for Urban Blind Passages",
62+
"role": "Data Collection and Preprocessing Specialist",
63+
"duration": "Sep 2022-June 2023",
64+
"description": "Built an accessibility assistance system using YOLO-based object detection and semantic segmentation for blind pathways.",
65+
"technologies": ["YOLO", "Object Detection", "Semantic Segmentation", "Data Preprocessing"],
66+
"impact": "Developed a functional accessibility assistance system for visually impaired individuals.",
67+
"role_description": "Responsible for technical architecture, dataset collection, data preprocessing, and model development."
9068
}
9169
],
9270
"education": [
9371
{
94-
"degree": "Master of Science in Computer Science",
95-
"school": "University of Technology",
96-
"year": "2019",
97-
"focus": "Software Engineering and Artificial Intelligence",
98-
"gpa": "3.8/4.0",
99-
"relevantCourses": ["Advanced Algorithms", "Machine Learning", "Software Architecture", "Database Systems"]
72+
"degree": "M.S. in Computer Science",
73+
"school": "Boston University",
74+
"year": "Sep 2024 - Present",
75+
"gpa": "3.95 / 4.0",
76+
"relevantCourses": ["Machine Learning", "Deep Learning", "Data Science", "Object-oriented Software Design"]
10077
},
10178
{
102-
"degree": "Bachelor of Science in Computer Science",
103-
"school": "State University",
104-
"year": "2017",
105-
"focus": "Computer Science and Mathematics",
106-
"gpa": "3.7/4.0",
107-
"relevantCourses": ["Data Structures", "Algorithms", "Software Engineering", "Web Development"]
79+
"degree": "B.Eng. in Artificial Intelligence",
80+
"school": "Nanjing Normal University",
81+
"year": "Sep 2020 - June 2024",
82+
"relevantCourses": ["Database System", "Data Mining", "Natural Language Processing", "Computer Vision"]
83+
}
84+
],
85+
"publications": [
86+
{
87+
"title": "A comprehensive investigation for ChatGPT's applications in education",
88+
"journal": "Applied and Computational Engineering, 35, pp.116-122, 2024",
89+
"doi": "10.54254/2755-2721/35/20230377"
90+
}
91+
],
92+
"patents": [
93+
{
94+
"id": "ZL202411718876.X",
95+
"title": "A Method and System for Calculating the Distribution Probability of a Compound Flood Disaster",
96+
"issuer": "CNIPA Patent",
97+
"date": "May 16, 2025"
10898
}
10999
],
110100
"certifications": [
111-
"AWS Certified Solutions Architect",
112-
"Google Cloud Professional Developer",
113-
"Microsoft Azure Developer Associate"
101+
"Certificate of Achievement Fundamentals of Agents, Huggingface – May 2025",
102+
"Prompt Engineer Certification, Datawhale and iFLYTEK - Jan 2023"
114103
],
115-
"interests": [
116-
"Open source contributions to software libraries",
117-
"Mentoring junior developers and students",
118-
"Reading latest research papers in AI/ML",
119-
"Hiking and outdoor photography"
104+
"honors": [
105+
"Merit Student Scholarship - Dec 2021",
106+
"Scholarship for Outstanding Students of Nanjing Normal University - May 2021",
107+
"AI Mathematical Olympiad-Progress Prize 2 Top 20% - April 2025"
120108
],
121-
"careerGoals": "I'm passionate about building innovative software solutions that can make a positive impact on society. I'm looking for opportunities to lead cutting-edge projects, mentor talented developers, and contribute to the advancement of technology."
109+
"careerGoals": "Seeking opportunities to apply my expertise in AI and machine learning to solve challenging problems, contribute to innovative projects, and grow as a technology leader."
122110
}

0 commit comments

Comments
 (0)