API Reference
ArxivRetriever
langchain_arxiv.ArxivRetriever
Bases: BaseRetriever
Retriever for papers on arXiv <https://arxiv.org>__.
Returns one Document per paper, in arXiv's relevance order. By
default page_content is the paper's abstract; with
full_text=True it is the paper's full text, extracted from arXiv's
native HTML rendering when one exists (most papers submitted since
December 2023) and from the PDF via pypdf otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of papers to return. Can be overridden per call:
|
3
|
full_text
|
bool
|
If True, |
False
|
max_content_chars
|
int
|
Hard cap on |
required |
Raises:
| Type | Description |
|---|---|
ArxivAPIError
|
If the arXiv search API request fails. |
FullTextFetchError
|
In full-text mode, if neither the native HTML nor the PDF yields text for a paper. |
Notes
- Queries are passed to the arXiv API verbatim. Field syntax
(
ti:,abs:,au:,cat:,all:) and boolean operators work as documented in thearXiv API manual <https://info.arxiv.org/help/api/user-manual.html>__. arXiv's search is lexical, not semantic; keyword-style queries retrieve better than natural-language questions. - A query consisting only of arXiv identifiers (for example
"2305.05665"or"math/0211159v1") is fetched by ID instead of searched. - Content is never truncated silently. Set
max_content_charsto cap it; when the cap fires,metadata["truncated"]isTrue. - An error is never returned as a
Document. A query with zero matches returns an empty list. - The retriever is stateless: nothing is cached and nothing is
written to disk. Search requests observe arXiv's requested
courtesy rate (one request per three seconds) via the
arxivclient.
The metadata schema is identical in both modes: entry_id,
arxiv_id, version, title, authors, summary,
published, updated, primary_category, categories,
doi, journal_ref, comment, pdf_url, plus the content
descriptors content_length, token_estimate (a rough
chars / 4 heuristic), truncated, and source_format (one of
"abstract", "html", "pdf").
Examples:
>>> from langchain_arxiv import ArxivRetriever
>>> retriever = ArxivRetriever()
>>> docs = retriever.invoke('ti:"attention is all you need"')
>>> docs = retriever.invoke("2305.05665") # arXiv IDs fetch directly
>>> docs = retriever.invoke("grokking", k=10) # per-call k override
Whole papers instead of abstracts:
>>> full = ArxivRetriever(full_text=True, k=2)
>>> docs = full.invoke("kolmogorov-arnold networks")
>>> docs[0].metadata["source_format"]
'html'
k
class-attribute
instance-attribute
Number of papers to return. Override per call: retriever.invoke(query, k=10).
full_text
class-attribute
instance-attribute
If True, page_content is the paper's full text (native arXiv
HTML when available, PDF otherwise). If False, the abstract.
Exceptions
All failures raise one of these; an error is never encoded as a Document.
langchain_arxiv.ArxivRetrieverError
Bases: Exception
Base exception for all langchain-arxiv-retriever failures.
langchain_arxiv.ArxivAPIError
Bases: ArxivRetrieverError
The arXiv search API request failed.
Wraps the underlying cause (an arxiv.ArxivError or a
requests exception) as __cause__.
langchain_arxiv.FullTextFetchError
Bases: ArxivRetrieverError
Fetching or extracting a paper's full text failed.
Raised in full-text mode when neither the native arXiv HTML nor the
PDF yields text for a paper. The underlying cause, when there is one,
is available as __cause__.