run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
36.99k stars 5.3k forks source link

[Bug]: PropertyGraphIndex (Neo4J Aura): PydanticSerializationError: Error calling function `<lambda>`: AttributeError: 'str' object has no attribute 'value' #17065

Open Anindyadeep opened 17 hours ago

Anindyadeep commented 17 hours ago

Bug Description

Initially I was following these tutorials:

Which was working on Neo4J local free version (running on docker), but when I switched to Neo4J Aura DB (which is the cloud version), I started to get some error.

Version

llama-index                             0.11.23
llama-index-agent-openai                0.3.4
llama-index-cli                         0.3.1
llama-index-core                        0.12.1
llama-index-embeddings-fastembed        0.2.0
llama-index-embeddings-openai           0.2.5
llama-index-graph-stores-neo4j          0.4.0
llama-index-indices-managed-llama-cloud 0.4.0
llama-index-legacy                      0.9.48.post4
llama-index-llms-openai                 0.2.16
llama-index-multi-modal-llms-openai     0.2.3
llama-index-program-openai              0.2.0
llama-index-question-gen-openai         0.2.0
llama-index-readers-file                0.3.0
llama-index-readers-llama-parse         0.3.0
llama-index-vector-stores-qdrant        0.3.3

Steps to Reproduce

import nest_asyncio
from dotenv import load_dotenv
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core import SimpleDirectoryReader
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding
from kg_extractor import BetterKGExtractor

nest_asyncio.apply()
load_dotenv()

embedding_model_name="text-embedding-3-small"
llm = OpenAI(model="gpt-4o-mini")
embedding_model = OpenAIEmbedding(model=embedding_model_name)

documents = SimpleDirectoryReader(input_dir="./documents").load_data()
splitter = SentenceSplitter(
    chunk_size=512,
    chunk_overlap=0
)
nodes = splitter.get_nodes_from_documents(documents=documents)
nodes = nodes[:30]

from llama_index.graph_stores.neo4j import Neo4jPropertyGraphStore

username="neo4j"
password="xxxx"
url="neo4j+s://xxxxx.neo4j.io"
database="neo4j"

store = Neo4jPropertyGraphStore(
    username=username,
    password=password,
    url=url,
    database=database
)

from llama_index.core import PropertyGraphIndex

index = PropertyGraphIndex(
    nodes=nodes,
    kg_extractors=[BetterKGExtractor(llm=llm, embedding_model_name=embedding_model_name)],
    show_progress=True,
    embed_kg_nodes=True,
    property_graph_store=store
)

Till here everything was working fine, I could even see the visualization inside my cloud database. Now problem starts when doing retrieval

from llama_index.core.retrievers import VectorContextRetriever
retriever = VectorContextRetriever(
    graph_store=store,
    include_properties=True,
    embed_model=embedding_model,
    similarity_top_k=4
)
retriever.retrieve("What is the formula of liquid neural networks")

Above lines of code gave error, so tried different method

query = "What is the formula of liquid neural networks"
index.as_retriever(similarity_top_k=4).retrieve(query)

This also gave me the same error.

Relevant Logs/Tracbacks

index.as_retriever(similarity_top_k=4).retrieve(query)

I got this error:

```bash
╭─────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────╮
│ in <module>:2                                                                                                   │
│                                                                                                                 │
│   1 query = "What is the formula of liquid neural networks"                                                     │
│ ❱ 2 index.as_retriever(similarity_top_k=4).retrieve(query)                                                      │
│   3                                                                                                             │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 311 in wrapper                                                                                                  │
│                                                                                                                 │
│   308 │   │   │   │   │   │   _logger.debug(f"Failed to reset active_span_id: {e}")                             │
│   309 │   │   │                                                                                                 │
│   310 │   │   │   try:                                                                                          │
│ ❱ 311 │   │   │   │   result = func(*args, **kwargs)                                                            │
│   312 │   │   │   │   if isinstance(result, asyncio.Future):                                                    │
│   313 │   │   │   │   │   # If the result is a Future, wrap it                                                  │
│   314 │   │   │   │   │   new_future = asyncio.ensure_future(result)                                            │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py:245 in  │
│ retrieve                                                                                                        │
│                                                                                                                 │
│   242 │   │   │   │   CBEventType.RETRIEVE,                                                                     │
│   243 │   │   │   │   payload={EventPayload.QUERY_STR: query_bundle.query_str},                                 │
│   244 │   │   │   ) as retrieve_event:                                                                          │
│ ❱ 245 │   │   │   │   nodes = self._retrieve(query_bundle)                                                      │
│   246 │   │   │   │   nodes = self._handle_recursive_retrieval(query_bundle, nodes)                             │
│   247 │   │   │   │   retrieve_event.on_end(                                                                    │
│   248 │   │   │   │   │   payload={EventPayload.NODES: nodes},                                                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 311 in wrapper                                                                                                  │
│                                                                                                                 │
│   308 │   │   │   │   │   │   _logger.debug(f"Failed to reset active_span_id: {e}")                             │
│   309 │   │   │                                                                                                 │
│   310 │   │   │   try:                                                                                          │
│ ❱ 311 │   │   │   │   result = func(*args, **kwargs)                                                            │
│   312 │   │   │   │   if isinstance(result, asyncio.Future):                                                    │
│   313 │   │   │   │   │   # If the result is a Future, wrap it                                                  │
│   314 │   │   │   │   │   new_future = asyncio.ensure_future(result)                                            │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/retriev │
│ er.py:52 in _retrieve                                                                                           │
│                                                                                                                 │
│   49 │   def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:                                 │
│   50 │   │   results = []                                                                                       │
│   51 │   │   if self.use_async:                                                                                 │
│ ❱ 52 │   │   │   return asyncio_run(self._aretrieve(query_bundle))                                              │
│   53 │   │                                                                                                      │
│   54 │   │   for sub_retriever in tqdm(self.sub_retrievers, disable=not self.show_progress):                    │
│   55 │   │   │   results.extend(sub_retriever.retrieve(query_bundle))                                           │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/async_utils.py:33 in           │
│ asyncio_run                                                                                                     │
│                                                                                                                 │
│    30 │   │   loop = asyncio.get_event_loop()                                                                   │
│    31 │   │                                                                                                     │
│    32 │   │   # If we're here, there's an existing loop but it's not running                                    │
│ ❱  33 │   │   return loop.run_until_complete(coro)                                                              │
│    34 │                                                                                                         │
│    35 │   except RuntimeError as e:                                                                             │
│    36 │   │   # If we can't get the event loop, we're likely in a different thread, or its alr                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/nest_asyncio.py:98 in run_until_complete        │
│                                                                                                                 │
│    95 │   │   │   if not f.done():                                                                              │
│    96 │   │   │   │   raise RuntimeError(                                                                       │
│    97 │   │   │   │   │   'Event loop stopped before Future completed.')                                        │
│ ❱  98 │   │   │   return f.result()                                                                             │
│    99 │                                                                                                         │
│   100 │   def _run_once(self):                                                                                  │
│   101 │   │   """                                                                                               │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/asyncio/futures.py:201 in result                              │
│                                                                                                                 │
│   198 │   │   │   raise exceptions.InvalidStateError('Result is not ready.')                                    │
│   199 │   │   self.__log_traceback = False                                                                      │
│   200 │   │   if self._exception is not None:                                                                   │
│ ❱ 201 │   │   │   raise self._exception.with_traceback(self._exception_tb)                                      │
│   202 │   │   return self._result                                                                               │
│   203 │                                                                                                         │
│   204 │   def exception(self):                                                                                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/asyncio/tasks.py:234 in __step                                │
│                                                                                                                 │
│   231 │   │   │   │   # don't have `__iter__` and `__next__` methods.                                           │
│   232 │   │   │   │   result = coro.send(None)                                                                  │
│   233 │   │   │   else:                                                                                         │
│ ❱ 234 │   │   │   │   result = coro.throw(exc)                                                                  │
│   235 │   │   except StopIteration as exc:                                                                      │
│   236 │   │   │   if self._must_cancel:                                                                         │
│   237 │   │   │   │   # Task is cancelled right before coro stops.                                              │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/retriev │
│ er.py:64 in _aretrieve                                                                                          │
│                                                                                                                 │
│   61 │   │   for sub_retriever in self.sub_retrievers:                                                          │
│   62 │   │   │   tasks.append(sub_retriever.aretrieve(query_bundle))                                            │
│   63 │   │                                                                                                      │
│ ❱ 64 │   │   async_results = await run_jobs(                                                                    │
│   65 │   │   │   tasks, workers=self.num_workers, show_progress=self.show_progress                              │
│   66 │   │   )                                                                                                  │
│   67                                                                                                            │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 357 in async_wrapper                                                                                            │
│                                                                                                                 │
│   354 │   │   │   │   tags=tags,                                                                                │
│   355 │   │   │   )                                                                                             │
│   356 │   │   │   try:                                                                                          │
│ ❱ 357 │   │   │   │   result = await func(*args, **kwargs)                                                      │
│   358 │   │   │   except BaseException as e:                                                                    │
│   359 │   │   │   │   self.event(SpanDropEvent(span_id=id_, err_str=str(e)))                                    │
│   360 │   │   │   │   self.span_drop(id_=id_, bound_args=bound_args, instance=instance, err=e)                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/async_utils.py:148 in run_jobs │
│                                                                                                                 │
│   145 │   │                                                                                                     │
│   146 │   │   results = await tqdm_asyncio.gather(*pool_jobs, desc=desc)                                        │
│   147 │   else:                                                                                                 │
│ ❱ 148 │   │   results = await asyncio.gather(*pool_jobs)                                                        │
│   149 │                                                                                                         │
│   150 │   return results                                                                                        │
│   151                                                                                                           │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/asyncio/tasks.py:304 in __wakeup                              │
│                                                                                                                 │
│   301 │                                                                                                         │
│   302 │   def __wakeup(self, future):                                                                           │
│   303 │   │   try:                                                                                              │
│ ❱ 304 │   │   │   future.result()                                                                               │
│   305 │   │   except BaseException as exc:                                                                      │
│   306 │   │   │   # This may also be a cancellation.                                                            │
│   307 │   │   │   self.__step(exc)                                                                              │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/asyncio/tasks.py:232 in __step                                │
│                                                                                                                 │
│   229 │   │   │   if exc is None:                                                                               │
│   230 │   │   │   │   # We use the `send` method directly, because coroutines                                   │
│   231 │   │   │   │   # don't have `__iter__` and `__next__` methods.                                           │
│ ❱ 232 │   │   │   │   result = coro.send(None)                                                                  │
│   233 │   │   │   else:                                                                                         │
│   234 │   │   │   │   result = coro.throw(exc)                                                                  │
│   235 │   │   except StopIteration as exc:                                                                      │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 357 in async_wrapper                                                                                            │
│                                                                                                                 │
│   354 │   │   │   │   tags=tags,                                                                                │
│   355 │   │   │   )                                                                                             │
│   356 │   │   │   try:                                                                                          │
│ ❱ 357 │   │   │   │   result = await func(*args, **kwargs)                                                      │
│   358 │   │   │   except BaseException as e:                                                                    │
│   359 │   │   │   │   self.event(SpanDropEvent(span_id=id_, err_str=str(e)))                                    │
│   360 │   │   │   │   self.span_drop(id_=id_, bound_args=bound_args, instance=instance, err=e)                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/async_utils.py:139 in worker   │
│                                                                                                                 │
│   136 │   @dispatcher.span                                                                                      │
│   137 │   async def worker(job: Coroutine) -> Any:                                                              │
│   138 │   │   async with semaphore:                                                                             │
│ ❱ 139 │   │   │   return await job                                                                              │
│   140 │                                                                                                         │
│   141 │   pool_jobs = [worker(job) for job in jobs]                                                             │
│   142                                                                                                           │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 357 in async_wrapper                                                                                            │
│                                                                                                                 │
│   354 │   │   │   │   tags=tags,                                                                                │
│   355 │   │   │   )                                                                                             │
│   356 │   │   │   try:                                                                                          │
│ ❱ 357 │   │   │   │   result = await func(*args, **kwargs)                                                      │
│   358 │   │   │   except BaseException as e:                                                                    │
│   359 │   │   │   │   self.event(SpanDropEvent(span_id=id_, err_str=str(e)))                                    │
│   360 │   │   │   │   self.span_drop(id_=id_, bound_args=bound_args, instance=instance, err=e)                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py:276 in  │
│ aretrieve                                                                                                       │
│                                                                                                                 │
│   273 │   │   │   │   CBEventType.RETRIEVE,                                                                     │
│   274 │   │   │   │   payload={EventPayload.QUERY_STR: query_bundle.query_str},                                 │
│   275 │   │   │   ) as retrieve_event:                                                                          │
│ ❱ 276 │   │   │   │   nodes = await self._aretrieve(query_bundle=query_bundle)                                  │
│   277 │   │   │   │   nodes = await self._ahandle_recursive_retrieval(                                          │
│   278 │   │   │   │   │   query_bundle=query_bundle, nodes=nodes                                                │
│   279 │   │   │   │   )                                                                                         │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/sub_ret │
│ rievers/base.py:150 in _aretrieve                                                                               │
│                                                                                                                 │
│   147 │   async def _aretrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:                         │
│   148 │   │   nodes = await self.aretrieve_from_graph(query_bundle)                                             │
│   149 │   │   if self.include_text and nodes:                                                                   │
│ ❱ 150 │   │   │   nodes = await self.async_add_source_text(nodes)                                               │
│   151 │   │   return nodes                                                                                      │
│   152 │                                                                                                         │
│   153 │   @abstractmethod                                                                                       │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/sub_ret │
│ rievers/base.py:139 in async_add_source_text                                                                    │
│                                                                                                                 │
│   136 │   │   )                                                                                                 │
│   137 │   │   og_node_map = {node.node_id: node for node in og_nodes}                                           │
│   138 │   │                                                                                                     │
│ ❱ 139 │   │   return self._add_source_text(nodes, og_node_map)                                                  │
│   140 │                                                                                                         │
│   141 │   def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:                                │
│   142 │   │   nodes = self.retrieve_from_graph(query_bundle)                                                    │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/sub_ret │
│ rievers/base.py:108 in _add_source_text                                                                         │
│                                                                                                                 │
│   105 │   │   │   │   │   new_content = (                                                                       │
│   106 │   │   │   │   │   │   preamble_text + graph_content_str + "\n\n" + cur_content                          │
│   107 │   │   │   │   │   )                                                                                     │
│ ❱ 108 │   │   │   │   │   mapped_node = TextNode(**mapped_node.dict())                                          │
│   109 │   │   │   │   │   mapped_node.text = new_content                                                        │
│   110 │   │   │   │   result_nodes.append(                                                                      │
│   111 │   │   │   │   │   NodeWithScore(                                                                        │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/schema.py:108 in dict          │
│                                                                                                                 │
│    105 │   │   return data                                                                                      │
│    106 │                                                                                                        │
│    107 │   def dict(self, **kwargs: Any) -> Dict[str, Any]:                                                     │
│ ❱  108 │   │   return self.model_dump(**kwargs)                                                                 │
│    109 │                                                                                                        │
│    110 │   def __getstate__(self) -> Dict[str, Any]:                                                            │
│    111 │   │   state = super().__getstate__()                                                                   │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/pydantic/main.py:364 in model_dump              │
│                                                                                                                 │
│    361 │   │   Returns:                                                                                         │
│    362 │   │   │   A dictionary representation of the model.                                                    │
│    363 │   │   """                                                                                              │
│ ❱  364 │   │   return self.__pydantic_serializer__.to_python(                                                   │
│    365 │   │   │   self,                                                                                        │
│    366 │   │   │   mode=mode,                                                                                   │
│    367 │   │   │   by_alias=by_alias,                                                                           │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
PydanticSerializationError: Error calling function `<lambda>`: AttributeError: 'str' object has no attribute 
'value'

And for this:

retriever.retrieve("What is the formula of liquid neural networks")

I got this error:

─────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────╮
│ in <module>:1                                                                                                   │
│                                                                                                                 │
│ ❱ 1 retriever.retrieve("What is the formula of liquid neural networks")                                         │
│   2                                                                                                             │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 311 in wrapper                                                                                                  │
│                                                                                                                 │
│   308 │   │   │   │   │   │   _logger.debug(f"Failed to reset active_span_id: {e}")                             │
│   309 │   │   │                                                                                                 │
│   310 │   │   │   try:                                                                                          │
│ ❱ 311 │   │   │   │   result = func(*args, **kwargs)                                                            │
│   312 │   │   │   │   if isinstance(result, asyncio.Future):                                                    │
│   313 │   │   │   │   │   # If the result is a Future, wrap it                                                  │
│   314 │   │   │   │   │   new_future = asyncio.ensure_future(result)                                            │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/base/base_retriever.py:245 in  │
│ retrieve                                                                                                        │
│                                                                                                                 │
│   242 │   │   │   │   CBEventType.RETRIEVE,                                                                     │
│   243 │   │   │   │   payload={EventPayload.QUERY_STR: query_bundle.query_str},                                 │
│   244 │   │   │   ) as retrieve_event:                                                                          │
│ ❱ 245 │   │   │   │   nodes = self._retrieve(query_bundle)                                                      │
│   246 │   │   │   │   nodes = self._handle_recursive_retrieval(query_bundle, nodes)                             │
│   247 │   │   │   │   retrieve_event.on_end(                                                                    │
│   248 │   │   │   │   │   payload={EventPayload.NODES: nodes},                                                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/instrumentation/dispatcher.py: │
│ 311 in wrapper                                                                                                  │
│                                                                                                                 │
│   308 │   │   │   │   │   │   _logger.debug(f"Failed to reset active_span_id: {e}")                             │
│   309 │   │   │                                                                                                 │
│   310 │   │   │   try:                                                                                          │
│ ❱ 311 │   │   │   │   result = func(*args, **kwargs)                                                            │
│   312 │   │   │   │   if isinstance(result, asyncio.Future):                                                    │
│   313 │   │   │   │   │   # If the result is a Future, wrap it                                                  │
│   314 │   │   │   │   │   new_future = asyncio.ensure_future(result)                                            │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/sub_ret │
│ rievers/base.py:144 in _retrieve                                                                                │
│                                                                                                                 │
│   141 │   def _retrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:                                │
│   142 │   │   nodes = self.retrieve_from_graph(query_bundle)                                                    │
│   143 │   │   if self.include_text and nodes:                                                                   │
│ ❱ 144 │   │   │   nodes = self.add_source_text(nodes)                                                           │
│   145 │   │   return nodes                                                                                      │
│   146 │                                                                                                         │
│   147 │   async def _aretrieve(self, query_bundle: QueryBundle) -> List[NodeWithScore]:                         │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/sub_ret │
│ rievers/base.py:128 in add_source_text                                                                          │
│                                                                                                                 │
│   125 │   │   )                                                                                                 │
│   126 │   │   node_map = {node.node_id: node for node in og_nodes}                                              │
│   127 │   │                                                                                                     │
│ ❱ 128 │   │   return self._add_source_text(nodes, node_map)                                                     │
│   129 │                                                                                                         │
│   130 │   async def async_add_source_text(                                                                      │
│   131 │   │   self, nodes: List[NodeWithScore]                                                                  │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/indices/property_graph/sub_ret │
│ rievers/base.py:108 in _add_source_text                                                                         │
│                                                                                                                 │
│   105 │   │   │   │   │   new_content = (                                                                       │
│   106 │   │   │   │   │   │   preamble_text + graph_content_str + "\n\n" + cur_content                          │
│   107 │   │   │   │   │   )                                                                                     │
│ ❱ 108 │   │   │   │   │   mapped_node = TextNode(**mapped_node.dict())                                          │
│   109 │   │   │   │   │   mapped_node.text = new_content                                                        │
│   110 │   │   │   │   result_nodes.append(                                                                      │
│   111 │   │   │   │   │   NodeWithScore(                                                                        │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/llama_index/core/schema.py:108 in dict          │
│                                                                                                                 │
│    105 │   │   return data                                                                                      │
│    106 │                                                                                                        │
│    107 │   def dict(self, **kwargs: Any) -> Dict[str, Any]:                                                     │
│ ❱  108 │   │   return self.model_dump(**kwargs)                                                                 │
│    109 │                                                                                                        │
│    110 │   def __getstate__(self) -> Dict[str, Any]:                                                            │
│    111 │   │   state = super().__getstate__()                                                                   │
│                                                                                                                 │
│ /home/anindya/miniconda3/envs/deep/lib/python3.10/site-packages/pydantic/main.py:364 in model_dump              │
│                                                                                                                 │
│    361 │   │   Returns:                                                                                         │
│    362 │   │   │   A dictionary representation of the model.                                                    │
│    363 │   │   """                                                                                              │
│ ❱  364 │   │   return self.__pydantic_serializer__.to_python(                                                   │
│    365 │   │   │   self,                                                                                        │
│    366 │   │   │   mode=mode,                                                                                   │
│    367 │   │   │   by_alias=by_alias,                                                                           │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
PydanticSerializationError: Error calling function `<lambda>`: AttributeError: 'str' object has no attribute 
'value'
dosubot[bot] commented 17 hours ago

The error you're encountering, PydanticSerializationError: Error calling function <lambda>: AttributeError: 'str' object has no attribute 'value', typically arises when there is an attempt to access an attribute or method on a string that doesn't exist. This can happen if a Pydantic model is expecting an object with certain attributes, but instead receives a plain string.

Here are a few steps you can take to troubleshoot and potentially resolve this issue:

  1. Check Data Types: Ensure that all data being passed to Pydantic models, especially those related to the TextNode or any other custom models, are of the expected types. If a field is expected to be an object with attributes, make sure it is not a plain string.

  2. Review Model Definitions: Look at the Pydantic models involved in the process, particularly those that might be serialized or deserialized. Ensure that the fields are correctly defined and that the data being passed matches these definitions.

  3. Debugging: Add logging or print statements before the point of failure to inspect the data being processed. This can help identify if a string is being passed where an object is expected.

  4. Check for Updates: Ensure that all packages, including LlamaIndex and its dependencies, are up to date. Sometimes, bugs are fixed in newer versions.

  5. Custom Serializers: If you have custom serialization logic (e.g., using __pydantic_serializer__), verify that it correctly handles all expected data types.

If these steps do not resolve the issue, you may need to delve deeper into the specific part of the code where the error occurs, focusing on how data is being transformed and passed to Pydantic models.

To continue talking to Dosu, mention @dosu.

Anindyadeep commented 13 hours ago

Hi, sorry but it would be great, if I get to know any possible solution of this issue. Thanks

cc: @logan-markewich @ravi03071991

logan-markewich commented 7 hours ago

@Anindyadeep what version of pydantic do you have? This seems related.

v2.10 of pydantic is very breaking, newer versions of llama-index had to pin it. Try pip install "pydantic<2.10"

Anindyadeep commented 7 hours ago

@Anindyadeep what version of pydantic do you have? This seems related.

v2.10 of pydantic is very breaking, newer versions of llama-index had to pin it. Try pip install "pydantic<2.10"

I see, makes sense, let me try to downgrade pydantic. Thanks for the headsup