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

# NVIDIARAGRetriever 集成

> 使用 LangChain Python 与 NVIDIARAGRetriever 进行集成。

`NVIDIARAGRetriever` 将 LangChain 连接到正在运行的 [NVIDIA RAG Blueprint](https://docs.nvidia.com/rag/latest/index.html) 服务器，并通过 `/v1/search` 端点检索相关文档。它支持同步和异步检索、重排序、查询重写和元数据过滤。

## 概述

### 集成详情

| 类                                                                                                                          | 包                                                                                                       |  本地 | 可序列化 | JS 支持 |                                                       下载量                                                      |                                                      版本                                                     |
| :------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------ | :-: | :--: | :---: | :------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: |
| [`NVIDIARAGRetriever`](https://reference.langchain.com/python/langchain-nvidia-ai-endpoints/retrievers/NVIDIARAGRetriever) | [`langchain-nvidia-ai-endpoints`](https://reference.langchain.com/python/langchain-nvidia-ai-endpoints) |  ✅  | beta |   ❌   | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain_nvidia_ai_endpoints?style=flat-square\&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain_nvidia_ai_endpoints?style=flat-square\&label=%20) |

## 设置

`NVIDIARAGRetriever` 需要一个正在运行的 NVIDIA RAG Blueprint 服务器。有关部署说明，请参阅 [NVIDIA RAG Blueprint 文档](https://docs.nvidia.com/rag/latest/index.html)。默认情况下，服务器监听 `http://localhost:8081`，并期望其向量数据库中至少有一个已摄入的集合。

检索器不需要 API 密钥；身份验证由 RAG 服务器处理。

### 安装

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-nvidia-ai-endpoints
```

## 实例化

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_nvidia_ai_endpoints import NVIDIARAGRetriever

retriever = NVIDIARAGRetriever(
    base_url="http://localhost:8081",
    k=4,
    collection_names=["my_collection"],
)
```

关键参数：

| 参数                       | 类型          | 默认值                   | 描述                       |
| ------------------------ | ----------- | --------------------- | ------------------------ |
| `base_url`               | `str`       | —                     | RAG Blueprint 服务器的基础 URL |
| `k`                      | `int`       | `10`                  | 返回的文档数量 (0–25)           |
| `collection_names`       | `list[str]` | `["multimodal_data"]` | 要搜索的向量数据库集合              |
| `vdb_top_k`              | `int`       | `100`                 | 重排序之前检索的结果 (0–400)       |
| `enable_reranker`        | `bool`      | `True`                | 启用检索结果的重排序               |
| `enable_query_rewriting` | `bool`      | `False`               | 在搜索前启用查询重写               |
| `confidence_threshold`   | `float`     | `0.0`                 | 包含文档的最小相关性分数 (0.0–1.0)   |
| `timeout`                | `float`     | `60`                  | HTTP 请求超时时间（秒）           |

## 用法

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs = retriever.invoke("What is NVIDIA NIM?")
for doc in docs:
    print(doc.page_content)
```

也支持异步检索：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs = await retriever.ainvoke("What is NVIDIA NIM?")
```

## 在链中使用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_nvidia_ai_endpoints import ChatNVIDIA, NVIDIARAGRetriever

retriever = NVIDIARAGRetriever(base_url="http://localhost:8081", k=4)
llm = ChatNVIDIA(model="meta/llama3-8b-instruct")

prompt = ChatPromptTemplate.from_template(
    "Answer the question based only on the following context:\n{context}\n\nQuestion: {question}"
)


def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)


chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

chain.invoke("What is NVIDIA NIM?")
```

## API 参考

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

## 相关主题

* [NVIDIA 提供商页面](/oss/python/integrations/providers/nvidia)
* [`ChatNVIDIA` 集成](/oss/python/integrations/chat/nvidia_ai_endpoints)
* [`NVIDIAEmbeddings` 集成](/oss/python/integrations/embeddings/nvidia_ai_endpoints)
* [NVIDIA RAG Blueprint 文档](https://docs.nvidia.com/rag/latest/index.html)

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\retrievers\nvidia.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
