> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/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 - 下载](https://img.shields.io/pypi/dm/langchain_nvidia_ai_endpoints?style=flat-square\&label=%20) | ![PyPI - 版本](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={null}
pip install -qU langchain-nvidia-ai-endpoints
```

## 实例化

```python theme={null}
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={null}
docs = retriever.invoke("What is NVIDIA NIM?")
for doc in docs:
    print(doc.page_content)
```

也支持异步检索：

```python theme={null}
docs = await retriever.ainvoke("What is NVIDIA NIM?")
```

## 在链中使用

```python theme={null}
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 提供者页面](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/providers/nvidia.md)
* [`ChatNVIDIA` 集成](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/nvidia_ai_endpoints)
* [`NVIDIAEmbeddings` 集成](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/embeddings/nvidia_ai_endpoints)
* [NVIDIA RAG Blueprint 文档](https://docs.nvidia.com/rag/latest/index.html)

***

> 官方原文：[src/oss/python/integrations/retrievers/nvidia.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/retrievers/nvidia.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.