langchain-ai / langchain

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

Function get_relevant_docs() returning AttributeError #12076

Closed gabriellm1 closed 8 months ago

gabriellm1 commented 1 year ago

System Info

MacOS Ventura 13.6 Python 3.10.13 langchain 0.0.306

Who can help?

@hwchase17 @agola11

Information

Related Components

Reproduction

  llm = AzureOpenAI(temperature=0, model="gpt-35-turbo")
  compressor = LLMChainExtractor.from_llm(llm)
  base_retriever = vectorstores.as_retriever()
  compression_retriever = ContextualCompressionRetriever(base_compressor=compressor, base_retriever=base_retriever)
  compression_retriever.get_relevant_documents("Owner")

Expected behavior

Expected to return the docs compressed from the vectorstore, but I'm getting the AttributeError: 'str' object has no attribute 'get'

dosubot[bot] commented 1 year ago

🤖

Hello,

The error you're encountering, AttributeError: 'str' object has no attribute 'get', typically occurs when you're trying to use a method that doesn't exist for the string data type. In this case, it seems like you're trying to use the get method on a string object, which is causing the error.

In your code, you're using the get_relevant_documents() function, which is a method of the BaseRetriever class in the LangChain framework. This method takes a string query and returns a list of relevant documents. Here's an example of how you can use this function:

retriever = BaseRetriever()  # Assuming you have an instance of BaseRetriever
documents = retriever.get_relevant_documents("your query")

If you're still encountering the error, it's possible that you're not calling the get_relevant_documents() function correctly. Make sure you're calling it on an instance of the BaseRetriever class and passing the correct arguments.

Also, please note that you're using LangChain version 0.0.306, while the latest version is 0.0.319. It's possible that the issue you're encountering has been fixed in a more recent version. I would recommend updating to the latest version and see if the issue persists.

If the error still persists after these steps, could you please provide more information about how you're using this function? Specifically, could you share the code where you're initializing the BaseRetriever and ContextualCompressionRetriever instances? This would help in identifying the issue more accurately.

Best, Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

gabriellm1 commented 12 months ago

I do not think that is the problem since I instantiated a retriever using the method as_retriever() in the FAISS vectorstore

zhuzihan728 commented 11 months ago

This can happen when you receive an HTTP error response, e.g., 404, from OpenAI embedding API.

dosubot[bot] commented 8 months ago

Hi, @gabriellm1

I'm helping the LangChain team manage their backlog and am marking this issue as stale. It looks like you encountered an AttributeError when using the get_relevant_docs() function in the LangChain framework. There were suggestions to check the method call, update to the latest LangChain version, and considerations about potential HTTP error responses from the OpenAI embedding API.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team 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!