~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(pubmed): exclude OtherAbstract and read Keyword/Affiliation inline markup (#8000)
HPH Protond881ee6f5e71
diff --git a/changelog.d/7938.bugfix.md b/changelog.d/7938.bugfix.mdnew file mode 100644index 0000000000..afc5ed5e58--- /dev/null+++ b/changelog.d/7938.bugfix.md@@ -0,0 +1,2 @@+PubMed abstracts no longer include OtherAbstract translations, and keywords+and affiliations keep the text inside inline markup such as `<i>` and `<sub>`.diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py b/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.pyindex 0270c18fab..44d3c18bab 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py@@ -949,9 +949,14 @@ The default assumption should be that medical and scientific queries want RECENTif pmid is None:continue- # The abstract is its sections, one or several (structured)+ # The abstract is its sections, one or several (structured).+ # Primary <Abstract> under <Article> only. <OtherAbstract>+ # (translations, plain-language summaries) is a sibling of+ # <Article> and must not be appended or used as a fallback.abstract_text = ""- abstract_sections = article.findall(".//AbstractText")+ abstract_sections = article.findall(+ ".//Article/Abstract/AbstractText"+ )if len(abstract_sections) > 1:logger.debug(f"Article {pmid} has {len(abstract_sections)} abstract sections"@@ -1064,19 +1069,21 @@ The default assumption should be that medical and scientific queries want RECENTif mesh_terms:article_metadata["mesh_terms"] = mesh_terms- # Extract keywords+ # Extract keywords. `.text` stops at the first inline tag.keywords = []for keyword in article.findall(".//Keyword"):- if keyword.text:- keywords.append(keyword.text)+ keyword_text = "".join(keyword.itertext()).strip()+ if keyword_text:+ keywords.append(keyword_text)if keywords:article_metadata["keywords"] = keywords- # Extract affiliations+ # Extract affiliations. `.text` stops at the first inline tag.affiliations = []for affiliation in article.findall(".//Affiliation"):- if affiliation.text:- affiliations.append(affiliation.text)+ affiliation_text = "".join(affiliation.itertext()).strip()+ if affiliation_text:+ affiliations.append(affiliation_text)if affiliations:article_metadata["affiliations"] = affiliationsdiff --git a/tests/web_search_engines/engines/test_search_engine_pubmed.py b/tests/web_search_engines/engines/test_search_engine_pubmed.pyindex 459ccac4be..d2956f122e 100644--- a/tests/web_search_engines/engines/test_search_engine_pubmed.py+++ b/tests/web_search_engines/engines/test_search_engine_pubmed.py@@ -999,6 +999,53 @@ class TestGetArticleAbstracts:"2": "BACKGROUND: Background info.\n\nRESULTS: Results info.",}+ def test_excludes_other_abstract_translations(self):+ """A publisher translation is not part of the returned abstract."""+ from local_deep_research.web_search_engines.engines.search_engine_pubmed import (+ PubMedSearchEngine,+ )++ engine = PubMedSearchEngine()++ xml_response = """<?xml version="1.0"?>+ <PubmedArticleSet>+ <PubmedArticle>+ <MedlineCitation>+ <PMID>1</PMID>+ <Article>+ <Abstract>+ <AbstractText>Primary English abstract.</AbstractText>+ </Abstract>+ </Article>+ <OtherAbstract Type="Publisher" Language="fre">+ <AbstractText>Résumé en français.</AbstractText>+ </OtherAbstract>+ </MedlineCitation>+ </PubmedArticle>+ <PubmedArticle>+ <MedlineCitation>+ <PMID>2</PMID>+ <OtherAbstract Language="fre">+ <AbstractText>Résumé seulement.</AbstractText>+ </OtherAbstract>+ </MedlineCitation>+ </PubmedArticle>+ </PubmedArticleSet>+ """++ with patch(+ "local_deep_research.web_search_engines.engines.search_engine_pubmed.safe_get"+ ) as mock_get:+ mock_response = Mock()+ mock_response.text = xml_response+ mock_response.raise_for_status = Mock()+ mock_get.return_value = mock_response++ result = engine._get_article_abstracts(["1", "2"])++ assert result["1"] == "Primary English abstract."+ assert "2" not in result+class TestGetArticleDetailedMetadata:"""Tests for _get_article_detailed_metadata method."""@@ -1118,6 +1165,53 @@ class TestGetArticleDetailedMetadata:assert "keywords" in result["12345"]assert "cancer" in result["12345"]["keywords"]+ def test_extracts_keywords_and_affiliations_with_inline_markup(self):+ """Inline tags inside a keyword or affiliation stay in the text."""+ from local_deep_research.web_search_engines.engines.search_engine_pubmed import (+ PubMedSearchEngine,+ )++ engine = PubMedSearchEngine()++ xml_response = """<?xml version="1.0"?>+ <PubmedArticleSet>+ <PubmedArticle>+ <MedlineCitation>+ <PMID>12345</PMID>+ <Article>+ <AuthorList>+ <Author>+ <Affiliation><sup>1</sup>Department of Biology, <i>In Vivo</i> Unit</Affiliation>+ </Author>+ </AuthorList>+ </Article>+ <KeywordList>+ <Keyword><i>Escherichia coli</i> resistance</Keyword>+ <Keyword>CO<sub>2</sub> capture</Keyword>+ </KeywordList>+ </MedlineCitation>+ </PubmedArticle>+ </PubmedArticleSet>+ """++ with patch(+ "local_deep_research.web_search_engines.engines.search_engine_pubmed.safe_get"+ ) as mock_get:+ mock_response = Mock()+ mock_response.text = xml_response+ mock_response.raise_for_status = Mock()+ mock_get.return_value = mock_response++ result = engine._get_article_detailed_metadata(["12345"])++ assert result["12345"]["keywords"] == [+ "Escherichia coli resistance",+ "CO2 capture",+ ]+ assert result["12345"]["affiliations"] == [+ "1Department of Biology, In Vivo Unit"+ ]+def test_returns_empty_for_empty_id_list(self):"""Returns empty dict for empty ID list."""from local_deep_research.web_search_engines.engines.search_engine_pubmed import (