Skip to content

Commit de0ddda

Browse files
AryanBVclaude
andcommitted
fix: Remove option limits and fix hierarchy mixing for coffee grades
Root cause fixes for option limiting and hierarchy mixing issues: 1. Remove .slice(0, 6) limit - now shows ALL relevant options instead of arbitrarily cutting off valid HS codes (e.g., Robusta codes were hidden) 2. Increase maxOptions from 8 to 25 - allows complex hierarchies like coffee grades (20+ options under 0901.11) to display fully 3. Increase leaf options limit from 8 to 25 - ensures all grade variants are shown when navigating to specific code levels 4. Fix getAllChapters() to filter 4-digit headings only - prevents mixing 2-digit chapters (09) with 4-digit headings (0901) in first question Test results: 36/37 passing (97%) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 87a6295 commit de0ddda

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

backend/src/services/llm-navigator.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,10 @@ function detectDistinctGroups(
404404
const questionText = generateSmartQuestion(relevantOptions);
405405

406406
// ROOT CAUSE FIX: Use generateUniqueLabel which handles duplicates properly
407+
// Show ALL options - don't arbitrarily cut off valid HS codes
408+
// Users need to see all choices to make accurate classification
407409
const existingLabels = new Set<string>();
408-
const groups = relevantOptions.slice(0, 6).map(o => {
410+
const groups = relevantOptions.map(o => {
409411
const uniqueLabel = generateUniqueLabel(o.code, o.description, existingLabels);
410412
return {
411413
name: uniqueLabel,
@@ -650,12 +652,17 @@ async function getAllChapters(): Promise<HierarchyOption[]> {
650652
orderBy: { code: 'asc' }
651653
});
652654

653-
// All headings have children in HS code structure
654-
return headings.map(h => ({
655+
// CRITICAL FIX: Only return 4-digit headings, not 2-digit chapters
656+
// This prevents mixing hierarchy levels in the first question
657+
// Database has both "09" (2-digit chapter) and "0901" (4-digit heading) - we want only 4-digit
658+
const fourDigitHeadings = headings.filter(h => h.code.length === 4);
659+
660+
// All 4-digit headings have children in HS code structure
661+
return fourDigitHeadings.map(h => ({
655662
code: h.code,
656663
description: h.description,
657664
isOther: h.isOther,
658-
hasChildren: true // Headings always have subheadings underneath
665+
hasChildren: true // 4-digit headings always have subheadings underneath
659666
}));
660667
}
661668

@@ -866,7 +873,7 @@ function generateUniqueLabel(code: string, description: string, existingLabels:
866873
*/
867874
function processOptionsForDisplay(
868875
options: Array<{code: string; description: string; isOther?: boolean}>,
869-
maxOptions: number = 8
876+
maxOptions: number = 25 // Allow more options for complex hierarchies like coffee grades
870877
): Array<{code: string; label: string; description: string}> {
871878
const result: Array<{code: string; label: string; description: string}> = [];
872879
const existingLabels = new Set<string>();
@@ -1624,8 +1631,9 @@ export async function navigateHierarchy(
16241631
logger.info(`[LLM-NAV] Multiple leaf options detected (${leafOptions.length}), forcing question`);
16251632

16261633
// Generate question about the specific variants
1634+
// Don't cut off valid leaf options - show all grades/variants
16271635
const existingLabels = new Set<string>();
1628-
const questionOptions = leafOptions.slice(0, 8).map(opt => ({
1636+
const questionOptions = leafOptions.slice(0, 25).map(opt => ({
16291637
code: opt.code,
16301638
label: generateUniqueLabel(opt.code, opt.description, existingLabels),
16311639
description: opt.description

0 commit comments

Comments
 (0)