I'm trying to reproduce the code from documentation: https://docs.llamaindex.ai/en/stable/examples/customization/llms/AzureOpenAI.html and receive the following error after index = VectorStoreIndex.from_documents(documents):
raise ValueError(f"Unknown document type: {type(document)}")
ValueError: Unknown document type: <class 'llama_index.legacy.schema.Document'>
Due to the fact that all these generative ai libraries are being constantly updated, I have to switch the import of SimpleDirectoryReader and make it like from llama_index.legacy.readers.file.base import SimpleDirectoryReader
All the rest is actually the same with tutorial (using llama_index==0.10.18 and python of version 3.9.16). I have spent already several hours on that and actually don't have ideas how should I proceed. So if somebody can assist with that - it would be super helpful :)
Many thanks in advance.
The error occurs because of the type of document you are passing for
VectorStoreIndex.from_documents().When you import
SimpleDirectoryReaderfrom legacy modules, the type of document isllama_index.legacy.schema.Document.You are passing that to
VectorStoreIndex, which is imported from core modules:from llama_index.core import VectorStoreIndex.The document you referred to is correct for core modules, and you can import
SimpleDirectoryReaderasfrom llama_index.core import VectorStoreIndex, SimpleDirectoryReader, and everything will work fine.If you wish to use legacy modules, then use the code below.
Output:
Here, when using legacy modules, all tools and models should be imported from the same legacy modules, and an additional service context is used for the vector store index.