langchain icon indicating copy to clipboard operation
langchain copied to clipboard

TypeError when using SelfQueryRetriever

Open jobe1k opened this issue 2 years ago • 7 comments

Enviorment: DATABRICKS_RUNTIME_VERSION: 10.4 Python 3.8.10 Langchain 0.0.172

I was following along with the basic tutorial here: Self-querying retriever with Chroma and I keep getting TypeError: 'NoneType' object is not callable error. Also, when I call .get() on the vectorstore, the embeddings field is "None". Is this related to the error? Any idea what I'm doing wrong here? Many thanks.

image --------------------------------------------------------------------------------------------------------------------------------------------- My full code: from langchain.docstore.document import Document docs = [ Document(page_content="A bunch of scientists bring back dinosaurs and mayhem breaks loose", metadata={"year": 1993, "rating": 7.7, "genre": "action"}), Document(page_content="Leo DiCaprio gets lost in a dream within a dream within a dream within a ...", metadata={"year": 2010, "director": "Christopher Nolan", "rating": 8.2}), Document(page_content="A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea", metadata={"year": 2006, "director": "Satoshi Kon", "rating": 8.6}), Document(page_content="A bunch of normal-sized women are supremely wholesome and some men pine after them", metadata={"year": 2019, "director": "Greta Gerwig", "rating": 8.3}), Document(page_content="Toys come alive and have a blast doing so", metadata={"year": 1995, "genre": "animated"}), Document(page_content="Three men walk into the Zone, three men walk out of the Zone", metadata={"year": 1979, "rating": 9.9, "director": "Andrei Tarkovsky", "genre": "science fiction", "rating": 9.9}) ]

embeddings = OpenAIEmbeddings(chunk_size=1)

vectorstore = Chroma.from_documents( docs, embeddings )

from langchain.llms import OpenAI from langchain.retrievers.self_query.base import SelfQueryRetriever from langchain.chains.query_constructor.base import AttributeInfo

metadata_field_info=[ AttributeInfo( name="genre", description="The genre of the movie", type="string or list[string]", ), AttributeInfo( name="year", description="The year the movie was released", type="integer", ), AttributeInfo( name="director", description="The name of the movie director", type="string", ), AttributeInfo( name="rating", description="A 1-10 rating for the movie", type="float" ), ] document_content_description = "Brief summary of a movie" llm = OpenAI(temperature=0) retriever = SelfQueryRetriever.from_llm(llm, vectorstore, document_content_description, metadata_field_info, verbose=True)

--------------------------------------------------------------------------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 27 document_content_description = "Brief summary of a movie" 28 llm = OpenAI(temperature=0) ---> 29 retriever = SelfQueryRetriever.from_llm(llm, vectorstore, document_content_description, metadata_field_info, verbose=True)

/databricks/python/lib/python3.8/site-packages/langchain/retrievers/self_query/base.py in from_llm(cls, llm, vectorstore, document_contents, metadata_field_info, structured_query_translator, chain_kwargs, enable_limit, **kwargs) 112 "allowed_operators" 113 ] = structured_query_translator.allowed_operators --> 114 llm_chain = load_query_constructor_chain( 115 llm, 116 document_contents,

/databricks/python/lib/python3.8/site-packages/langchain/chains/query_constructor/base.py in load_query_constructor_chain(llm, document_contents, attribute_info, examples, allowed_comparators, allowed_operators, enable_limit, **kwargs) 123 **kwargs: Any, 124 ) -> LLMChain: --> 125 prompt = _get_prompt( 126 document_contents, 127 attribute_info,

/databricks/python/lib/python3.8/site-packages/langchain/chains/query_constructor/base.py in _get_prompt(document_contents, attribute_info, examples, allowed_comparators, allowed_operators, enable_limit) 100 i=len(examples) + 1, content=document_contents, attributes=attribute_str 101 ) --> 102 output_parser = StructuredQueryOutputParser.from_components( 103 allowed_comparators=allowed_comparators, allowed_operators=allowed_operators 104 )

/databricks/python/lib/python3.8/site-packages/langchain/chains/query_constructor/base.py in from_components(cls, allowed_comparators, allowed_operators) 57 allowed_operators: Optional[Sequence[Operator]] = None, 58 ) -> StructuredQueryOutputParser: ---> 59 ast_parser = get_parser( 60 allowed_comparators=allowed_comparators, allowed_operators=allowed_operators 61 )

/databricks/python/lib/python3.8/site-packages/langchain/chains/query_constructor/parser.py in get_parser(allowed_comparators, allowed_operators) 127 allowed_operators: Optional[Sequence[Operator]] = None, 128 ) -> Lark: --> 129 transformer = QueryTransformer( 130 allowed_comparators=allowed_comparators, allowed_operators=allowed_operators 131 )

jobe1k avatar May 17 '23 22:05 jobe1k

I keep getting TypeError: 'NoneType' object is not callable too. I have updated, installed Lark, but didn't help tried in different environemnts, but didn't help

sergeyvi4ev avatar May 18 '23 12:05 sergeyvi4ev

@sergeyvi4ev Could you share the full stacktrace ?

imeckr avatar May 18 '23 13:05 imeckr

@jobe1k do you have lark installed?

dev2049 avatar May 19 '23 01:05 dev2049

@sergeyvi4ev are you running this in a notebook? sometimes installing dependencies in those is tricky

dev2049 avatar May 19 '23 01:05 dev2049

@dev2049 yup, installed lark and all other dependencies.

jobe1k avatar May 19 '23 18:05 jobe1k

it seems like it's saying the QueryTransformer class is None so then trying to instantiate it fails. which only occurs when Lark import fails. if you just run

from lark import Lark, Transformer, v_args

that doesn't error?

dev2049 avatar May 19 '23 19:05 dev2049

install lark and restart the jupyter notebook kernel solved this issue for me. Thanks for the info!

shawnlix avatar May 20 '23 23:05 shawnlix

Hi, @jobe1k! 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, the issue you reported is a TypeError that occurs when using the SelfQueryRetriever class. It seems that the error is related to a NoneType object not being callable. Some users have suggested checking if the lark library is installed and restarting the Jupyter notebook kernel. One user confirmed that this solution worked for them.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this 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!

dosubot[bot] avatar Sep 15 '23 16:09 dosubot[bot]