LlamaParse
LlamaParse is an API created by LlamaIndex to efficiently parse files, e.g. it’s great at converting PDF tables into markdown.
To use it, first login and get an API key from https://cloud.llamaindex.ai. Make sure to store the key as apiKey parameter or in the environment variable LLAMA_CLOUD_API_KEY.
Official documentation for LlamaParse can be found here.
You can then use the LlamaParseReader class to load local files and convert them into a parsed document that can be used by LlamaIndex.
See reader.ts for a list of supported file types:
Params
Section titled “Params”All options can be set with the LlamaParseReader constructor.
They can be divided into two groups.
General params:
Section titled “General params:”apiKeyis required. Can be set as an environment variableLLAMA_CLOUD_API_KEYcheckIntervalis the interval in seconds to check if the parsing is done. Default is1.maxTimeoutis the maximum timeout to wait for parsing to finish. Default is2000verboseshows progress of the parsing. Default istrueignoreErrorsset to false to get errors while parsing. Default istrueand returns an empty array on error.
Advanced params:
Section titled “Advanced params:”resultTypecan be set tomarkdown,textorjson. Defaults totext. More information aboutjsonmode on the next pages.languageprimarily helps with OCR recognition. Defaults toen.parsingInstructions?Optional. Can help with complicated document structures. See this LlamaIndex Blog Post for an example.skipDiagonalText?Optional. Set to true to ignore diagonal text. (Text that is not rotated 0, 90, 180 or 270 degrees)invalidateCache?Optional. Set to true to ignore the LlamaCloud cache. All document are kept in cache for 48hours after the job was completed to avoid processing the same document twice. Can be useful for testing when trying to re-parse the same document with, e.g. differentparsingInstructions.doNotCache?Optional. Set to true to not cache the document.fastMode?Optional. Set to true to use the fast mode. This mode will skip OCR of images, and table/heading reconstruction. Note: Non-compatible withgpt4oMode.doNotUnrollColumns?Optional. Set to true to keep the text according to document layout. Reduce reconstruction accuracy, and LLMs/embeddings performances in most cases.pageSeparator?Optional. A templated page separator to use to split the text. If the results contain{page_number}(e.g. JSON mode), it will be replaced by the next page number. If not set the default separator\\n---\\nwill be used.pagePrefix?Optional. A templated prefix to add to the beginning of each page. If the results contain{page_number}, it will be replaced by the page number.pageSuffix?Optional. A templated suffix to add to the end of each page. If the results contain{page_number}, it will be replaced by the page number.gpt4oModeDeprecated. Use vendorMultimodal params. Set to true to use GPT-4o to extract content. Default isfalse.gpt4oApiKey?Deprecated. Use vendorMultimodal params. Optional. Set the GPT-4o API key. Lowers the cost of parsing by using your own API key. Your OpenAI account will be charged. Can also be set in the environment variableLLAMA_CLOUD_GPT4O_API_KEY.boundingBox?Optional. Specify an area of the document to parse. Expects the bounding box margins as a string in clockwise order, e.g.boundingBox = "0.1,0,0,0"to not parse the top 10% of the document.targetPages?Optional. Specify which pages to parse by specifying them as a comma-separated list. First page is0.splitByPageWether to split the results, creating one document per page. Uses the setpageSeparatoror\n---\nas fallback. Default is true.useVendorMultimodalModelset to true to use a multimodal model. Default isfalse.vendorMultimodalModel?Optional. Specify which multimodal model to use. Default is GPT4o. See here for a list of available models and cost.vendorMultimodalApiKey?Optional. Set the multimodal model API key. Can also be set in the environment variableLLAMA_CLOUD_VENDOR_MULTIMODAL_API_KEY.numWorkersas in the python version, is set inSimpleDirectoryReader. Default is 1.
LlamaParse with SimpleDirectoryReader
Section titled “LlamaParse with SimpleDirectoryReader”Below a full example of LlamaParse integrated in SimpleDirectoryReader with additional options.