Skip to main content

LlamaParse

Welcome to LlamaParse, the first public-facing release in LlamaCloud! To get started, head to cloud.llamaindex.ai. Login with the method of your choice.

Screenshot 2024-02-16 at 10.04.01 AM.png

You should now see our welcome screen. There’s two things you can do here: use LlamaParse, or create an index and optimize it in the playground (invitation-only beta, get in touch if you’d like to try it out).

The point of our new LlamaParse UI is to demonstrate our new, industry-leading PDF parsing capabilities before you integrate them into your code. Let’s go ahead and click “Parse”.

Screenshot 2024-02-16 at 10.06.24 AM.png

You now have three options: you can use LlamaParse in the UI, in Python, or as a standalone REST API that you can call from any language. We’ll take a look at all three! Let’s start with the UI method: just drag and drop any PDF into the grey box.

Screenshot 2024-02-19 at 1.47.40 PM.png

We started with a simple, PDF printout of the Wikipedia page for “Canada”. We immediately get a preview of the PDF, and the parsing process starts. Depending on the size of your PDF this can take a while.

Screenshot 2024-02-19 at 1.53.44 PM.png

If you scroll down past the PDF preview, you’ll see the results. The parser turns the PDF into Markdown, which LLMs are much more easily able to understand. Our parser understands embedded tables, will automatically parse text out of images, and handles a huge range of fonts.

Screenshot 2024-02-19 at 1.54.00 PM.png

Now let’s try the second option: using LlamaParse from Python using the llama-parse package. If you click into the “Use with LlamaIndex” section you’ll see basic instructions, but we’ll walk you through it.

Screenshot 2024-02-19 at 1.57.26 PM.png

First, we’ll need an API key. Click “API Key” down in the bottom left, and click “Generate New Key”:

Screenshot 2024-02-16 at 10.37.35 AM.png

Pick a name for your key and click “Create new key”, then copy the key that’s generated. You won’t have a chance to copy your key again!

Screenshot 2024-02-16 at 10.37.46 AM.png

Put your key in a .env file in the form LLAMA_CLOUD_API_KEY=llx-xxxxxx . If you lose your key, you can always revoke it and create a new one.

Screenshot 2024-02-16 at 10.39.14 AM.png

Set up a new python environment using the tool of your choice, we used poetry init . Then install the deps you’ll need:

pip install llama-index llama-parse python-dotenv

Now we have our libraries and our API key available, let’s create a parse.py file and parse our Canada PDF from the command line instead.

# bring in our LLAMA_CLOUD_API_KEY
from dotenv import load_dotenv
load_dotenv()

# bring in deps
from llama_parse import LlamaParse
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

# set up parser
parser = LlamaParse(
result_type="markdown" # "markdown" and "text" are available
)

# use SimpleDirectoryReader to parse our file
file_extractor = {".pdf": parser}
documents = SimpleDirectoryReader(input_files=['data/Canada.pdf'], file_extractor=file_extractor).load_data()
print(documents)

This will give you the same parsed document you saw in the UI. Let’s query this document using an LLM! Add these lines to your file:

# create an index from the parsed markdown
index = VectorStoreIndex.from_documents(documents)

# create a query engine for the index
query_engine = index.as_query_engine()

# query the engine
query = "What is the capital of Canada?"
response = query_engine.query(query)
print(response)

Which will give us this output:

The capital of Canada is Ottawa.

Congratulations! You’ve used industry-leading PDF parsing and are ready to integrate it into your app.