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.
本页面涵盖所有与 Microsoft Azure 及其相关项目的 LangChain 集成。
Azure AI、Dynamic Sessions 和 SQL Server 的集成包维护在
langchain-azure 仓库中。
聊天模型
我们建议开发人员从 (langchain-azure-ai) 开始,以访问 Azure AI Foundry 中提供的所有模型。
Azure AI 聊天补全
使用 AzureAIOpenAIApiChatModel 类访问 Azure OpenAI、DeepSeek R1、Cohere、Phi 和 Mistral 等模型。
pip install -U langchain-azure-ai
配置您的端点。您可以使用 DefaultAzureCredential 配合项目端点,或直接设置 API 密钥。
export AZURE_AI_PROJECT_ENDPOINT=your-project-endpoint
from langchain_azure_ai.chat_models import AzureAIOpenAIApiChatModel
from azure.identity import DefaultAzureCredential
llm = AzureAIOpenAIApiChatModel(
model="gpt-4.1",
credential=DefaultAzureCredential(),
)
llm.invoke('Tell me a joke and include some emojis')
嵌入模型
Azure AI 嵌入模型推理
pip install -U langchain-azure-ai
配置您的端点。您可以使用 DefaultAzureCredential 配合项目端点,或直接设置 API 密钥。
export AZURE_AI_PROJECT_ENDPOINT=your-project-endpoint
from langchain_azure_ai.embeddings import AzureAIOpenAIApiEmbeddingsModel
from azure.identity import DefaultAzureCredential
embed_model = AzureAIOpenAIApiEmbeddingsModel(
model="text-embedding-ada-002",
credential=DefaultAzureCredential(),
)
向量存储
Azure CosmosDB NoSQL 向量搜索
Azure CosmosDB NoSQL 是一个完全托管、全球分布、无服务器的文档数据库,适用于现代应用程序。它以灵活的 JSON 文档存储数据,并使用类 SQL 查询语言。这提供了高性能、低延迟以及自动弹性扩展能力。它还具备针对生成式 AI 和 RAG 等 AI 工作负载的集成向量搜索功能。这使得您可以在同一数据库中存储、索引和查询向量嵌入以及您的运营数据。您可以将向量相似性搜索与传统基于关键词的搜索相结合以获得相关结果,并从各种索引方法中选择以实现最佳性能。这种统一的方法简化了应用程序架构并确保数据一致性。
我们需要安装 azure-cosmos 包才能使用此向量存储。
pip install -qU azure-cosmos
from langchain_azure_ai.vectorstores.azure_cosmos_db_no_sql import (
AzureCosmosDBNoSqlVectorSearch,
)
vector_search = AzureCosmosDBNoSqlVectorSearch.from_documents(
documents=docs,
embedding=openai_embeddings,
cosmos_client=cosmos_client,
database_name=database_name,
container_name=container_name,
vector_embedding_policy=vector_embedding_policy,
full_text_policy=full_text_policy,
indexing_policy=indexing_policy,
cosmos_container_properties=cosmos_container_properties,
cosmos_database_properties={},
full_text_search_enabled=True,
)
See a usage example.
Azure CosmosDB Mongo vCore 向量搜索
Azure CosmosDB Mongo vCore 架构使得创建具有完整原生 MongoDB 支持的数据库变得容易。您可以通过将应用程序指向 MongoDB (vCore) 集群的连接字符串,来应用您的 MongoDB 经验并继续使用您喜欢的 MongoDB 驱动程序、SDK 和工具。
我们需要安装 pymongo 包才能使用此向量存储。
from langchain_azure_ai.vectorstores.azure_cosmos_db_mongo_vcore import (
AzureCosmosDBMongoVCoreVectorSearch,
)
vectorstore = AzureCosmosDBMongoVCoreVectorSearch.from_documents(
docs,
openai_embeddings,
collection=collection,
index_name=INDEX_NAME,
)
See a usage example.