> ## 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.

# EgnyteRetriever

> 这将帮助您开始使用 Egnyte retriever。有关所有 EgnyteRetriever 功能和配置的详细文档，请访问 API reference。

这将帮助您开始使用 Egnyte [retriever](https://langchain-docs-zh.mintlify.site/langchain/oss/deepagents/retrieval.md)。有关所有 `EgnyteRetriever` 功能和配置的详细文档，请访问 [API reference](https://github.com/egnyte/egnyte-langchain-connector)。

# 概述

`EgnyteRetriever` 类帮助您使用混合搜索功能（结合语义搜索和关键词搜索）从 Egnyte 搜索和检索文档。此检索器完全符合 LangChain 标准，并支持同步和异步操作。

### 集成细节

自带数据（即索引和搜索自定义文档集合）：

| 检索器 | 自托管 | 云服务 | 包 |
| :- | :- | :-: | :-: |
| [EgnyteRetriever](https://github.com/egnyte/egnyte-langchain-connector) | ❌ | ✅ | egnyte-langchain-connector |

## 设置

要使用 Egnyte 包，您需要：

* 一个 Egnyte 账户：如果您不是当前的 Egnyte 客户或希望在您的生产 Egnyte 实例之外进行测试，您可以使用 [免费开发者账户](https://developers.egnyte.com/member/register)。
* 一个 Egnyte 应用：这在 [开发者控制台](https://developers.egnyte.com/) 中配置，并且必须启用适当的范围。
* 该应用必须由管理员启用。对于免费开发者账户，这是注册该账户的人。

### 凭证

对于这些示例，我们将使用 Bearer token 身份验证和 Egnyte 用户 token。要生成用户 token：

1. 在 [https://developers.egnyte.com/member/register](https://developers.egnyte.com/member/register) 注册开发者账户
2. 按照 [Public API Authentication guide](https://developers.egnyte.com/docs/read/Public_API_Authentication) 生成用户 token
3. **重要**：在生成 token 时使用范围 `Egnyte.ai`

```python theme={null}
import getpass
import os

egnyte_user_token = getpass.getpass("Enter your Egnyte User Token: ")
domain = input("Enter your Egnyte domain (e.g., company.egnyte.com): ")
```

如果您希望从单个查询中获得自动跟踪，您也可以通过取消注释以下内容来设置您的 [LangSmith](https://docs.langchain.com/langsmith/observability) API 密钥：

```python theme={null}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### 安装

此检索器位于 `egnyte-langchain-connector` 包中：

```bash theme={null}
pip install -qU egnyte-langchain-connector
```

```output theme={null}
Note: you may need to restart the kernel to use updated packages.
```

## 实例化

现在我们可以实例化我们的检索器：

```python theme={null}
from langchain_egnyte import EgnyteRetriever

retriever = EgnyteRetriever(domain=domain, k=100)
```

## 使用

### 基本搜索

```python theme={null}
query = "machine learning policies"

documents = retriever.invoke(query, egnyte_user_token=egnyte_user_token)

for doc in documents:
    print(f"Title: {doc.metadata.get('title', 'N/A')}")
    print(f"Content: {doc.page_content[:200]}...")
    print("---")
```

### 带选项的高级搜索

对于更细粒度的搜索，您可以使用 `EgnyteSearchOptions` 通过文件夹路径、日期范围等进行结果过滤：

```python theme={null}
from langchain_egnyte import EgnyteRetriever, EgnyteSearchOptions

search_options = EgnyteSearchOptions(
    limit=50,
    folderPath="/policies",
    excludeFolderPaths=["/temp", "/archive"],
    createdAfter=1640995200000,  # Unix timestamp in milliseconds (Jan 1, 2022)
    createdBefore=1672531200000  # Unix timestamp in milliseconds (Jan 1, 2023)
)

retriever = EgnyteRetriever(
    domain=domain,
    k=50,
    search_options=search_options
)

documents = retriever.invoke(
    "compliance requirements",
    egnyte_user_token=egnyte_user_token
)
```

### 异步使用

检索器支持异步操作：

```python theme={null}
import asyncio

async def search_async():
    documents = await retriever.ainvoke(
        "data privacy guidelines",
        egnyte_user_token=egnyte_user_token
    )
    return documents

# Run async search
documents = asyncio.run(search_async())
```

### 批量操作

您可以批量处理多个查询：

```python theme={null}
queries = [
    "security policies",
    "employee handbook",
    "compliance guidelines"
]

# Synchronous batch
results = retriever.batch(
    queries,
    config={"configurable": {"egnyte_user_token": egnyte_user_token}}
)

# Asynchronous batch
results = await retriever.abatch(
    queries,
    config={"configurable": {"egnyte_user_token": egnyte_user_token}}
)
```

## 作为智能体工具使用

与其他检索器一样，EgnyteRetriever 可以作为工具添加到 LangGraph 智能体中。

```python theme={null}
from langchain_classic import hub
from langchain_classic.agents import AgentExecutor, create_openai_tools_agent
from langchain_classic.tools.retriever import create_retriever_tool
from langchain_openai import ChatOpenAI

retriever = EgnyteRetriever(domain=domain, k=50)

egnyte_search_tool = create_retriever_tool(
    retriever,
    "egnyte_search_tool",
    "This tool searches Egnyte and retrieves documents that match the search criteria using hybrid search"
)

tools = [egnyte_search_tool]

prompt = hub.pull("hwchase17/openai-tools-agent")
llm = ChatOpenAI(temperature=0)

agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

result = agent_executor.invoke({
    "input": "Find all documents related to data privacy policies"
})

print(result['output'])
```

***

## API 参考

有关所有 `EgnyteRetriever` 功能和配置的详细文档，请访问 [GitHub repository](https://github.com/egnyte/egnyte-langchain-connector)。

## 帮助

如果您有问题，请查看 [Egnyte developer documentation](https://developers.egnyte.com/) 或联系 Egnyte 开发者社区。

***

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


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