Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5675e97
Image reader and image support in `gather_evidence` (#1046)
jamesbraza Aug 6, 2025
d1cde22
Preventing Greek name from crashing `DocDetails` creation (#1048)
jamesbraza Aug 6, 2025
0caa926
Better invalid name logs (#1049)
jamesbraza Aug 6, 2025
f71d023
Multimodal PDF support (#1047)
jamesbraza Aug 7, 2025
d3760c9
Fix paperqa/configs link in README.md (#1051)
chrisranderson Aug 8, 2025
948423f
Fixing all broken links, `pymarkdown` (#1052)
jamesbraza Aug 9, 2025
d34543e
Documenting `DocMetadataTask`/`MetadataProvider` (#1050)
jamesbraza Aug 9, 2025
beb838e
chore(deps): lock file maintenance (#1053)
renovate[bot] Aug 9, 2025
81ea858
chore(deps): update actions/checkout action to v5 (#1058)
renovate[bot] Aug 11, 2025
193feb6
chore(deps): update actions/download-artifact action to v5 (#1059)
renovate[bot] Aug 11, 2025
72b7f26
Moved `mypy` to use `local` hook to unsilence it on missing dependenc…
jamesbraza Aug 11, 2025
6801155
Removed dead `patch` from `test_add_clinical_trials_to_docs` (#1056)
jamesbraza Aug 11, 2025
34ceb70
Restored `UnpaywallProvider` by updating expected response (#1057)
jamesbraza Aug 11, 2025
fab944a
Refreshed `test_crossref_journalquality_fields_filtering` cassette (#…
jamesbraza Aug 11, 2025
4862764
Updating `journal_quality.csv` from script (#1061)
jamesbraza Aug 11, 2025
2d58202
Better lookup failure message in `Settings.from_name` (#1064)
jamesbraza Aug 16, 2025
62afb8c
Lower bibtex logging to debug (#1067)
mskarlin Aug 19, 2025
687ce40
Fix: handle non-UTF-8 input in util.py
dmcgrath19 Aug 20, 2025
7a88d42
Add comments to utf-8 error handling
dmcgrath19 Aug 20, 2025
46e21d6
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Aug 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Documenting DocMetadataTask/MetadataProvider (#1050)
  • Loading branch information
jamesbraza authored Aug 9, 2025
commit d34543e86b663890ac7f33f61cc7ebcdbcc438a6
21 changes: 16 additions & 5 deletions src/paperqa/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import aiohttp
from lmi.utils import gather_with_concurrency
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field

from paperqa.types import Doc, DocDetails

Expand Down Expand Up @@ -36,21 +36,33 @@


class DocMetadataTask(BaseModel):
"""Holder for provider and processor tasks."""
"""Simple container pairing metadata providers with processors."""

model_config = ConfigDict(arbitrary_types_allowed=True)

providers: Collection[MetadataProvider]
processors: Collection[MetadataPostProcessor]
providers: Collection[MetadataProvider] = Field(
description=(
"Metadata providers allotted to this task."
" An example would be providers for Crossref and Semantic Scholar."
)
)
processors: Collection[MetadataPostProcessor] = Field(
description=(
"Metadata post-processors allotted to this task."
" An example would be a journal quality filter."
)
)

def provider_queries(
self, query: dict
) -> list[Coroutine[Any, Any, DocDetails | None]]:
"""Set up query coroutines for each contained metadata provider."""
return [p.query(query) for p in self.providers]

def processor_queries(
self, doc_details: DocDetails, session: aiohttp.ClientSession
) -> list[Coroutine[Any, Any, DocDetails]]:
"""Set up process coroutines for each contained metadata post-processor."""
return [
p.process(copy.copy(doc_details), session=session) for p in self.processors
]
Expand Down Expand Up @@ -78,7 +90,6 @@ def __init__(
if nested, will query in order looking for termination criteria after each.
Will terminate early if either DocDetails.is_hydration_needed is False OR if
all requested fields are present in the DocDetails object.

"""
self._session = session
self.tasks: list[DocMetadataTask] = []
Expand Down
18 changes: 10 additions & 8 deletions src/paperqa/clients/client_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,28 @@ class JournalQuery(ClientQuery):


class MetadataProvider(ABC, Generic[ClientQueryType]):
"""Provide metadata from a query by any means necessary."""
"""Provide metadata from a query by any means necessary.

An example is going from a DOI to full paper metadata using Semantic Scholar.
"""

async def query(self, query: dict) -> DocDetails | None:
return await self._query(self.query_transformer(query))
return await self._query(self.query_factory(query))

@abstractmethod
async def _query(self, query: ClientQueryType) -> DocDetails | None:
pass
"""Run a query against the provider."""

@abstractmethod
def query_transformer(self, query: dict) -> ClientQueryType:
pass
def query_factory(self, query: dict) -> ClientQueryType:
"""Create a query object from unstructured query data."""


class DOIOrTitleBasedProvider(MetadataProvider[DOIQuery | TitleAuthorQuery]):

async def query(self, query: dict) -> DocDetails | None:
try:
client_query = self.query_transformer(query)
client_query = self.query_factory(query)
return await self._query(client_query)
# We allow graceful failures, i.e. return "None" for both DOI errors and timeout errors
# DOINotFoundError means the paper doesn't exist in the source, the timeout is to prevent
Expand Down Expand Up @@ -150,7 +153,7 @@ async def _query(self, query: DOIQuery | TitleAuthorQuery) -> DocDetails | None:
TimeoutError: When the request takes too long on the client side
"""

def query_transformer(self, query: dict) -> DOIQuery | TitleAuthorQuery:
def query_factory(self, query: dict) -> DOIQuery | TitleAuthorQuery:
try:
if "doi" in query:
return DOIQuery(**query)
Expand All @@ -169,7 +172,6 @@ class MetadataPostProcessor(ABC, Generic[ClientQueryType]):

MetadataPostProcessor should be idempotent and not order-dependent, i.e.
all MetadataPostProcessor instances should be able to run in parallel.

"""

async def process(self, doc_details: DocDetails, **kwargs) -> DocDetails:
Expand Down