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

# Microsoft 集成

> 使用 LangChain Python 与 Microsoft 集成。

本页涵盖了所有 LangChain 与 [Microsoft Azure](https://portal.azure.com) 和其他 [Microsoft](https://www.microsoft.com) 产品的集成。

<Tip>
  **推荐：Azure OpenAI**

  我们建议在 [聊天模型](#chat-models)、[LLMs](#llms) 和 [嵌入模型](#embedding-models) 中使用 [Azure OpenAI](https://reference.langchain.com/python/langchain-openai/llms/azure/AzureOpenAI)。通过 [v1 API](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/api-version-lifecycle?tabs=python)（自 2025 年 8 月起正式发布），您可以直接使用您的 Azure 端点和 API 密钥，通过 [`langchain-openai`](https://reference.langchain.com/python/langchain-openai/) 包，通过单一接口调用部署在 [Microsoft Foundry](https://learn.microsoft.com/en-us/azure/ai-foundry/) 中的任何模型（包括 OpenAI、Llama、DeepSeek、Mistral 和 Phi）。您还可以获得 Microsoft Entra ID 身份验证的原生支持，以及访问最新功能，包括 [Responses API](#responses-api) 和 [推理模型](/oss/python/integrations/chat/azure_chat_openai)。[从这里开始](#azure-openai)。

  **示例和教程：**

  * [Azure-Samples/langchain-azure-openai-starter](https://github.com/Azure-Samples/langchain-azure-openai-starter)：从一个生产就绪的 LangChain 和 Azure OpenAI 应用模板开始，该模板允许您使用单个 `azd` 命令直接部署到 Azure。
  * [microsoft/langchain-for-beginners](https://github.com/microsoft/langchain-for-beginners)：一门介绍 LangChain 与 Azure OpenAI 的实践课程。
  * [Azure-Samples/langchain-agent-python](https://github.com/Azure-Samples/langchain-agent-python)：在 Azure 上构建和部署 LangChain 代理。
</Tip>

<Note>
  **Azure 上的 Claude**

  Microsoft Foundry 还提供对所有 [Anthropic Claude 模型](https://learn.microsoft.com/en-us/azure/foundry/foundry-models/how-to/use-foundry-models-claude) 的访问，包括 Opus、Sonnet 和 Haiku。Claude 模型通过专用的 Anthropic 原生端点提供服务，而不是 Azure OpenAI v1 API。使用 [`langchain-anthropic`](/oss/python/integrations/chat/anthropic) 指向您的 Foundry Anthropic 端点。
</Note>

## 聊天模型

Microsoft 提供三种主要选项，用于通过 Azure 访问聊天模型：

1. **[Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/)**（推荐）— 通过单一接口访问部署在 Microsoft Foundry 中的任何模型（包括 OpenAI、Llama、DeepSeek、Mistral 和 Phi），并具备企业功能，例如通过 [Microsoft Entra ID](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/managed-identity) 进行无密钥身份验证、区域数据驻留和私有网络。在 v1 API 上使用 [`ChatOpenAI`](https://reference.langchain.com/python/langchain-openai/chat_models/base/ChatOpenAI)，或在传统部署中使用 [`AzureChatOpenAI`](https://reference.langchain.com/python/langchain-openai/chat_models/azure/AzureChatOpenAI)。

   Azure OpenAI 还支持 [Responses API](#responses-api)，它允许您直接从聊天模型访问服务器端工具，如代码解释器、图像生成和文件搜索。
2. **[Azure AI](https://learn.microsoft.com/en-us/azure/ai-studio/how-to/deploy-models)** — 推荐用于在聊天模型之外，访问更广泛 Azure 生态系统中的工具、存储和自定义中间件。
3. **[Azure ML](https://learn.microsoft.com/en-us/azure/machine-learning/)** — 允许使用 Azure Machine Learning 部署和管理自定义或微调的开源模型。

### Azure OpenAI

要开始使用 Azure OpenAI，请 [创建 Azure 部署](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource) 并安装 `langchain-openai` 包：

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-openai
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-openai
  ```
</CodeGroup>

在 v1 API 上，直接使用 [`ChatOpenAI`](https://reference.langchain.com/python/langchain-openai/chat_models/base/ChatOpenAI) 对接您的 Azure 端点——无需 `api_version`：

<Tabs>
  <Tab title="Entra ID（推荐）">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    pip install azure-identity
    ```

    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    from langchain_openai import ChatOpenAI

    token_provider = get_bearer_token_provider(
        DefaultAzureCredential(),
        "https://cognitiveservices.azure.com/.default",
    )

    llm = ChatOpenAI(
        model="gpt-5.4-mini",  # 您的 Azure 部署名称
        base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
        api_key=token_provider,  # 处理令牌刷新的可调用对象
    )
    ```
  </Tab>

  <Tab title="API 密钥">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from langchain_openai import ChatOpenAI

    llm = ChatOpenAI(
        model="gpt-5.4-mini",  # 您的 Azure 部署名称
        base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
        api_key="your-azure-api-key",
    )
    ```
  </Tab>
</Tabs>

对于传统的 Azure OpenAI API 版本，请使用 [`AzureChatOpenAI`](https://reference.langchain.com/python/langchain-openai/chat_models/azure/AzureChatOpenAI)：

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

有关端到端设置、Entra ID 身份验证、工具调用和推理示例，请参阅 [Azure ChatOpenAI 集成页面](/oss/python/integrations/chat/azure_chat_openai)。

#### Responses API

Azure OpenAI 支持 [Responses API](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/responses)，它提供有状态对话、内置工具（网络搜索、文件搜索、代码解释器）和结构化推理摘要。[`ChatOpenAI`](https://reference.langchain.com/python/langchain-openai/chat_models/base/ChatOpenAI) 在您设置 `reasoning` 参数时会自动路由到 Responses API，或者您也可以通过 `use_responses_api=True` 显式选择使用：

<Tabs>
  <Tab title="Entra ID（推荐）">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    from langchain_openai import ChatOpenAI

    token_provider = get_bearer_token_provider(
        DefaultAzureCredential(),
        "https://cognitiveservices.azure.com/.default",
    )

    llm = ChatOpenAI(
        model="gpt-5.4-mini",
        base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
        api_key=token_provider,
        use_responses_api=True,
    )

    response = llm.invoke("Summarize the bitter lesson.")
    print(response.text)
    ```
  </Tab>

  <Tab title="API 密钥">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from langchain_openai import ChatOpenAI

    llm = ChatOpenAI(
        model="gpt-5.4-mini",
        base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
        api_key="your-azure-api-key",
        use_responses_api=True,
    )

    response = llm.invoke("Summarize the bitter lesson.")
    print(response.text)
    ```
  </Tab>
</Tabs>

有关使用 Responses API 进行推理努力、推理摘要和流式传输的演练，请参阅 [Azure ChatOpenAI 集成页面](/oss/python/integrations/chat/azure_chat_openai)。

### Azure AI

> [Azure AI Foundry](https://learn.microsoft.com/en-us/azure/developer/python/get-started) 是更广泛的 Azure AI 平台。`langchain-azure-ai` 包允许您将 Azure 原生工具、存储和自定义中间件引入您的 LangChain 应用，并通过 `AzureAIOpenAIApiChatModel` 类公开部署在 Foundry 中的聊天模型。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-azure-ai
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-ai
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/chat/azure_ai)。

### Azure ML 聊天在线端点

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-community
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-community
  ```
</CodeGroup>

有关访问托管在 [Azure Machine Learning](https://azure.microsoft.com/en-us/products/machine-learning/) 上的聊天模型，请参阅 [Azure ML 聊天端点文档](/oss/python/integrations/chat/azureml_chat_endpoint)。

## LLMs

Microsoft 提供两种主要选项，用于通过 Azure 访问 LLMs：

1. **[Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/)**（推荐）— 使用 [`AzureOpenAI`](https://reference.langchain.com/python/langchain-openai/llms/azure/AzureOpenAI) 将部署在 Microsoft Foundry 中的任何模型（包括 OpenAI、Llama、DeepSeek、Mistral 和 Phi）作为补全 LLM 访问。
2. **[Azure ML](https://learn.microsoft.com/en-us/azure/machine-learning/)** — 使用托管在 Azure Machine Learning 在线端点上的自定义或开源模型。

### Azure OpenAI

查看 [使用示例](/oss/python/integrations/llms/azure_openai)。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-openai
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-openai
  ```
</CodeGroup>

<Tabs>
  <Tab title="Entra ID（推荐）">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    from langchain_openai import AzureOpenAI

    token_provider = get_bearer_token_provider(
        DefaultAzureCredential(),
        "https://cognitiveservices.azure.com/.default",
    )

    llm = AzureOpenAI(
        azure_deployment="gpt-5.4-mini",  # 您的 Azure 部署名称
        api_version="2025-04-01-preview",
        azure_ad_token_provider=token_provider,
    )

    print(llm.invoke("Write a haiku about the ocean."))
    ```
  </Tab>

  <Tab title="API 密钥">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from langchain_openai import AzureOpenAI

    llm = AzureOpenAI(
        azure_deployment="gpt-5.4-mini",  # 您的 Azure 部署名称
        api_version="2025-04-01-preview",
        azure_endpoint="https://YOUR-RESOURCE-NAME.openai.azure.com/",
        api_key="your-azure-api-key",
    )

    print(llm.invoke("Write a haiku about the ocean."))
    ```
  </Tab>
</Tabs>

### Azure ML

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-community
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-community
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/llms/azure_ml)。

## 嵌入模型

Microsoft 提供两种主要选项，用于通过 Azure 访问嵌入模型：

1. **[Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/)**（推荐）— 使用 [`AzureOpenAIEmbeddings`](https://reference.langchain.com/python/langchain-openai/embeddings/azure/AzureOpenAIEmbeddings) 访问部署在 Microsoft Foundry 中的嵌入模型（包括 OpenAI `text-embedding-3-small`、`text-embedding-3-large` 和 Cohere）。
2. **[Azure AI](https://learn.microsoft.com/en-us/azure/ai-studio/how-to/deploy-models)** — 推荐用于在嵌入模型之外，访问更广泛 Azure 生态系统中的工具、存储和自定义中间件。

### Azure OpenAI

查看 [使用示例](/oss/python/integrations/embeddings/azure_openai)。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-openai
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-openai
  ```
</CodeGroup>

<Tabs>
  <Tab title="Entra ID（推荐）">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from azure.identity import DefaultAzureCredential, get_bearer_token_provider
    from langchain_openai import AzureOpenAIEmbeddings

    token_provider = get_bearer_token_provider(
        DefaultAzureCredential(),
        "https://cognitiveservices.azure.com/.default",
    )

    embeddings = AzureOpenAIEmbeddings(
        azure_deployment="text-embedding-3-small",  # 您的 Azure 部署名称
        api_version="2025-04-01-preview",
        azure_ad_token_provider=token_provider,
    )

    vector = embeddings.embed_query("LangChain makes agents easy.")
    ```
  </Tab>

  <Tab title="API 密钥">
    ```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    from langchain_openai import AzureOpenAIEmbeddings

    embeddings = AzureOpenAIEmbeddings(
        azure_deployment="text-embedding-3-small",  # 您的 Azure 部署名称
        api_version="2025-04-01-preview",
        azure_endpoint="https://YOUR-RESOURCE-NAME.openai.azure.com/",
        api_key="your-azure-api-key",
    )

    vector = embeddings.embed_query("LangChain makes agents easy.")
    ```
  </Tab>
</Tabs>

### Azure AI

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-azure-ai
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-ai
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/providers/azure_ai#azure-ai-model-inference-for-embeddings)。

## 中间件

### Azure AI 内容安全中间件

> [Azure AI 内容安全](https://learn.microsoft.com/en-us/azure/ai-services/content-safety/overview) 提供护栏，您可以通过中间件将其应用于 LangChain 代理。`langchain-azure-ai` 包目前导出用于文本审核、图像审核、提示注入检测、受保护材料检测和基础性评估的中间件。

安装中间件包：

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-azure-ai
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-ai
  ```
</CodeGroup>

参阅 [Microsoft Foundry 中间件指南](/oss/python/integrations/middleware/azure_ai)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_azure_ai.agents.middleware import AzureContentModerationMiddleware
```

## 文档加载器

### Azure AI 数据

> [Azure AI Foundry（前身为 Azure AI Studio](https://ai.azure.com/) 提供将数据资产上传到云存储并从以下来源注册现有数据资产的功能：
>
> * `Microsoft OneLake`
> * `Azure Blob Storage`
> * `Azure Data Lake gen 2`

首先，您需要安装几个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install azureml-fsspec, azure-ai-generative
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add azureml-fsspec, azure-ai-generative
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/document_loaders/azure_ai_data)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.document_loaders import AzureAIDataLoader
```

### Azure AI 文档智能

> [Azure AI 文档智能](https://aka.ms/doc-intelligence)（前身为 `Azure Form Recognizer`）是一项基于机器学习的服务，可从数字或扫描的 PDF、图像、Office 和 HTML 文件中提取文本（包括手写体）、表格、文档结构和键值对。
>
> 文档智能支持 `PDF`、`JPEG/JPG`、`PNG`、`BMP`、`TIFF`、`HEIF`、`DOCX`、`XLSX`、`PPTX` 和 `HTML`。

首先，您需要安装一个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install azure-ai-documentintelligence
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add azure-ai-documentintelligence
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/document_loaders/azure_document_intelligence)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.document_loaders import AzureAIDocumentIntelligenceLoader
```

### Azure Blob Storage

> [Azure Blob Storage](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction) 是 Microsoft 的云对象存储解决方案。Blob Storage 针对存储海量非结构化数据进行了优化。非结构化数据是指不遵循特定数据模型或定义的数据，例如文本或二进制数据。

`Azure Blob Storage` 设计用于：

* 直接向浏览器提供图像或文档。
* 存储用于分布式访问的文件。
* 流式传输视频和音频。
* 写入日志文件。
* 存储用于备份和恢复、灾难恢复和归档的数据。
* 存储用于本地或 Azure 托管服务分析的数据。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-azure-storage
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-storage
  ```
</CodeGroup>

查看 [Azure Blob Storage 加载器使用示例](/oss/python/integrations/document_loaders/azure_blob_storage)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_azure_storage.document_loaders import AzureBlobStorageLoader
```

### Microsoft OneDrive

> [Microsoft OneDrive](https://en.wikipedia.org/wiki/OneDrive)（前身为 `SkyDrive`）是 Microsoft 运营的文件托管服务。

首先，您需要安装一个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install o365
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add o365
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/document_loaders/microsoft_onedrive)。

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

### Microsoft OneDrive 文件

> [Microsoft OneDrive](https://en.wikipedia.org/wiki/OneDrive)（前身为 `SkyDrive`）是 Microsoft 运营的文件托管服务。

首先，您需要安装一个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install o365
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add o365
  ```
</CodeGroup>

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

### Microsoft Word

> [Microsoft Word](https://www.microsoft.com/en-us/microsoft-365/word) 是 Microsoft 开发的文字处理器。

查看 [使用示例](/oss/python/integrations/document_loaders/microsoft_word)。

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

### Microsoft Excel

> [Microsoft Excel](https://en.wikipedia.org/wiki/Microsoft_Excel) 是 Microsoft 为 Windows、macOS、Android、iOS 和 iPadOS 开发的电子表格编辑器。
> 它具有计算或计算功能、图表工具、数据透视表以及称为 Visual Basic for Applications (VBA) 的宏编程语言。Excel 是 Microsoft 365 软件套件的一部分。

`UnstructuredExcelLoader` 用于加载 `Microsoft Excel` 文件。该加载器适用于 `.xlsx` 和 `.xls` 文件。
页面内容将是 Excel 文件的原始文本。如果您在 `"elements"` 模式下使用加载器，Excel 文件的 HTML 表示形式将在文档元数据的 `text_as_html` 键下可用。

查看 [使用示例](/oss/python/integrations/document_loaders/microsoft_excel)。

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

### Microsoft SharePoint

> [Microsoft SharePoint](https://en.wikipedia.org/wiki/SharePoint) 是一个基于网站的协作系统，使用工作流应用程序、“列表”数据库和其他 Web 部件及安全功能来赋能业务团队协同工作，由 Microsoft 开发。

查看 [使用示例](/oss/python/integrations/document_loaders/microsoft_sharepoint)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders.sharepoint import SharePointLoader
```

### Microsoft PowerPoint

> [Microsoft PowerPoint](https://en.wikipedia.org/wiki/Microsoft_PowerPoint) 是 Microsoft 的演示文稿程序。

查看 [使用示例](/oss/python/integrations/document_loaders/microsoft_powerpoint)。

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

### Microsoft OneNote

首先，让我们安装依赖项：

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install bs4 msal
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add bs4 msal
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/document_loaders/microsoft_onenote)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders.onenote import OneNoteLoader
```

### Playwright URL 加载器

> [Playwright](https://github.com/microsoft/playwright) 是一个开源自动化工具，由 `Microsoft` 开发，允许您以编程方式控制和自动化 Web 浏览器。它专为跨各种 Web 浏览器（如 `Chromium`、`Firefox` 和 `WebKit`）的端到端测试、抓取和自动化任务而设计。

首先，让我们安装依赖项：

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install playwright unstructured
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add playwright unstructured
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/document_loaders/url/#playwright-url-loader)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders.onenote import OneNoteLoader
```

## 记忆

### Azure Cosmos DB 聊天消息历史记录

> [Azure Cosmos DB](https://learn.microsoft.com/azure/cosmos-db/) 为对话式 AI 应用程序提供聊天消息历史记录存储，使您能够以低延迟和高可用性持久化和检索对话历史记录。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-azure-cosmosdb
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-cosmosdb
  ```
</CodeGroup>

配置您的 Azure Cosmos DB 连接（同步或异步，使用访问密钥或 Microsoft Entra ID）：

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

history = CosmosDBChatMessageHistory(
    cosmos_endpoint="https://<your-account>.documents.azure.com:443/",
    cosmos_database="<your-database>",
    cosmos_container="<your-container>",
    session_id="<session-id>",
    user_id="<user-id>",
    credential="<your-key-or-token-credential>",
    ttl=3600,  # 可选：消息在 1 小时后过期
)
history.prepare_cosmos()

history.add_user_message("Hello!")
history.add_ai_message("Hi there!")
```

对于异步用法，请从同一包导入 `AsyncCosmosDBChatMessageHistory`。

### Azure Cosmos DB 语义缓存

> [`AzureCosmosDBNoSqlSemanticCache`](https://github.com/langchain-ai/langchain-azure/tree/main/libs/azure-cosmosdb) 使用向量相似性在 Azure Cosmos DB for NoSQL 中缓存 LLM 响应，当再次看到语义相似的提示时返回缓存结果。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-azure-cosmosdb
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-cosmosdb
  ```
</CodeGroup>

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from azure.cosmos import CosmosClient, PartitionKey
from langchain_core.globals import set_llm_cache
from langchain_azure_cosmosdb import AzureCosmosDBNoSqlSemanticCache

cosmos_client = CosmosClient("<endpoint>", "<key>")

cache = AzureCosmosDBNoSqlSemanticCache(
    cosmos_client=cosmos_client,
    embedding=embedding,
    vector_embedding_policy=vector_embedding_policy,
    indexing_policy=indexing_policy,
    cosmos_container_properties={"partition_key": PartitionKey(path="/id")},
    cosmos_database_properties={"id": "cache-db"},
    vector_search_fields={"text_field": "text", "embedding_field": "embedding"},
    database_name="cache-db",
    container_name="cache-container",
)

set_llm_cache(cache)
```

对于异步用法，请导入 `AsyncAzureCosmosDBNoSqlSemanticCache`。

## 向量存储

### Azure Cosmos DB

AI 代理可以依赖 Azure Cosmos DB 作为统一的 [记忆系统](https://learn.microsoft.com/en-us/azure/cosmos-db/ai-agents#memory-can-make-or-break-agents) 解决方案，享受速度、规模和简单性。该服务成功 [支持了 OpenAI 的 ChatGPT 服务](https://www.youtube.com/watch?v=6IIUtEFKJec\&t) 以高可靠性和低维护性动态扩展。它由原子记录序列引擎驱动，是世界上第一个提供无服务器模式的全球分布式 [NoSQL](https://learn.microsoft.com/en-us/azure/cosmos-db/distributed-nosql)、[关系型](https://learn.microsoft.com/en-us/azure/cosmos-db/distributed-relational) 和 [向量数据库](https://learn.microsoft.com/en-us/azure/cosmos-db/vector-database) 服务。

以下是两个可用的 Azure Cosmos DB API，可提供向量存储功能。

#### Azure Cosmos DB for MongoDB (vCore)

> [Azure Cosmos DB for MongoDB vCore](https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/) 使创建具有完整原生 MongoDB 支持的数据库变得轻而易举。
> 您可以应用您的 MongoDB 经验，并通过将应用程序指向 API for MongoDB vCore 帐户的连接字符串，继续使用您喜爱的 MongoDB 驱动程序、SDK 和工具。
> 在 Azure Cosmos DB for MongoDB vCore 中使用向量搜索，将您的基于 AI 的应用程序与存储在 Azure Cosmos DB 中的数据无缝集成。

##### 安装和设置

参阅 [详细配置说明](/oss/python/integrations/vectorstores/azure_cosmos_db_mongo_vcore)。

我们需要安装 `langchain-azure-ai` 和 `pymongo` python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-azure-ai pymongo
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-ai pymongo
  ```
</CodeGroup>

##### 在 Microsoft Azure 上部署 Azure Cosmos DB

Azure Cosmos DB for MongoDB vCore 为开发人员提供了一个完全托管的 MongoDB 兼容数据库服务，用于使用熟悉的架构构建现代应用程序。

通过 Cosmos DB for MongoDB vCore，开发人员在迁移现有应用程序或构建新应用程序时，可以享受原生 Azure 集成、低总拥有成本 (TCO) 和熟悉的 vCore 架构的优势。

[免费注册](https://azure.microsoft.com/en-us/free/) 以立即开始。

查看 [使用示例](/oss/python/integrations/vectorstores/azure_cosmos_db_mongo_vcore)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_azure_ai.vectorstores import AzureCosmosDBMongoVCoreVectorSearch
```

#### Azure Cosmos DB NoSQL

> [Azure Cosmos DB for NoSQL](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/vector-search) 现在预览提供向量索引和搜索。
> 此功能旨在处理高维向量，能够在任何规模下实现高效准确的向量搜索。您现在可以直接将向量存储在文档中，与您的数据并列。这意味着您数据库中的每个文档不仅可以包含传统的无模式数据，还可以包含高维向量作为文档的其他属性。这种数据和向量的同地存储允许高效的索引和搜索，因为向量存储在与其所代表的数据相同的逻辑单元中。这简化了数据管理、AI 应用程序架构以及基于向量操作的效率。

##### 安装和设置

参阅 [详细配置说明](/oss/python/integrations/vectorstores/azure_cosmos_db_no_sql)。

我们需要安装 `langchain-azure-cosmosdb` 和 `azure-cosmos` python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-azure-cosmosdb azure-cosmos
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-cosmosdb azure-cosmos
  ```
</CodeGroup>

##### 在 Microsoft Azure 上部署 Azure Cosmos DB

Azure Cosmos DB 通过高度响应的动态和弹性自动扩展，为现代应用程序和智能工作负载提供了解决方案。它在每个 Azure 区域都可用，并且可以自动将数据复制到更靠近用户的位置。它具有 SLA 保证的低延迟和高可用性。

[免费注册](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/quickstart-python?pivots=devcontainer-codespace) 以立即开始。

查看 [使用示例](/oss/python/integrations/vectorstores/azure_cosmos_db_no_sql)。

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

### Azure Database for PostgreSQL

> [Azure Database for PostgreSQL - Flexible Server](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/service-overview) 是一种基于开源 Postgres 数据库引擎的关系数据库服务。它是一种完全托管的数据库即服务，可以处理关键任务工作负载，提供可预测的性能、安全性、高可用性和动态可扩展性。

参阅 [Azure Database for PostgreSQL 设置说明](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/quickstart-create-server-portal)。

只需使用来自您 Azure 门户的 [连接字符串](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/connect-python?tabs=cmd%2Cpassword#add-authentication-code)。

由于 Azure Database for PostgreSQL 是开源的 Postgres，您可以使用 [LangChain 的 Postgres 支持](/oss/python/integrations/vectorstores/pgvector/) 连接到 Azure Database for PostgreSQL。

### Azure SQL Database

> [Azure SQL Database](https://learn.microsoft.com/azure/azure-sql/database/sql-database-paas-overview?view=azuresql) 是一项强大的服务，结合了可扩展性、安全性和高可用性，提供了现代数据库解决方案的所有优势。它还提供专用的 Vector 数据类型和内置函数，简化了在关系数据库中直接存储和查询向量嵌入。这消除了对单独向量数据库和相关集成的需求，提高了解决方案的安全性，同时降低了整体复杂性。

通过利用您当前的 SQL Server 数据库进行向量搜索，您可以增强数据能力，同时最小化费用并避免迁移到新系统的挑战。

##### 安装和设置

参阅 [详细配置说明](/oss/python/integrations/vectorstores/sqlserver)。

我们需要安装 `langchain-sqlserver` python 包。

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
!pip install langchain-sqlserver==0.1.1
```

##### 在 Microsoft Azure 上部署 Azure SQL DB

[免费注册](https://learn.microsoft.com/azure/azure-sql/database/free-offer?view=azuresql) 以立即开始。

查看 [使用示例](/oss/python/integrations/vectorstores/sqlserver)。

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

### Azure AI Search

[Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search) 是一项云搜索服务，为开发人员提供基础设施、API 和工具，用于大规模检索向量、关键字和混合查询的信息。查看 [Azure AI Search 使用示例](/oss/python/integrations/vectorstores/azuresearch) 了解用法示例。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.vectorstores.azuresearch import AzureSearch
```

## 检索器

### Azure AI Search

> [Azure AI Search](https://learn.microsoft.com/en-us/azure/search/search-what-is-azure-search)（前身为 `Azure Search` 或 `Azure Cognitive Search`）是一项云搜索服务，为开发人员提供基础设施、API 和工具，用于在 Web、移动和企业应用程序中构建丰富的搜索体验，以搜索私有、异构内容。

> 搜索是任何向用户显示文本的应用程序的基础，常见场景包括目录或文档搜索、在线零售应用程序或对专有内容的数据探索。创建搜索服务时，您将使用以下功能：
>
> * 用于对包含用户自有内容的搜索索引进行全文搜索的搜索引擎
> * 丰富的索引功能，具有词法分析和可选的 AI 增强，用于内容提取和转换
> * 用于文本搜索、模糊搜索、自动完成、地理搜索等的丰富查询语法
> * 通过 REST API 和 Azure SDK 中的客户端库进行可编程性
> * 在数据层、机器学习层和 AI（AI Services）的 Azure 集成

参阅 [设置说明](https://learn.microsoft.com/en-us/azure/search/search-create-service-portal)。

查看 [使用示例](/oss/python/integrations/retrievers/azure_ai_search)。

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

## 向量存储

### Azure Database for PostgreSQL

> [Azure Database for PostgreSQL - Flexible Server](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/service-overview) 是一种基于开源 Postgres 数据库引擎的关系数据库服务。它是一种完全托管的数据库即服务，可以处理关键任务工作负载，提供可预测的性能、安全性、高可用性和动态可扩展性。

参阅 [Azure Database for PostgreSQL 设置说明](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/quickstart-create-server-portal)。

您需要在数据库中 [启用 pgvector 扩展](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/how-to-use-pgvector) 才能将 Postgres 用作向量存储。启用扩展后，您可以使用 [LangChain 中的 PGVector](/oss/python/integrations/vectorstores/pgvector/) 连接到 Azure Database for PostgreSQL。

查看 [使用示例](/oss/python/integrations/vectorstores/pgvector/)。只需使用来自您 Azure 门户的 [连接字符串](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/connect-python?tabs=cmd%2Cpassword#add-authentication-code)。

## 工具

### Azure Container Apps 动态会话

我们需要从 Azure Container Apps 服务获取 `POOL_MANAGEMENT_ENDPOINT` 环境变量。
参阅 [Azure 动态会话设置说明](/oss/python/integrations/tools/azure_dynamic_sessions/#setup)。

我们需要安装一个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-azure-dynamic-sessions
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-azure-dynamic-sessions
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/tools/azure_dynamic_sessions)。

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

### Bing 搜索

请遵循 [Bing 搜索工具文档](/oss/python/integrations/tools/bing_search) 获取有关此工具的详细说明和指导。

需要来自 Bing Search 资源的环境变量 `BING_SUBSCRIPTION_KEY` 和 `BING_SEARCH_URL`。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.tools.bing_search import BingSearchResults
from langchain_community.utilities import BingSearchAPIWrapper

api_wrapper = BingSearchAPIWrapper()
tool = BingSearchResults(api_wrapper=api_wrapper)
```

## 工具包

### Azure AI 服务

我们需要安装几个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install azure-ai-formrecognizer azure-cognitiveservices-speech azure-ai-vision-imageanalysis
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add azure-ai-formrecognizer azure-cognitiveservices-speech azure-ai-vision-imageanalysis
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/tools/azure_ai_services)。

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

#### Azure AI 服务单独工具

`azure_ai_services` 工具包包括以下工具：

* 图像分析：[AzureAiServicesImageAnalysisTool](https://reference.langchain.com/python/langchain-community/tools/azure_ai_services/image_analysis/AzureAiServicesImageAnalysisTool)
* 文档智能：[AzureAiServicesDocumentIntelligenceTool](https://reference.langchain.com/python/langchain-community/tools/azure_ai_services/document_intelligence/AzureAiServicesDocumentIntelligenceTool)
* 语音转文本：[AzureAiServicesSpeechToTextTool](https://reference.langchain.com/python/langchain-community/tools/azure_ai_services/speech_to_text/AzureAiServicesSpeechToTextTool)
* 文本转语音：[AzureAiServicesTextToSpeechTool](https://reference.langchain.com/python/langchain-community/tools/azure_ai_services/text_to_speech/AzureAiServicesTextToSpeechTool)
* 健康文本分析：[AzureAiServicesTextAnalyticsForHealthTool](https://reference.langchain.com/python/langchain-community/tools/azure_ai_services/text_analytics_for_health/AzureAiServicesTextAnalyticsForHealthTool)

### Azure 认知服务

我们需要安装几个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install azure-ai-formrecognizer azure-cognitiveservices-speech azure-ai-vision-imageanalysis
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add azure-ai-formrecognizer azure-cognitiveservices-speech azure-ai-vision-imageanalysis
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/tools/azure_cognitive_services)。

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

#### Azure AI 服务单独工具

`azure_ai_services` 工具包包括查询 `Azure Cognitive Services` 的工具：

* `AzureCogsFormRecognizerTool`：Form Recognizer API
* `AzureCogsImageAnalysisTool`：Image Analysis API
* `AzureCogsSpeech2TextTool`：Speech2Text API
* `AzureCogsText2SpeechTool`：Text2Speech API
* `AzureCogsTextAnalyticsHealthTool`：Text Analytics for Health API

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.tools.azure_cognitive_services import (
    AzureCogsFormRecognizerTool,
    AzureCogsImageAnalysisTool,
    AzureCogsSpeech2TextTool,
    AzureCogsText2SpeechTool,
    AzureCogsTextAnalyticsHealthTool,
)
```

### Microsoft Office 365 电子邮件和日历

我们需要安装 `O365` python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install O365
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add O365
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/tools/office365)。

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

#### Office 365 单独工具

您可以使用 Office 365 工具包中的单独工具：

* `O365CreateDraftMessage`：在 Office 365 中创建草稿电子邮件
* `O365SearchEmails`：在 Office 365 中搜索电子邮件消息
* `O365SearchEvents`：在 Office 365 中搜索日历事件
* `O365SendEvent`：在 Office 365 中发送日历事件
* `O365SendMessage`：在 Office 365 中发送电子邮件

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.tools.office365 import O365CreateDraftMessage
from langchain_community.tools.office365 import O365SearchEmails
from langchain_community.tools.office365 import O365SearchEvents
from langchain_community.tools.office365 import O365SendEvent
from langchain_community.tools.office365 import O365SendMessage
```

### Microsoft Azure PowerBI

我们需要安装 `azure-identity` python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install azure-identity
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add azure-identity
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/tools/powerbi)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.agent_toolkits import PowerBIToolkit
from langchain_community.utilities.powerbi import PowerBIDataset
```

#### PowerBI 单独工具

您可以使用 Azure PowerBI 工具包中的单独工具：

* `InfoPowerBITool`：获取有关 PowerBI 数据集的元数据
* `ListPowerBITool`：获取表名
* `QueryPowerBITool`：查询 PowerBI 数据集

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.tools.powerbi.tool import InfoPowerBITool
from langchain_community.tools.powerbi.tool import ListPowerBITool
from langchain_community.tools.powerbi.tool import QueryPowerBITool
```

### PlayWright 浏览器工具包

> [Playwright](https://github.com/microsoft/playwright) 是一个开源自动化工具，由 `Microsoft` 开发，允许您以编程方式控制和自动化 Web 浏览器。它专为跨各种 Web 浏览器（如 `Chromium`、`Firefox` 和 `WebKit`）的端到端测试、抓取和自动化任务而设计。

我们需要安装几个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install playwright lxml
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add playwright lxml
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/tools/playwright)。

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

#### PlayWright 浏览器单独工具

您可以使用 PlayWright 浏览器工具包中的单独工具。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.tools.playwright import ClickTool
from langchain_community.tools.playwright import CurrentWebPageTool
from langchain_community.tools.playwright import ExtractHyperlinksTool
from langchain_community.tools.playwright import ExtractTextTool
from langchain_community.tools.playwright import GetElementsTool
from langchain_community.tools.playwright import NavigateTool
from langchain_community.tools.playwright import NavigateBackTool
```

## 图

### Azure Cosmos DB for Apache Gremlin

我们需要安装一个 python 包。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install gremlinpython
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add gremlinpython
  ```
</CodeGroup>

查看 [使用示例](/oss/python/integrations/graphs/azure_cosmosdb_gremlin)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.graphs import GremlinGraph
from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship
```

## 实用工具

### Bing 搜索 API

> [Microsoft Bing](https://www.bing.com/)，通常称为 `Bing` 或 `Bing Search`，是由 `Microsoft` 拥有和运营的网络搜索引擎。

查看 [使用示例](/oss/python/integrations/tools/bing_search)。

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

## 更多

### Microsoft Presidio

> [Presidio](https://microsoft.github.io/presidio/)（源自拉丁语 praesidium ‘保护，驻军’）有助于确保敏感数据得到妥善管理和治理。它提供快速识别和匿名化模块，用于处理文本和图像中的私人实体，如信用卡号码、姓名、地址、社会安全号码、比特币钱包、美国电话号码、财务数据等。

首先，您需要安装几个 python 包并下载一个 `SpaCy` 模型。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker
  python -m spacy download en_core_web_lg
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-experimental openai presidio-analyzer presidio-anonymizer spacy Faker
  python -m spacy download en_core_web_lg
  ```
</CodeGroup>

查看 [使用示例](https://python.langchain.com/v0.1/docs/guides/productionization/safety/presidio_data_anonymization)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_experimental.data_anonymizer import PresidioAnonymizer, PresidioReversibleAnonymizer
```

***

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

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