Find answers from the community

Updated 3 months ago

List: load_from_dict

Hey all. Through refactoring I'm upgrading to the latest LlamaIndex version and I'm suddenly getting the error type_to_struct must be provided if type is index struct. while trying to manually construct a GPTListIndex. The code roughly looks like:
Plain Text
    index_struct = GPTListIndex.index_struct_cls.from_dict(data.get("index_struct", {}))
    docstore = DocumentStore.load_from_dict(data.get("docstore", {"docs": {}}))

    return GPTListIndex(index_struct=index_struct, docstore=docstore)

where data roughly looks like:
Plain Text
{
  "index_struct": {
    "text": null,
    "doc_id": "56c33884-3aaa-49a2-af48-43afd7e31bd1",
    "embedding": null,
    "extra_info": null,
    "nodes": [
      {
        "text": "Me: message\nYou:other message",
        "doc_id": "1b8ec128-8117-4318-a8b9-1c791b163296",
        "embedding": null,
        "extra_info": null,
        "index": 0,
        "child_indices": [],
        "ref_doc_id": "484c1022-0c19-4513-88f1-1bb4349bfbda",
        "node_info": {
          "start": 0,
          "end": 113
        }
      }
    ]
  },
  "docstore": {
    "docs": {
      "56c33884-3aaa-49a2-af48-43afd7e31bd1": {
        "text": null,
        "doc_id": "56c33884-3aaa-49a2-af48-43afd7e31bd1",
        "embedding": null,
        "extra_info": null,
        "nodes": [
          {
            "text": "Me: message\nYou:other message",,
            "doc_id": "1b8ec128-8117-4318-a8b9-1c791b163296",
            "embedding": null,
            "extra_info": null,
            "index": 0,
            "child_indices": [],
            "ref_doc_id": "484c1022-0c19-4513-88f1-1bb4349bfbda",
            "node_info": {
              "start": 0,
              "end": 113
            }
          }
        ],
        "__type__": "list"
      }
    }
  }
}

I tried passing type_to_struct={ "list": GPTListIndex }) but that produced (AttributeError: type object 'GPTListIndex' has no attribute 'from_dict'). Any guidance is appreciated πŸ™
D
1 comment
I think I found what I needed?

docstore = DocumentStore.load_from_dict(data.get("docstore", {"docs": {}}), { "list": GPTListIndex.index_struct_cls })
Add a reply
Sign up and join the conversation on Discord