Skip to main content

LangChain retriever for the arXiv

Project description

langchain-arxiv-retriever

A LangChain retriever for the arXiv API.

pip install langchain-arxiv-retriever
from langchain_arxiv import ArxivRetriever

retriever = ArxivRetriever()
docs = retriever.invoke('ti:"attention is all you need"')

One Document per paper, in arXiv's relevance order. Three knobs, one metadata schema, typed errors, nothing silent.

Documentation: https://j1c.github.io/langchain-arxiv-retriever/

Usage

Abstracts (default)

page_content is the paper's abstract — fast, no downloads:

retriever = ArxivRetriever()          # k=3 papers by default
docs = retriever.invoke("grokking transformers", k=10)   # per-call override

Full text

page_content is the whole paper. Text comes from arXiv's native HTML rendering when available and from the PDF otherwise; metadata["source_format"] tells you which ("html" or "pdf"):

full = ArxivRetriever(full_text=True, k=2)
docs = full.invoke("2404.19756")
docs[0].metadata["content_length"]   # 140369 — never silently cut

Need both modes? Instances are stateless and cheap — make two. For runtime switching inside a chain, use LangChain's standard configurable_fields mechanism on full_text.

Fetch by arXiv ID

A query consisting only of arXiv identifiers is fetched directly instead of searched:

retriever.invoke("1706.03762")            # new-style ID
retriever.invoke("quant-ph/9508027")      # old-style ID
retriever.invoke("2305.05665 2404.19756") # several at once

Query semantics

Queries go to the arXiv API verbatim. Everything in the arXiv API manual works: ti:, abs:, au:, cat:, all:, AND/OR/ANDNOT, quoted phrases.

Be aware that arXiv search is lexical, not semantic. Keyword-style queries retrieve well; conversational questions don't.

Metadata schema

Identical keys in both modes, snake_case, JSON-serializable:

Key Type Notes
entry_id str Canonical abs URL, e.g. http://arxiv.org/abs/2305.05665v2 (also the Document.id)
arxiv_id str Short ID with version, e.g. 2305.05665v2
version int | None Parsed from the ID
title, summary str summary is the abstract, in both modes
authors list[str]
published, updated str ISO dates: first submission / this version
primary_category str e.g. cs.LG
categories list[str]
doi, journal_ref, comment str | None None when absent
pdf_url str | None
content_length int Length of page_content in chars
token_estimate int content_length // 4
truncated bool True only if max_content_chars fired
source_format str "abstract", "html", or "pdf"

Why not langchain-community's ArxivRetriever?

This package exists because langchain-community has been deprecated and is no longer maintained, and uses deprecated functions from arxiv-py. Lastly, the community implementation has accumulated footguns:

langchain-community langchain-arxiv-retriever
"Full documents" mode Silently truncated at 4,000 chars (doc_content_chars_max default) — about a page and a half Whole text by default; truncation only if you opt in, and then it's flagged in metadata
Full-text source PDF only, parsed with PyMuPDF (AGPL) arXiv's native HTML when it exists (most papers since Dec 2023), pypdf (BSD) fallback — permissive licenses only
arXiv field syntax (ti:, cat:, …) Strips : and - from queries in full-text mode, breaking it Queries pass through verbatim
Query length Silently cut at 300 chars Untouched
Metadata Different keys, casing, and value types per mode One snake_case schema, both modes
Errors Returned as a fake Document ("Arxiv exception: …") that flows into your prompt Raised, always, as typed exceptions
API traffic Fetches 100 results per request regardless of k; re-downloads PDFs to disk on every call Fetches what k needs; downloads stay in memory; nothing written to disk

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_arxiv_retriever-1.0.0.tar.gz (530.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_arxiv_retriever-1.0.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_arxiv_retriever-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_arxiv_retriever-1.0.0.tar.gz
  • Upload date:
  • Size: 530.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for langchain_arxiv_retriever-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a99107f02ad7849557373dceff0d8a29bd311a244f9d7106b55769d4ba43ddc3
MD5 bb40b5fe64241b9858cb72b6c0bc4640
BLAKE2b-256 3e9ec408a585669fc3d808c1e25ce97c48bd01452b293c03edb8dfa53f0ad0ae

See more details on using hashes here.

File details

Details for the file langchain_arxiv_retriever-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_arxiv_retriever-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for langchain_arxiv_retriever-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e158a97af655630532dc961e313bf7559c0f1ea3b3aa93008715254d2754b9f
MD5 3903af8b7cdc7ae4ad98ef743132769f
BLAKE2b-256 073a3ff553da16dc391ed5369a3520d48d72e0c7196925cbf262fd60533f863a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page