langchain
langchain copied to clipboard
TypeError when using SelfQueryRetriever
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.
---------------------------------------------------------------------------------------------------------------------------------------------
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)
/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 )
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 Could you share the full stacktrace ?
@jobe1k do you have lark installed?
@sergeyvi4ev are you running this in a notebook? sometimes installing dependencies in those is tricky
@dev2049 yup, installed lark and all other dependencies.
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?
install lark and restart the jupyter notebook kernel solved this issue for me. Thanks for the info!
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!