langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.87k stars 15.36k forks source link

KeyError: 'content' using `AzureCognitiveSearchRetreiver` #6171

Closed na-stewart closed 1 year ago

na-stewart commented 1 year ago

System Info

langchain=0.0.199 Python=3.9.13

Who Can Help

@eyurtsev @hwchase17

Information

Related Components

Reproduction

import os

from langchain.retrievers import AzureCognitiveSearchRetriever

cognitive_search_name = os.environ["AZURE_COGNITIVE_SEARCH_SERVICE_NAME"]
vector_store_address: str = f"https://{cognitive_search_name}.search.windows.net/"
index_name: str = os.environ["AZURE_COGNITIVE_SEARCH_INDEX_NAME"]
vector_store_password: str = os.environ["AZURE_COGNITIVE_SEARCH_API_KEY"]

retriever = AzureCognitiveSearchRetriever(content_key="content")
retriever.get_relevant_documents("what is langchain")

Expected behavior

I am attempting to use AzureCognitiveSearchRetriever to no avail. There is little guidance or documentation that I could find to make this functionality work. I don't know what value I'm supposed to set the parameter content_key to in order to make this work.

My overall goal is to retrieve data from Azure Cognitive Search and use it to determine the output served by the chatbot based on user query.

Thanks!

devstein commented 1 year ago

Generated by a 🤖

Answer

The content_key parameter in the AzureCognitiveSearchRetriever is used to specify the key in the retrieved result that should be set as the Document's page_content. In your case, you should set the content_key parameter to the key in your Azure Cognitive Search index that corresponds to the content you want to retrieve.

For example, if your Azure Cognitive Search index has a field named "text" that contains the content you want to use as page_content, you should initialize the AzureCognitiveSearchRetriever with content_key="text":

retriever = AzureCognitiveSearchRetriever(content_key="text")
retriever.get_relevant_documents("what is langchain")

Make sure to replace "text" with the appropriate key from your Azure Cognitive Search index.

Sources


This response is meant to be helpful and save users time. It is not meant to be a precise solution.

Please leave a 👍 if this is helpful and 👎 if it is irrelevant

dosubot[bot] commented 1 year ago

Hi, @na-stewart! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you were experiencing a KeyError in the LangChain library when using the AzureCognitiveSearchRetriever. Devstein, one of the maintainers, provided a helpful response explaining that the content_key parameter should be set to the key in the Azure Cognitive Search index that corresponds to the content you want to retrieve. You confirmed that the response was helpful.

Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain project!