mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-17 07:26:16 +00:00
Community: Updating Azure Retriever and Docs to be Azure AI Search instead of Azure Cognitive Search (#19925)
Last year Microsoft [changed the name](https://learn.microsoft.com/en-us/azure/search/search-what-is-azure-search) of Azure Cognitive Search to Azure AI Search. This PR updates the Langchain Azure Retriever API and it's associated docs to reflect this change. It may be confusing for users to see the name Cognitive here and AI in the Microsoft documentation which is why this is needed. I've also added a more detailed example to the Azure retriever doc page. There are more places that need a similar update but I'm breaking it up so the PRs are not too big 😄 Fixing my errors from the previous PR. Twitter: @marlene_zw Two new tests added to test backward compatibility in `libs/community/tests/integration_tests/retrievers/test_azure_cognitive_search.py` --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""Test Azure AI Search wrapper."""
|
||||
from langchain_core.documents import Document
|
||||
|
||||
from langchain_community.retrievers.azure_ai_search import (
|
||||
AzureAISearchRetriever,
|
||||
AzureCognitiveSearchRetriever,
|
||||
)
|
||||
|
||||
|
||||
def test_azure_ai_search_get_relevant_documents() -> None:
|
||||
"""Test valid call to Azure AI Search.
|
||||
|
||||
In order to run this test, you should provide
|
||||
a `service_name`, azure search `api_key` and an `index_name`
|
||||
as arguments for the AzureAISearchRetriever in both tests.
|
||||
api_version, aiosession and topk_k are optional parameters.
|
||||
"""
|
||||
retriever = AzureAISearchRetriever()
|
||||
|
||||
documents = retriever.get_relevant_documents("what is langchain?")
|
||||
for doc in documents:
|
||||
assert isinstance(doc, Document)
|
||||
assert doc.page_content
|
||||
|
||||
retriever = AzureAISearchRetriever(top_k=1)
|
||||
documents = retriever.get_relevant_documents("what is langchain?")
|
||||
assert len(documents) <= 1
|
||||
|
||||
|
||||
async def test_azure_ai_search_aget_relevant_documents() -> None:
|
||||
"""Test valid async call to Azure AI Search.
|
||||
|
||||
In order to run this test, you should provide
|
||||
a `service_name`, azure search `api_key` and an `index_name`
|
||||
as arguments for the AzureAISearchRetriever.
|
||||
"""
|
||||
retriever = AzureAISearchRetriever()
|
||||
documents = await retriever.aget_relevant_documents("what is langchain?")
|
||||
for doc in documents:
|
||||
assert isinstance(doc, Document)
|
||||
assert doc.page_content
|
||||
|
||||
|
||||
def test_azure_cognitive_search_get_relevant_documents() -> None:
|
||||
"""Test valid call to Azure Cognitive Search.
|
||||
|
||||
This is to test backwards compatibility of the retriever
|
||||
"""
|
||||
retriever = AzureCognitiveSearchRetriever()
|
||||
|
||||
documents = retriever.get_relevant_documents("what is langchain?")
|
||||
for doc in documents:
|
||||
assert isinstance(doc, Document)
|
||||
assert doc.page_content
|
||||
|
||||
retriever = AzureCognitiveSearchRetriever(top_k=1)
|
||||
documents = retriever.get_relevant_documents("what is langchain?")
|
||||
assert len(documents) <= 1
|
||||
|
||||
|
||||
async def test_azure_cognitive_search_aget_relevant_documents() -> None:
|
||||
"""Test valid async call to Azure Cognitive Search.
|
||||
|
||||
This is to test backwards compatibility of the retriever
|
||||
"""
|
||||
retriever = AzureCognitiveSearchRetriever()
|
||||
documents = await retriever.aget_relevant_documents("what is langchain?")
|
||||
for doc in documents:
|
||||
assert isinstance(doc, Document)
|
||||
assert doc.page_content
|
@@ -1,37 +0,0 @@
|
||||
"""Test Azure Cognitive Search wrapper."""
|
||||
from langchain_core.documents import Document
|
||||
|
||||
from langchain_community.retrievers.azure_cognitive_search import (
|
||||
AzureCognitiveSearchRetriever,
|
||||
)
|
||||
|
||||
|
||||
def test_azure_cognitive_search_get_relevant_documents() -> None:
|
||||
"""Test valid call to Azure Cognitive Search.
|
||||
|
||||
In order to run this test, you should provide a service name, azure search api key
|
||||
and an index_name as arguments for the AzureCognitiveSearchRetriever in both tests.
|
||||
"""
|
||||
retriever = AzureCognitiveSearchRetriever()
|
||||
|
||||
documents = retriever.get_relevant_documents("what is langchain?")
|
||||
for doc in documents:
|
||||
assert isinstance(doc, Document)
|
||||
assert doc.page_content
|
||||
|
||||
retriever = AzureCognitiveSearchRetriever()
|
||||
documents = retriever.get_relevant_documents("what is langchain?")
|
||||
assert len(documents) <= 1
|
||||
|
||||
|
||||
async def test_azure_cognitive_search_aget_relevant_documents() -> None:
|
||||
"""Test valid async call to Azure Cognitive Search.
|
||||
|
||||
In order to run this test, you should provide a service name, azure search api key
|
||||
and an index_name as arguments for the AzureCognitiveSearchRetriever.
|
||||
"""
|
||||
retriever = AzureCognitiveSearchRetriever()
|
||||
documents = await retriever.aget_relevant_documents("what is langchain?")
|
||||
for doc in documents:
|
||||
assert isinstance(doc, Document)
|
||||
assert doc.page_content
|
Reference in New Issue
Block a user