engine
zocrates.discovery.engine ¶
Discovery Engine orchestrating search providers, deduplication, abstract backfill, and OA PDF resolution.
AbstractFallback ¶
Manages 3-tier opportunistic fallback for paper abstracts
- Tier 1: Direct OpenAlex abstract (present in CandidatePaper).
- Tier 2: Semantic Scholar REST API (and NCBI PubMed E-utilities for biomedical papers) with 2.0s timeout.
- Tier 3: Clean fallback to OpenAlex keywords and primary topic.
Initialize the abstract fallback resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email used for respectful API polite-pool headers. |
DEFAULT_POLITE_EMAIL
|
timeout
|
float
|
HTTP request timeout in seconds. |
2.0
|
Source code in zocrates/discovery/abstract_fallback.py
backfill_abstract
async
¶
Backfill missing abstract and TLDR on a candidate paper using opportunistic fallbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate
|
CandidatePaper
|
CandidatePaper instance. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper
|
CandidatePaper with abstract/tldr backfilled if resolved. |
Source code in zocrates/discovery/abstract_fallback.py
backfill_batch
async
¶
Backfill missing abstracts concurrently across a batch of candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidates
|
list[CandidatePaper]
|
List of CandidatePaper instances. |
required |
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of updated CandidatePaper instances. |
Source code in zocrates/discovery/abstract_fallback.py
CandidatePaper
dataclass
¶
CandidatePaper(candidate_id, title, authors=list(), year=None, venue=None, doi=None, arxiv_id=None, openalex_id='', abstract=None, tldr=None, is_oa=False, oa_pdf_url=None, oa_pdf_urls=list(), citation_count=0, primary_topic=None, keywords=list(), in_library=False)
Represents a discovered scholarly paper candidate.
from_dict
classmethod
¶
Deserialize CandidatePaper from a dictionary.
Source code in zocrates/discovery/models.py
to_dict ¶
Serialize CandidatePaper to a plain dictionary.
Source code in zocrates/discovery/models.py
Deduplicator ¶
Deduplicator(zotero_db=None, existing_dois=None, existing_arxiv_ids=None, existing_records=None, existing_titles=None)
Enforces strict novelty against the user's local Zotero library and removes duplicates within search result batches.
Initialize Deduplicator with library state from ZoteroDB or explicit collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotero_db
|
Any | None
|
Optional ZoteroDB instance to query live library records. |
None
|
existing_dois
|
set[str] | None
|
Pre-populated set of normalized DOIs. |
None
|
existing_arxiv_ids
|
set[str] | None
|
Pre-populated set of normalized arXiv IDs. |
None
|
existing_records
|
list[dict[str, Any]] | None
|
Pre-populated list of library record dicts (with title, year, creators). |
None
|
existing_titles
|
list[str] | None
|
Pre-populated list of raw or normalized titles. |
None
|
Source code in zocrates/discovery/dedup.py
filter_novel ¶
Filter candidate papers enforcing strict novelty against the library and deduplicating across the current batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidates
|
list[CandidatePaper]
|
List of CandidatePaper instances. |
required |
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of strictly novel CandidatePaper instances, deduplicated intra-batch. |
Source code in zocrates/discovery/dedup.py
is_in_library ¶
Check whether candidate paper already exists in the user's library.
Evaluates
- DOI exact match.
- arXiv ID exact match.
- Exact normalized title match.
- Fuzzy title similarity (>= 0.92) with matching year or author.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate
|
CandidatePaper
|
CandidatePaper instance. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the paper exists in the library, False otherwise. |
Source code in zocrates/discovery/dedup.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
DiscoveryEngine ¶
DiscoveryEngine(provider=None, deduplicator=None, abstract_fallback=None, unpaywall=None, email=DEFAULT_POLITE_EMAIL)
Coordinates scholarly search across providers, enforces strict novelty against the local Zotero library, backfills abstracts, and resolves Open Access PDFs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
SearchProvider | None
|
SearchProvider instance (defaults to OpenAlexProvider). |
None
|
deduplicator
|
Deduplicator | None
|
Deduplicator instance with loaded library state. |
None
|
abstract_fallback
|
AbstractFallback | None
|
AbstractFallback instance for missing abstracts. |
None
|
unpaywall
|
UnpaywallResolver | None
|
UnpaywallResolver instance for OA PDF links. |
None
|
email
|
str
|
Polite pool email for upstream academic APIs. |
DEFAULT_POLITE_EMAIL
|
Source code in zocrates/discovery/engine.py
resolve_identifier
async
¶
Resolve a single paper by DOI, arXiv ID, or OpenAlex ID and check its library presence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or OpenAlex ID string. |
required |
Returns:
| Type | Description |
|---|---|
tuple[CandidatePaper | None, bool]
|
Tuple of (CandidatePaper or None, in_library boolean). |
Source code in zocrates/discovery/engine.py
search
async
¶
Search for scholarly literature, filtering out papers already in the library and enriching top results with abstracts and OA PDF URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Free-text search terms or conceptual query. |
required |
limit
|
int
|
Target number of novel candidate papers to return. |
10
|
year_from
|
int | None
|
Optional starting publication year. |
None
|
year_to
|
int | None
|
Optional ending publication year. |
None
|
is_oa_only
|
bool
|
Restrict results to open-access papers. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of novel CandidatePaper instances (at most |
Source code in zocrates/discovery/engine.py
OpenAlexProvider ¶
Bases: SearchProvider
Primary search provider backed by the OpenAlex REST API. Indexes 250M+ scholarly works, arXiv preprints, and open-access metadata.
Initialize the OpenAlex search provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email for polite-pool API requests. |
DEFAULT_POLITE_EMAIL
|
rate_limiter
|
TokenBucketRateLimiter | None
|
Token bucket rate limiter instance. |
None
|
timeout
|
float
|
HTTP request timeout in seconds. |
15.0
|
api_key
|
str | None
|
Optional OpenAlex premium API key. |
None
|
Source code in zocrates/discovery/providers/openalex.py
extract_arxiv_id_from_work
staticmethod
¶
Extract canonical arXiv ID without version suffix from an OpenAlex work record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work
|
dict[str, Any]
|
OpenAlex work dictionary. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Canonical lowercase arXiv ID without 'v' suffix (e.g. '2305.12345'), or None. |
Source code in zocrates/discovery/providers/openalex.py
reconstruct_abstract
staticmethod
¶
Reconstruct plain-text abstract from an OpenAlex abstract_inverted_index dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inverted_index
|
dict[str, list[int]] | None
|
Mapping of words to their token position indices. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Coherent, human-readable abstract string, or None if empty/invalid. |
Source code in zocrates/discovery/providers/openalex.py
resolve_identifier
async
¶
Resolve a paper by DOI, arXiv ID, or OpenAlex ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or OpenAlex ID. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper | None
|
Resolved CandidatePaper, or None if not found. |
Source code in zocrates/discovery/providers/openalex.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
search
async
¶
Execute free-text or conceptual search against OpenAlex works.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User search query string. |
required |
limit
|
int
|
Maximum candidate works to return. |
10
|
year_from
|
int | None
|
Optional minimum publication year. |
None
|
year_to
|
int | None
|
Optional maximum publication year. |
None
|
is_oa_only
|
bool
|
Restrict to open-access papers. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of parsed CandidatePaper instances. |
Source code in zocrates/discovery/providers/openalex.py
SearchProvider ¶
Bases: ABC
Abstract base class for scholarly literature search providers.
resolve_identifier
abstractmethod
async
¶
Resolve a single scholarly paper by DOI, arXiv ID, or provider-specific ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or provider ID string. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper | None
|
CandidatePaper if resolved, or None if not found. |
Source code in zocrates/discovery/providers/base.py
search
abstractmethod
async
¶
Search for scholarly literature matching the query and filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Free-text search terms or conceptual query. |
required |
limit
|
int
|
Maximum number of candidate papers to return. |
10
|
year_from
|
int | None
|
Optional minimum publication year (inclusive). |
None
|
year_to
|
int | None
|
Optional maximum publication year (inclusive). |
None
|
is_oa_only
|
bool
|
When True, restrict results to open-access works. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of CandidatePaper instances. |
Source code in zocrates/discovery/providers/base.py
UnpaywallResolver ¶
Resolves open-access fulltext PDF URLs via the Unpaywall API.
Initialize the Unpaywall resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email used for polite-pool API requests. |
DEFAULT_POLITE_EMAIL
|
timeout
|
float
|
HTTP request timeout in seconds. |
5.0
|
Source code in zocrates/discovery/providers/unpaywall.py
resolve_pdf
async
¶
Query Unpaywall for a legal, direct Open Access PDF URL for the given DOI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doi
|
str
|
Digital Object Identifier (canonical or raw). |
required |
email
|
str | None
|
User or developer email for polite pool identification. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Direct PDF URL string if available and verified, or None. |
Source code in zocrates/discovery/providers/unpaywall.py
get_default_discovery_engine ¶
Instantiate a configured DiscoveryEngine with local Zotero deduplication.