> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Arxiv 集成

> 使用 LangChain Python 与 Arxiv 检索器集成。

> [arXiv](https://arxiv.org/) 是一个开放获取的档案库，收录了物理学、数学、计算机科学、定量生物学、定量金融学、统计学、电气工程与系统科学以及经济学领域的 200 万篇学术论文。

本笔记本展示了如何从 Arxiv.org 检索科学文章，并将其转换为下游使用的 [Document](https://reference.langchain.com/python/langchain-core/documents/base/Document) 格式。

有关所有 `ArxivRetriever` 功能和配置的详细文档，请前往 [API 参考](https://reference.langchain.com/python/langchain-community/retrievers/arxiv/ArxivRetriever)。

### 集成详情

<ItemTable category="external_retrievers" item="ArxivRetriever" />

## 设置

如果您想从单个查询中获得自动跟踪，也可以取消注释以下内容来设置您的 [LangSmith](/langsmith/home) API 密钥：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### 安装

此检索器位于 `langchain-community` 包中。我们还需要 [arxiv](https://pypi.org/project/arxiv/) 依赖项：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-community arxiv
```

## 实例化

`ArxivRetriever` 参数包括：

* 可选的 `load_max_docs`：默认=100。用于限制下载的文档数量。下载所有 100 篇文档需要时间，因此在实验时请使用较小的数字。目前硬性限制为 300。
* 可选的 `load_all_available_meta`：默认=False。默认情况下，仅下载最重要的字段：`Published`（文档发布/最后更新的日期）、`Title`、`Authors`、`Summary`。如果为 True，则也会下载其他字段。
* `get_full_documents`：布尔值，默认为 False。决定是否获取文档的全文。

更多详情请参阅 [API 参考](https://reference.langchain.com/python/langchain-community/retrievers/arxiv/ArxivRetriever)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.retrievers import ArxivRetriever

retriever = ArxivRetriever(
    load_max_docs=2,
    get_full_documents=True,
)
```

## 用法

`ArxivRetriever` 支持通过文章标识符进行检索：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs = retriever.invoke("1605.08386")
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs[0].metadata  # Document 的元信息
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'Entry ID': 'http://arxiv.org/abs/1605.08386v1',
 'Published': datetime.date(2016, 5, 26),
 'Title': 'Heat-bath random walks with Markov bases',
 'Authors': 'Caprice Stanley, Tobias Windisch'}
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs[0].page_content[:400]  # Document 的内容
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
'Graphs on lattice points are studied whose edges come from a finite set of\nallowed moves of arbitrary length. We show that the diameter of these graphs on\nfibers of a fixed integer matrix can be bounded from above by a constant. We\nthen study the mixing behaviour of heat-bath random walks on these graphs. We\nalso state explicit conditions on the set of moves so that the heat-bath random\nwalk, a ge'
```

`ArxivRetriever` 也支持基于自然语言文本的检索：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs = retriever.invoke("What is the ImageBind model?")
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs[0].metadata
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{'Entry ID': 'http://arxiv.org/abs/2305.05665v2',
 'Published': datetime.date(2023, 5, 31),
 'Title': 'ImageBind: One Embedding Space To Bind Them All',
 'Authors': 'Rohit Girdhar, Alaaeldin El-Nouby, Zhuang Liu, Mannat Singh, Kalyan Vasudev Alwala, Armand Joulin, Ishan Misra'}
```

***

## API 参考

有关所有 `ArxivRetriever` 功能和配置的详细文档，请前往 [API 参考](https://reference.langchain.com/python/langchain-community/retrievers/arxiv/ArxivRetriever)。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/retrievers/arxiv.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
