Spaces:
Paused
Download migration_instruction.md from MuhammadTechxone/heedx_v2: direct link, hf CLI and curl.
- Browser
- Download file 25.6 kB
-
https://huggingface.co/spaces/MuhammadTechxone/heedx_v2/resolve/main/migration_instruction.md
- Command line
-
hf download hf://spaces/MuhammadTechxone/heedx_v2/migration_instruction.md
-
curl -L -o migration_instruction.md https://huggingface.co/spaces/MuhammadTechxone/heedx_v2/resolve/main/migration_instruction.md
HeedX AI β Two-Mode Mental-Health AI Architecture
You are the primary AI software engineer working on HeedX AI, a Nigerian mental-health support and analysis application.
Your first responsibility is to understand the existing codebase and architecture before changing it.
Do not immediately rewrite the application.
Inspect the existing project, identify what is already working, and then redesign it around the architecture described below.
1. CORE CONCEPT
HeedX has TWO DISTINCT INPUT MODES.
They must remain conceptually separate even though they can share the same underlying AI/RAG infrastructure.
Mode A β Professional / Case Analysis
This mode is intended for a psychologist, mental-health professional, researcher, or authorized user who already has patient/client text.
The professional can:
- upload a document
- paste patient/client text
- write patient/client text manually
HeedX then performs qualitative analysis of the supplied text.
Example:
"The patient reports feeling persistently sad for approximately one month. She has difficulty sleeping, has withdrawn from friends, and is struggling to concentrate at university."
The system extracts and organizes information such as:
Presenting concerns
β’ persistent sadness
β’ sleep difficulty
β’ social withdrawal
β’ difficulty concentrating
Duration
β’ approximately one month
Context
β’ university/academic environment
Potentially relevant symptoms/signals
β’ low mood
β’ sleep disturbance
β’ reduced social engagement
β’ concentration difficulty
Risk information
β’ no suicidal ideation established from the supplied text
β’ further assessment may be appropriate
This is qualitative analysis.
Do NOT turn this into:
Depression = 78%
Anxiety = 15%
Normal = 5%
Suicidal = 2%
The system should not generate fake diagnostic probabilities.
2. Mode B β Conversational User Mode
This mode is for a person directly interacting with HeedX.
The user communicates naturally:
"I've been feeling really down lately."
Then:
"It's been happening for a few weeks and I can't sleep properly."
Then:
"University has also been stressful."
The system should maintain conversation context and continuously update its understanding.
Conceptually:
USER MESSAGE
β
UNDERSTAND CURRENT MESSAGE
β
UPDATE CONVERSATION STATE
β
RETRIEVE RELEVANT KNOWLEDGE
β
LLM
β
PERSONALIZED RESPONSE
β
USER CONTINUES
β
REPEAT
This mode should feel like a natural conversation, NOT like filling out a questionnaire.
3. VERY IMPORTANT: DO NOT ADD QUESTIONNAIRE SCREENING
For the current version, do NOT implement:
- PHQ-9
- GAD-7
- WHO-5
- Kessler
- questionnaire scoring
- questionnaire UI
- questionnaire-based diagnosis
This may be added in a future version.
The current system should primarily understand natural language.
4. VERY IMPORTANT: OLD CLASSIFIER IS NO LONGER THE PRIMARY ENGINE
The existing application may contain a classical ML classifier with classes such as:
Normal
Anxiety
Depression
Suicidal
The old architecture was approximately:
INPUT
β
CLASSICAL ML MODEL
β
class + probabilities
β
Python analysis
β
LLM
β
conversation
This classifier should NOT be the primary inference mechanism in the redesigned system.
It may be retained for:
- experimentation
- research comparison
- benchmarking
- future development
But the production user experience should NOT depend on the four-class classifier.
The new architecture is based on qualitative semantic understanding + retrieval + conversational generation.
5. TWO INPUTS, ONE SHARED INTELLIGENCE LAYER
The central architectural principle is:
HEEDX
β
βββββββββββ΄ββββββββββ
β β
βΌ βΌ
PROFESSIONAL MODE CONVERSATION MODE
CASE ANALYSIS USER CHAT
β β
βΌ βΌ
Qualitative analysis Conversation
β understanding
β β
βββββββββββ¬ββββββββββ
βΌ
SHARED HEEDX CORE
β
βββββββββββββββΌββββββββββββββ
β β β
βΌ βΌ βΌ
Analysis RAG Safety
Engine Engine Layer
β β β
βββββββββββββββΌββββββββββββββ
βΌ
LLM
β
ββββββββββ΄βββββββββ
βΌ βΌ
Case output User response
Do NOT build two completely unrelated AI systems.
Build two input experiences that share common underlying services.
6. WHAT "QUALITATIVE ANALYSIS" MEANS
The analysis engine should identify meaningful information from text rather than forcing it into mutually exclusive diagnostic categories.
Potential structured fields include:
{
"presenting_concerns": [],
"emotions": [],
"symptoms_or_signals": [],
"stressors": [],
"duration": null,
"functional_impact": [],
"social_context": [],
"protective_factors": [],
"risk_signals": [],
"support_needs": [],
"uncertainties": []
}
This is an information representation, not a diagnosis.
For example:
{
"presenting_concerns": [
"persistent sadness"
],
"symptoms_or_signals": [
"sleep difficulty",
"loss of interest",
"social withdrawal"
],
"stressors": [
"academic pressure"
],
"duration": "approximately three weeks",
"risk_signals": [],
"uncertainties": [
"suicidal ideation not established"
]
}
The system should distinguish between:
- explicitly stated information
- reasonable semantic interpretation
- information that remains unknown
Do not invent information that the user/patient did not provide.
7. PROFESSIONAL / CASE ANALYSIS PIPELINE
The professional mode should follow:
PROFESSIONAL
β
βΌ
Upload / Paste / Write Patient Text
β
βΌ
Text Extraction
β
βΌ
Qualitative Analysis
β
βββ concerns
βββ symptoms/signals
βββ emotions
βββ stressors
βββ duration
βββ functioning
βββ context
βββ risk signals
β
βΌ
Structured Case Representation
β
βΌ
Retrieval Query Construction
β
βΌ
Embedding
β
βΌ
Vector Search
β
βΌ
Relevant Evidence
β
βΌ
LLM
β
βΌ
Professional Case Summary / Evidence-Grounded Analysis
The professional should be able to see the resulting analysis clearly.
8. CONVERSATIONAL PIPELINE
The conversational mode should follow:
USER
β
βΌ
Message
β
βΌ
Conversation Understanding
β
βββ current concerns
βββ symptoms/signals
βββ emotions
βββ stressors
βββ duration
βββ risk signals
β
βΌ
Update Conversation State
β
βΌ
Construct Retrieval Query
β
βΌ
Embedding
β
βΌ
Vector Search
β
βΌ
Relevant Evidence
β
βΌ
LLM
β
βΌ
Natural Personalized Response
β
βΌ
USER
This process can repeat on every meaningful turn.
9. CONVERSATION STATE
The conversational system should maintain a structured state.
Example:
{
"main_concerns": [
"persistent sadness",
"sleep difficulty",
"loss of interest"
],
"duration": "approximately three weeks",
"stressors": [
"academic pressure",
"financial difficulty"
],
"functional_impact": [
"difficulty concentrating"
],
"risk_signals": [],
"risk_status": "not_established"
}
The state must evolve as the user provides new information.
For example:
First message
"I've been feeling down."
State:
low mood
Second message
"For about three weeks and I can't sleep."
State becomes:
low mood
+
three-week duration
+
sleep difficulty
Third message
"University has been stressful."
State becomes:
low mood
+
three-week duration
+
sleep difficulty
+
academic stress
This state should help improve retrieval and personalization.
10. EMBEDDINGS AND VECTORS
There are TWO sides to embeddings.
Static knowledge embeddings
Knowledge documents are processed before user interaction:
Research / Guidelines / Knowledge
β
Text extraction
β
Chunking
β
Embedding model
β
Vectors
β
Vector database
These embeddings are relatively static.
User/query embeddings
When relevant user information needs to be retrieved:
Current user message
+
Conversation state
+
Structured signals
β
Retrieval query
β
Embedding model
β
Query vector
β
Vector similarity search
The same compatible embedding model should be used for knowledge chunks and retrieval queries.
Remember:
The vector does not contain the knowledge itself.
The actual knowledge remains in the stored document chunks.
The vector allows the system to find semantically related chunks.
11. RETRIEVAL MUST USE THE USER'S INFORMATION
Do not build a RAG system where the user text is disconnected from retrieval.
The connection should be explicit:
USER TEXT
β
UNDERSTANDING
β
STRUCTURED SIGNALS
β
RETRIEVAL QUERY
β
EMBEDDING
β
VECTOR SEARCH
β
RELEVANT KNOWLEDGE
For example:
User:
"I haven't enjoyed football for weeks and I'm barely sleeping."
Possible retrieval representation:
loss of interest
sleep disturbance
persistent symptoms
reduced enjoyment
mental health
The system then searches the knowledge base for semantically relevant evidence.
12. DO NOT BLINDLY EMBED THE ENTIRE CONVERSATION
The system should not simply concatenate every historical message forever and embed everything blindly.
Instead use:
Current message
+
Relevant conversation state
+
Relevant context
+
Structured signals
to construct the retrieval query.
The full conversation history can still be supplied to the LLM where appropriate.
Retrieval context and conversational context are related but are not identical.
13. RAG KNOWLEDGE BASE
The knowledge base should be designed around reliable mental-health information, especially Nigerian/local context.
Suggested structure:
knowledge/
β
βββ nigeria_evidence/
β βββ national/
β βββ depression/
β βββ anxiety/
β βββ suicide/
β βββ trauma/
β βββ substance_use/
β βββ adolescents/
β βββ university_students/
β βββ severe_mental_illness/
β
βββ nigeria_context/
β βββ stigma/
β βββ culture/
β βββ family/
β βββ religion_and_mental_health/
β βββ unemployment/
β βββ poverty/
β βββ conflict/
β βββ healthcare_access/
β
βββ scenarios/
β βββ academic_stress/
β βββ financial_stress/
β βββ grief/
β βββ relationships/
β βββ anxiety/
β βββ depression/
β βββ trauma/
β βββ suicide_risk/
β
βββ psychoeducation/
β
βββ recommendations/
β
βββ metadata/
Do not simply dump documents into a vector database.
Preserve useful metadata.
14. KNOWLEDGE CHUNK METADATA
Where possible, each chunk should retain:
document_id
title
source
authors
year
country
state
population
sample_size
age_range
mental_health_domain
condition
study_design
measurement_tool
evidence_level
limitations
source_url
This allows future retrieval filtering and source attribution.
15. DETERMINISTIC MODULES STILL EXIST
RAG does NOT replace every existing static module.
Keep exact information in deterministic/structured data.
Examples:
Emergency contacts
Facilities
Facility addresses
Verified URLs
Crisis procedures
Service directories
Application configuration
Other exact structured information
Do not ask the LLM to invent these.
The architecture should therefore have:
HEEDX CORE
β
ββββββββββββββΌββββββββββββββ
β β β
βΌ βΌ βΌ
LLM RAG DETERMINISTIC
Conversation Knowledge Modules
β β β
β β βββ contacts
β β βββ facilities
β β βββ URLs
β β βββ exact data
β β
β βββ studies
β βββ guidance
β βββ psychoeducation
β βββ evidence
β
ββββββββββββββ¬ββββββββββββββ
βΌ
HEEDX
16. SAFETY LAYER
Safety must be separate from ordinary RAG.
For example, if a user says:
"I want to kill myself."
the application must not simply perform normal semantic retrieval and answer like an ordinary mental-health question.
It must activate a dedicated safety pathway.
The safety layer should be able to:
- identify high-risk signals
- determine whether clarification is necessary
- prioritize immediate safety
- provide verified emergency/crisis resources
- encourage appropriate human support
- change the response strategy
- prevent unsafe conversational behavior
RAG can provide supporting evidence, but the safety mechanism itself must have explicit rules and guardrails.
17. NO DIAGNOSTIC CLAIMS
HeedX should not claim:
"You have depression."
based solely on conversational analysis.
Prefer:
"What you're describing includes experiences commonly associated with depression."
or:
"These symptoms may be worth discussing with a mental-health professional."
The system is providing support, qualitative analysis, and evidence-grounded information, not replacing clinical diagnosis.
18. PROFESSIONAL OUTPUT VS USER OUTPUT
These two modes should have different presentation styles.
Professional mode
The output can be structured:
CASE ANALYSIS
Presenting concerns
...
Reported symptoms/signals
...
Duration
...
Stressors/context
...
Functional impact
...
Risk indicators
...
Relevant considerations
...
Evidence retrieved
...
Suggested areas for further assessment
...
Be clear that this is an AI-assisted analysis and not a definitive diagnosis.
Conversational mode
The output should be natural:
"I hear you. From what you've described, you've been dealing
with poor sleep and losing interest in things you normally enjoy.
That can be difficult, especially alongside academic stress.
Can I ask whether this has also affected your ability to attend
classes or carry out your normal daily activities?"
Do not expose vector databases, embeddings, retrieval mechanics, or internal analysis unless specifically requested.
19. LLM CONTEXT
The LLM should receive an appropriate combination of:
System instructions
+
Current user/patient text
+
Relevant conversation history
+
Structured analysis
+
Conversation/case state
+
Retrieved evidence
+
Safety state
+
Deterministic information when required
For professional mode:
Patient text
+
Qualitative analysis
+
Retrieved evidence
+
Safety information
+
Professional instructions
For conversational mode:
Current user message
+
Conversation history
+
Conversation state
+
Retrieved evidence
+
Safety state
+
Conversational instructions
20. KNOWLEDGE SOURCES
The knowledge system should prioritize reliable sources such as:
- peer-reviewed Nigerian research
- reputable international research
- WHO guidance
- Nigerian government/public-health sources
- recognized clinical/public-health organizations
- evidence-based mental-health resources
Nigerian evidence should be prioritized where relevant.
Do not fabricate citations or sources.
21. EXISTING CODEBASE INSPECTION
Before changing the project, inspect:
- Entry point
- UI
- Professional/case-analysis interface
- Conversational interface
- Existing classical ML model
- Existing Python analysis
- Existing LLM integration
- Existing static modules
- Existing recommendations
- Emergency/crisis information
- Facility/location data
- Data files
- Deployment configuration
- Requirements/dependencies
- Existing tests
Determine what should be:
- preserved
- refactored
- replaced
- deprecated
- newly added
Do not delete existing functionality simply because the architecture is changing.
22. TARGET ARCHITECTURE
The final conceptual architecture should resemble:
HEEDX AI
β
ββββββββββββββββ΄βββββββββββββββ
β β
βΌ βΌ
PROFESSIONAL MODE CONVERSATIONAL MODE
CASE ANALYSIS USER CHAT
β β
Upload / Paste / Write User messages
β β
βΌ βΌ
Qualitative Analysis Conversation Understanding
β β
βΌ βΌ
Structured Case State Conversation State
β β
ββββββββββββββββ¬βββββββββββββββ
βΌ
RETRIEVAL ENGINE
β
Query creation
β
Embedding
β
Vector Database
β
Relevant Knowledge
β
ββββββββββββββββΌβββββββββββββββ
β β β
βΌ βΌ βΌ
RAG SAFETY DETERMINISTIC
Evidence Layer Modules
β β β
ββββββββββββββββΌβββββββββββββββ
βΌ
LLM
ββββββββ΄βββββββ
βΌ βΌ
Professional User-facing
output response
23. DEVELOPMENT ORDER
Implement incrementally.
Stage 1 β Repository analysis
Understand the existing application.
Do not make destructive changes.
Stage 2 β Separate the two input modes
Ensure the UI and backend conceptually distinguish:
Professional / Case Analysis
from:
Conversational User Mode
Stage 3 β Build/refactor qualitative analysis
Create a structured qualitative analysis representation.
Stage 4 β Build knowledge ingestion
Implement:
documents
β extraction
β chunking
β metadata
β embeddings
β vector storage
Stage 5 β Implement retrieval
Implement:
query
β embedding
β similarity search
β relevant chunks
Stage 6 β Connect retrieval to professional analysis
patient text
β qualitative analysis
β retrieval
β evidence
β professional output
Stage 7 β Connect retrieval to conversation
user message
β conversation understanding
β state
β retrieval
β evidence
β LLM
β response
Stage 8 β Implement safety layer
Keep safety behavior separate from ordinary RAG.
Stage 9 β Test both modes separately
Test professional analysis independently from conversational behavior.
Stage 10 β Integrate and refine UI
Only after the underlying architecture is working.
24. TEST CASES
Create tests/examples for both modes.
Professional mode example
Input:
"Patient reports feeling sad most days for the past month, has stopped enjoying social activities and is having difficulty sleeping. Academic workload has increased significantly."
Expected qualitative analysis should identify:
persistent sadness
reduced interest/social withdrawal
sleep difficulty
academic stress
approximately one month duration
It should NOT output a fabricated diagnostic probability.
Conversational mode example
User:
"I've been feeling down lately."
Then:
"It's been about three weeks and I barely sleep."
Then:
"School has also been stressful."
The system should progressively update the conversation state and retrieve increasingly relevant evidence.
25. FINAL DESIGN PRINCIPLE
The most important architecture to preserve is:
TWO INPUT MODES
β
ββββββββββββββ΄βββββββββββββ
β β
βΌ βΌ
PROFESSIONAL MODE CONVERSATION MODE
β β
Qualitative analysis Continuous understanding
β β
ββββββββββββββ¬βββββββββββββ
βΌ
SHARED CORE
β
βββββββββββΌββββββββββ
βΌ βΌ βΌ
Analysis RAG Safety
β
Embeddings
β
Vector search
β
βΌ
LLM
β
βββββββββββ΄ββββββββββ
βΌ βΌ
Professional output User response
Remember these principles throughout implementation:
- There are two distinct input modes.
- Professional mode analyzes supplied patient/client text.
- Conversational mode interacts continuously with the user.
- The analysis is primarily qualitative, not a four-class probability prediction.
- No questionnaire screening in this version.
- RAG is shared infrastructure for both modes.
- Knowledge documents are embedded and stored as vectors.
- User/conversation information produces query embeddings for retrieval.
- The user's actual text remains central; embeddings only facilitate retrieval.
- Conversation state is maintained separately from the vector database.
- Deterministic modules remain responsible for exact information.
- Safety has its own explicit layer.
- RAG provides evidence; it does not diagnose.
- The LLM turns the analysis, context, evidence, and safety state into the appropriate output.
Before implementing major changes, first inspect the repository and produce:
- Current architecture
- Target architecture
- Files/components that should be preserved
- Files/components that should be changed
- New components required
- Implementation sequence
Then proceed incrementally without unnecessarily destroying existing working functionality.