llama_index: [Bug]: Can't instantiate abstract class BaseNode with abstract methods
Bug Description
Any vector store which returns a TextNode to the query method, i get the following error
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__ pydantic.error_wrappers.ValidationError: 1 validation error for NodeWithScore node Can't instantiate abstract class BaseNode with abstract methods get_content, get_metadata_str, get_type, hash, set_content (type=type_error)
Version
v0.10.3
Steps to Reproduce
VectorStoreIndex.from_vector_store(vector_store)
engine = clickhouse_vector_store().as_query_engine(
similarity_top_k=10)
response = engine.query(prompt)
Relevant Logs/Tracbacks
File "/Users/dalemcdiarmid/Library/Caches/pypoetry/virtualenvs/llama-index-xtW50Fas-py3.11/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 535, in _run_script
exec(code, module.__dict__)
File "/opt/llama_index/docs/examples/apps/hacker_insights.py", line 69, in <module>
response = query(prompt)
^^^^^^^^^^^^^
File "/Users/dalemcdiarmid/Library/Caches/pypoetry/virtualenvs/llama-index-xtW50Fas-py3.11/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 212, in wrapper
return cached_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dalemcdiarmid/Library/Caches/pypoetry/virtualenvs/llama-index-xtW50Fas-py3.11/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 241, in __call__
return self._get_or_create_cached_value(args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dalemcdiarmid/Library/Caches/pypoetry/virtualenvs/llama-index-xtW50Fas-py3.11/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 268, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dalemcdiarmid/Library/Caches/pypoetry/virtualenvs/llama-index-xtW50Fas-py3.11/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 324, in _handle_cache_miss
computed_value = self._info.func(*func_args, **func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/docs/examples/apps/hacker_insights.py", line 41, in query
response = engine.query(prompt)
^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/base/base_query_engine.py", line 40, in query
return self._query(str_or_query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/query_engine/retriever_query_engine.py", line 186, in _query
nodes = self.retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/query_engine/retriever_query_engine.py", line 142, in retrieve
nodes = self._retriever.retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/base/base_retriever.py", line 229, in retrieve
nodes = self._retrieve(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/indices/vector_store/retrievers/retriever.py", line 94, in _retrieve
return self._get_nodes_with_embeddings(query_bundle)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/indices/vector_store/retrievers/retriever.py", line 171, in _get_nodes_with_embeddings
return self._build_node_list_from_query_result(query_result)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/llama_index/llama-index-core/llama_index/core/indices/vector_store/retrievers/retriever.py", line 162, in _build_node_list_from_query_result
node_with_scores.append(NodeWithScore(node=node, score=score))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 2
- Comments: 42 (23 by maintainers)
ah, this issue was using
llama_index.legacyfor the vector store index (Pinecone). its running now with the fixed import 👍🤖
The error you’re encountering, “Can’t instantiate abstract class BaseNode with abstract methods”, typically occurs when you’re trying to instantiate an abstract base class that contains abstract methods. In Python, an abstract class is a class that contains one or more abstract methods, which are methods declared in an abstract class but do not contain any implementation.
In your case, it seems like the
BaseNodeclass is being used, but we don’t have the implementation details of this class. IfBaseNodeis an abstract class with abstract methods, you cannot create an instance of it directly. Instead, you should create a subclass ofBaseNodeand implement all of its abstract methods.However, in the provided code,
BaseNodeis used as a type hint in theaddmethod andTextNodeis instantiated in thequerymethod. IfTextNodeis a subclass ofBaseNodeand it implements all abstract methods ofBaseNode, it should not raise the error you mentioned.To resolve this issue, you need to check the implementation of
BaseNodeandTextNodeclasses. Make sureTextNodeis a subclass ofBaseNodeand it implements all abstract methods ofBaseNode. IfBaseNodeorTextNodeis not implemented correctly, you need to fix it according to your application requirements.Unfortunately, I wasn’t able to find the exact structure and implementation of the
BaseNodeclass in the LlamaIndex codebase. It would be helpful if you could provide more information about where these classes are defined or how they are implemented. This would allow me to give a more accurate answer to your question.Sources
About Dosu
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.
@ghassett please don’t mix llama_index.legacy imports with the new structure. It’s either you go for legacy completely or use new structure completely.
For your case, you need to install llama-index-vector-stores-chroma
And import using:
from llama_index.vector_stores.chroma import ChromaVectorStore
Resolved for me when i completely cleaned the env.
In my case the issue was a mix of legacy package in my code. When I removed legacy package and imported new package, it resolved my issue.
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Andrei Fajardo @.> Sent: Monday, February 19, 2024 10:17:37 PM To: run-llama/llama_index @.> Cc: HIMANGSHU KARMAKAR @.>; Mention @.> Subject: [EXTERNAL] Re: [run-llama/llama_index] [Bug]: Can’t instantiate abstract class BaseNode with abstract methods (Issue #10697)
Closed #10697 as completed. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned. Message ID: <run-llama/llama_index/issue/10697/issue_event/11852271812@ github. com> ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!1y-pihW84TIQkY-YMwrPpfe7FxP5RHiKl0F2mh2GUbCjB14UmOY6uaCZNb_CiqYeOw7y37WPTsaXkcXV4uMUjnwpjFOmaaU5h_PsQ05mfS55-Ly1QgQEPNus7i1ioeBaio3Vvw$ Report Suspicious
ZjQcmQRYFpfptBannerEnd
Closed #10697https://github.com/run-llama/llama_index/issues/10697 as completed.
— Reply to this email directly, view it on GitHubhttps://github.com/run-llama/llama_index/issues/10697#event-11852271812, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BDEJBVWJ6J2VDBADMVY32N3YUN62TAVCNFSM6AAAAABDICOXWGVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRHA2TEMRXGE4DCMQ. You are receiving this because you were mentioned.Message ID: @.***>
@amindadgar the issue is not the source code, the issue is mixing legacy with non-legacy imports
isinstance checks and similar break if the types are mixed from legacy and non legacy imports
That did the trick! Thank you, I’ll make sure not to import from legacy packages.
@shankartmv I took a look at your notebook. Your error is not the same as the one posted here as your’s has to do with the
TransformComponentclass rather than theBaseNodeclass which this issue is about. I filed a new issue (#10912) on your behalf. I have the resolution to your issue and will share there.@nerdai I have sent you a new one as requested.
I’ll reset my virtual env to see if this is the issue i.e.
Whats bizarre is its sproadic, it will work for a few queries and then fail vs just failing all the time. I was wondering if its a property of the TextNodes being returned @nerdai that somehow violate the datamodel.
~I think this is because the vector stores don’t inherit from BasePydanticVectorStore @nerdai~