You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Full RAG Query flow (tab: "❓ General FAQ"), the selected “top relevant medicine” is often incorrect or not aligned with the user’s intent. This leads to wrong context being passed to the LLM and an unhelpful final answer.
Repro
Run the Streamlit app and go to tab "❓ Full RAG Query".
Enter a general query like: "What are the side effects of a medicine for headaches?" or "Which medicine helps with fever?"
Click "🔍 Run Full RAG".
Observe the "Top relevant medicine" card and the LLM response.
Expected
The chosen anchor medicine should match the intended condition (e.g., for headache queries, a relevant analgesic; for fever, an antipyretic). The context should include appropriate uses/conditions and side effects for that selection.
Actual
The chosen anchor medicine is sometimes unrelated or loosely related, suggesting the selection heuristics are not robust.
Suspected Areas
Condition extraction heuristic: GraphQueryEngine._extract_condition_from_query in graph_rag_query.py may miss or mis-parse condition phrases.
Condition-to-medicine ranking: GraphQueryEngine._best_medicine_for_condition may pick suboptimal results (ordering/filters).
Vector fallback: GraphQueryEngine.retrieve_context_for_rag uses a 1-nearest vector search on the entire user query, which can skew results when the prompt contains generic words.
Proposed Fix Plan
Improve _extract_condition_from_query with a small set of additional patterns (e.g., handle plurals, “relief for”, “good for”, “treats”, “used for”, “helps with”) and strip common stop words.
In _best_medicine_for_condition, add a tie-breaker using number of matching :TREATS or uses_text density; ensure we return medicines with an image_url when available to aid UI, but not as the main rank factor.
In vector fallback, encode only the extracted condition phrase (if present) rather than the entire question; otherwise, try a hybrid: 1) vector search top-5, 2) re-rank by mention of the extracted condition in uses_text and :TREATS edges.
Add minimal unit-style checks (simple script) to validate that queries like “medicine for fever” or “medicine for headache” map to a sensible medicine from the dataset.
Additional Context
Relevant files: graph_rag_query.py (selection and retrieval), ingest_graph.py (embedding text construction and index config).
Vector index: medicine_embeddings on Medicine.embedding (dim 384, cosine).
Acceptance Criteria
For common queries (fever, headache, cold), the top medicine chosen matches typical use cases from the ingested CSV and graph relationships.
Manual smoke test on at least 5 queries shows improved precision of the anchor medicine.
Summary
Repro
Expected
Actual
Suspected Areas
GraphQueryEngine._extract_condition_from_queryingraph_rag_query.pymay miss or mis-parse condition phrases.GraphQueryEngine._best_medicine_for_conditionmay pick suboptimal results (ordering/filters).GraphQueryEngine.retrieve_context_for_raguses a 1-nearest vector search on the entire user query, which can skew results when the prompt contains generic words.Proposed Fix Plan
_extract_condition_from_querywith a small set of additional patterns (e.g., handle plurals, “relief for”, “good for”, “treats”, “used for”, “helps with”) and strip common stop words._best_medicine_for_condition, add a tie-breaker using number of matching:TREATSoruses_textdensity; ensure we return medicines with an image_url when available to aid UI, but not as the main rank factor.uses_textand:TREATSedges.Additional Context
graph_rag_query.py(selection and retrieval),ingest_graph.py(embedding text construction and index config).medicine_embeddingsonMedicine.embedding(dim 384, cosine).Acceptance Criteria
Labels