pediatric-ai-scribe-v3/test/clinical-retrieval-title.test.js
Daniel 9788b167f2 refactor: retrieval is text-only; admins can add model ids discovery never returns
Multimodal removal
The multimodal path called nc_multimodal_search against a second hardcoded
collection whose embedding service (multimodal-embeddings:7999) was never
deployed and ENABLE_MULTIMODAL_RAG has always been false, so it only ever logged
"multimodal search skipped". Removed rather than left as dead weight:

- clinicalRetrieval: normalizeMcpMultimodalResponse, isVisualSourceQuery,
  isRadiologyQuery, buildMultimodalSearchQuery, classifyAndRerankMultimodalResults,
  selectMultimodalResults, visualIntent, visualMetadataScore,
  shouldRejectVisualSource, allowsFrontMatterQuery, looksLikeFrontMatterPage,
  looksLikeTextOnlyPage and MULTIMODAL_CANDIDATE_LIMIT (~140 lines).
- clinicalMcpClient: multimodalSearch.
- The route's visual/text slot split is gone; the whole search limit is text.
- The "[visual PDF page match]" prompt label and the "visual PDF page" source
  badge are gone with it.

Adding models
Model availability could only be ticked from what the gateway advertised, so an
admin could never offer a model discovery did not list. Each list now has a text
field: a typed id joins the same checkbox list, is enabled by default, is
de-duplicated, and persists through the normal allowed_models save.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BkfrkQwA4YGrGw9LZSpeAq
2026-09-09 23:35:06 +02:00

92 lines
3 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert/strict');
const { normalizeMcpSearchResponse } = require('../src/utils/clinicalRetrieval');
test('clinical retrieval replaces known internal PDF title with document title', () => {
const results = normalizeMcpSearchResponse({
results: [{
id: 1586022,
doc_type: 'file',
title: 'FABK010-fm[i-xiv].qxd',
excerpt: 'Respiratory disease text',
page_number: 320
}]
});
assert.equal(results[0].title, 'Respiratory Disease');
assert.equal(results[0].page, 320);
});
test('clinical retrieval prefers file basename for internal PDF production titles', () => {
// Retrieval is text-only now; this used to run through the multimodal
// normalizer, but the title cleanup it checks belongs to the shared path.
const results = normalizeMcpSearchResponse({
results: [{
id: 99,
doc_type: 'file',
title: 'chapter-layout.qxd',
file_path: 'Medical Library/Critical%20care%20%26%20Respiratory/Respiratory%20Disease.pdf',
excerpt: 'Airway anatomy and management in the critically ill child.',
page_number: 12
}]
});
assert.equal(results[0].title, 'Respiratory Disease');
});
test('clinical retrieval leaves normal source titles unchanged', () => {
const results = normalizeMcpSearchResponse({
results: [{
id: 123,
doc_type: 'file',
title: 'Nelson Textbook of Pediatrics.pdf',
excerpt: 'Clinical text'
}]
});
assert.equal(results[0].title, 'Nelson Textbook of Pediatrics');
});
test('clinical retrieval always prefers file basename over PDF metadata title', () => {
const results = normalizeMcpSearchResponse({
results: [{
id: 321,
doc_type: 'file',
title: 'Dermatology, Second Edition: 2-Volume Set (Bolognia, Dermatology)',
file_path: 'Medical Library/Dermatology/My%20Named%20Dermatology%20Source.pdf',
excerpt: 'Dermatologic therapy text'
}]
});
assert.equal(results[0].title, 'My Named Dermatology Source');
});
test('clinical retrieval prefers file basename for URL PDF metadata titles', () => {
const results = normalizeMcpSearchResponse({
results: [{
id: 456,
doc_type: 'file',
title: 'https://bookbaz.ir',
file_path: 'Medical Library/Dermatology/Bolognia%20Dermatology%20Second%20Edition.pdf',
excerpt: 'Dermatologic therapy text'
}]
});
assert.equal(results[0].title, 'Bolognia Dermatology Second Edition');
});
test('clinical retrieval strips image markdown while preserving OCR table text', () => {
const results = normalizeMcpSearchResponse({
results: [{
id: 1585684,
doc_type: 'file',
title: 'Nelson Textbook of Pediatrics.pdf',
excerpt: '~~Table 13.1~~\n\n![](/tmp/pdf-images/pdf-0132-02.png)\n\nAGE STREAMS OF DEVELOPMENT<br>2 mo row'
}]
});
assert.match(results[0].excerpt, /Table 13\.1/);
assert.match(results[0].excerpt, /AGE STREAMS OF DEVELOPMENT/);
assert.doesNotMatch(results[0].excerpt, /pdf-images|!\[\]/);
});