diff --git a/includes/LegalTools.php b/includes/LegalTools.php index 9edc780..16854a2 100644 --- a/includes/LegalTools.php +++ b/includes/LegalTools.php @@ -70,6 +70,18 @@ final class DbnLegalToolsService // Retrieval still works in keyword mode without gateway config. } + // Doc-summary pre-pass: embed query → search bnl_doc_summaries → narrow shared chunks + // to the most semantically relevant documents. Non-fatal: empty = no filter applied. + $preFilterDocIds = []; + if ($scope !== 'private') { + try { + $preRag = new ClientRagPipeline((int)$client['id'], $gatewayUrl, 30); + $preFilterDocIds = $preRag->searchDocSummaries($query); + } catch (Throwable) { + // fall through — unfiltered chunk search + } + } + if ($scope === 'private') { // Search only the user's personal corpus if ($personalClientId > 0) { @@ -93,6 +105,7 @@ final class DbnLegalToolsService 'search_method' => $searchMethod, 'min_private' => 0, 'include_beta_website' => true, + 'shared_doc_ids' => $preFilterDocIds ?: null, ])); } else { // 'both': shared library + personal corpus merged and re-ranked by score @@ -105,6 +118,7 @@ final class DbnLegalToolsService 'search_method' => $searchMethod, 'min_private' => 0, 'include_beta_website' => true, + 'shared_doc_ids' => $preFilterDocIds ?: null, ])); $privateChunks = [];