> ## 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 JavaScript 与 Microsoft 进行集成。

所有与 `Microsoft Azure` 及其他 `Microsoft` 产品相关的功能。

## 聊天模型

### Azure OpenAI

查看 [使用示例](/oss/javascript/integrations/chat/azure)

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureChatOpenAI } from "@langchain/openai";

const model = new AzureChatOpenAI({
  temperature: 0.9,
  azureOpenAIApiKey: "<your_key>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_KEY
  azureOpenAIApiInstanceName: "<your_instance_name>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_INSTANCE_NAME
  azureOpenAIApiDeploymentName: "<your_deployment_name>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME
  azureOpenAIApiVersion: "<api_version>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_VERSION
});
```

## 大语言模型

### Azure OpenAI

> [Microsoft Azure](https://en.wikipedia.org/wiki/Microsoft_Azure)，通常称为 `Azure`，是一个由 `Microsoft` 运营的云计算平台，通过全球数据中心提供对应用程序和服务的访问、管理和开发。它提供一系列功能，包括软件即服务 (SaaS)、平台即服务 (PaaS) 和基础设施即服务 (IaaS)。`Microsoft Azure` 支持多种编程语言、工具和框架，包括 Microsoft 特有的以及第三方软件和系统。

> [Azure OpenAI](https://azure.microsoft.com/products/ai-services/openai-service/) 是一项云服务，可帮助您利用来自 OpenAI、Meta 等的多样化预构建和精选模型，快速开发生成式 AI 体验。

LangChain.js 支持使用 [OpenAI SDK](https://github.com/openai/openai-node) 中的新 Azure 集成来与 [Azure OpenAI](https://azure.microsoft.com/products/ai-services/openai-service/) 集成。

您可以在 [此页面](https://learn.microsoft.com/azure/ai-services/openai/overview) 上了解更多关于 Azure OpenAI 及其与 OpenAI API 的区别。如果您没有 Azure 帐户，可以 [创建一个免费帐户](https://azure.microsoft.com/free/) 来开始使用。

您需要部署一个 Azure OpenAI 实例。您可以按照 [此指南](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) 在 Azure 门户上部署一个版本。

一旦您的实例运行起来，请确保您拥有实例的名称和密钥。您可以在 Azure 门户中，在实例的“密钥和终结点”部分找到密钥。

如果您使用 Node.js，可以定义以下环境变量来使用该服务：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
AZURE_OPENAI_API_INSTANCE_NAME=<YOUR_INSTANCE_NAME>
AZURE_OPENAI_API_DEPLOYMENT_NAME=<YOUR_DEPLOYMENT_NAME>
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=<YOUR_EMBEDDINGS_DEPLOYMENT_NAME>
AZURE_OPENAI_API_KEY=<YOUR_KEY>
AZURE_OPENAI_API_VERSION="2024-02-01"
```

<Info>
  **您可以在 [Azure OpenAI 文档](https://learn.microsoft.com/azure/ai-services/openai/reference) 中找到支持的 API 版本列表。**
</Info>

<Tip>
  请参阅 [此部分了解安装 LangChain 包的一般说明](/oss/javascript/langchain/install)。
</Tip>

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/openai @langchain/core
```

查看 [使用示例](/oss/javascript/integrations/llms/azure)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureOpenAI } from "@langchain/openai";

const model = new AzureOpenAI({
  azureOpenAIApiKey: "<your_key>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_KEY
  azureOpenAIApiInstanceName: "<your_instance_name>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_INSTANCE_NAME
  azureOpenAIApiDeploymentName: "<your_deployment_name>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME
  azureOpenAIApiVersion: "<api_version>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_VERSION
});
```

## 文本嵌入模型

### Azure OpenAI

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

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureOpenAIEmbeddings } from "@langchain/openai";

const model = new AzureOpenAIEmbeddings({
  azureOpenAIApiKey: "<your_key>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_KEY
  azureOpenAIApiInstanceName: "<your_instance_name>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_INSTANCE_NAME
  azureOpenAIApiEmbeddingsDeploymentName: "<your_embeddings_deployment_name>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME
  azureOpenAIApiVersion: "<api_version>", // 在 Node.js 中默认为 process.env.AZURE_OPENAI_API_VERSION
});
```

## 向量存储

### Azure AI 搜索

> [Azure AI 搜索](https://azure.microsoft.com/products/ai-services/ai-search)（前身为 Azure Search 和 Azure Cognitive Search）是一个分布式、RESTful 的搜索引擎，针对 Azure 上生产规模工作负载的速度和相关性进行了优化。它还支持使用 [k-近邻](https://en.wikipedia.org/wiki/Nearest_neighbor_search) (kNN) 算法进行向量搜索，以及 [语义搜索](https://learn.microsoft.com/azure/search/semantic-search-overview)。

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install -S @langchain/community @langchain/core @azure/search-documents
```

查看 [使用示例](/oss/javascript/integrations/vectorstores/azure_aisearch)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureAISearchVectorStore } from "@langchain/community/vectorstores/azure_aisearch";
```

### Azure Cosmos DB for NoSQL

> [Azure Cosmos DB for NoSQL](https://learn.microsoft.com/azure/cosmos-db/nosql/) 支持查询具有灵活架构的项，并原生支持 JSON。它现在提供向量索引和搜索功能。此功能旨在处理高维向量，能够在任何规模下实现高效准确的向量搜索。您现在可以直接将向量存储在文档中，与您的数据并列。数据库中的每个文档不仅可以包含传统的无模式数据，还可以包含作为文档其他属性的高维向量。

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/azure-cosmosdb @langchain/core
```

查看 [使用示例](/oss/javascript/integrations/vectorstores/azure_cosmosdb_nosql)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureCosmosDBNoSQLVectorStore } from "@langchain/azure-cosmosdb";
```

### Azure DocumentDB

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

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/azure-cosmosdb @langchain/core
```

查看 [使用示例](/oss/javascript/integrations/vectorstores/azure_documentdb)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureDocumentDBVectorStore } from "@langchain/azure-cosmosdb";
```

## 语义缓存

### Azure Cosmos DB NoSQL 语义缓存

> 语义缓存功能通过 Azure Cosmos DB for NoSQL 集成得到支持，使用户能够根据用户输入与先前缓存结果之间的语义相似性来检索缓存的响应。它利用 [AzureCosmosDBNoSQLVectorStore](/oss/javascript/integrations/vectorstores/azure_cosmosdb_nosql) 来存储缓存提示的向量嵌入。这些嵌入支持基于相似性的搜索，使系统能够检索相关的缓存结果。

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/azure-cosmosdb @langchain/core
```

查看 [使用示例](/oss/javascript/integrations/llm_caching/azure_cosmosdb_nosql)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureCosmosDBNoSQLSemanticCache } from "@langchain/azure-cosmosdb";
```

## 文档加载器

### Azure Blob 存储

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

> [Azure 文件](https://learn.microsoft.com/azure/storage/files/storage-files-introduction) 提供完全托管的
> 云文件共享，可通过行业标准的服务器消息块 (`SMB`) 协议、
> 网络文件系统 (`NFS`) 协议和 `Azure Files REST API` 进行访问。`Azure 文件` 基于 `Azure Blob 存储`。

`Azure Blob 存储` 设计用于：

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

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/community @langchain/core @azure/storage-blob
```

查看 [Azure Blob 存储的使用示例](/oss/javascript/integrations/document_loaders/web_loaders/azure_blob_storage_container)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureBlobStorageContainerLoader } from "@langchain/community/document_loaders/web/azure_blob_storage_container";
```

查看 [Azure 文件的使用示例](/oss/javascript/integrations/document_loaders/web_loaders/azure_blob_storage_file)。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { AzureBlobStorageFileLoader } from "@langchain/community/document_loaders/web/azure_blob_storage_file";
```

## 工具

### Azure 容器应用动态会话

> [Azure 容器应用动态会话](https://learn.microsoft.com/azure/container-apps/sessions) 提供对安全沙盒环境的快速访问，这些环境非常适合运行需要与其他工作负载强隔离的代码或应用程序。

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/azure-dynamic-sessions @langchain/core
```

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

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { SessionsPythonREPLTool } from "@langchain/azure-dynamic-sessions";
```

***

<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/javascript/integrations/providers/microsoft.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
