Comparing LlamaIndex and LlamaParse for Dense Document Questioning Answering on Vertex AI
Source notebook
Repo path:
gemini/use-cases/document-processing/doc_parsing_with_llamaindex_and_llamaparse.ipynb· Open on GitHub · intermediate
Compares LlamaIndex and LlamaParse RAG parsing methods for dense 10-Q document QA on Vertex AI.
Summary
This notebook teaches how to ingest, parse, index, and query a complex Alphabet 10-Q PDF using LlamaIndex and LlamaParse. It compares SimpleDirectoryReader, LangChainNodeParser, LlamaParse with SimpleDirectoryReader, and LlamaParse backed by Vertex AI Vector Search. The workflow uses Gemini on Vertex AI for answering and metadata extraction, text embeddings for retrieval, and query comparisons against known financial answers.
Key code patterns
Initialize Vertex AI and LlamaIndex models
import vertexai
vertexai.init(project=PROJECT_ID, location=LOCATION)
embedding_model = VertexTextEmbedding("text-embedding-005", credentials=credentials)
llm = Vertex(model="gemini-2.5-flash", temperature=0.0, max_tokens=5000)
Settings.embed_model = embedding_model
Settings.llm = llmConfigures LlamaIndex to use Vertex AI Gemini and Vertex text embeddings.
SimpleDirectoryReader RAG index
reader = SimpleDirectoryReader("./data")
documents = reader.load_data(show_progress=True)
simpledirectory_index = VectorStoreIndex.from_documents(documents)
simple_query_engine = simpledirectory_index.as_query_engine(similarity_top_k=2)Provides the baseline LlamaIndex ingestion, indexing, and query engine path.
LangChain node parsing
parser = LangchainNodeParser(RecursiveCharacterTextSplitter())
langchain_nodes = parser.get_nodes_from_documents(documents)
langchainparser_index = VectorStoreIndex(nodes=langchain_nodes)
lg_query_engine = langchainparser_index.as_query_engine(similarity_top_k=2)Shows custom chunking with LangChain before indexing nodes in LlamaIndex.
LlamaParse PDF extraction
parser = LlamaParse(
parsing_instruction="You are a financial analyst working specifically with 10Q documents...",
api_key="",
result_type="text",
language="en",
invalidate_cache=True,
)Uses LlamaParse with domain-specific parsing instructions for financial PDFs.
Metadata extraction and embedding
extractors = [
QuestionsAnsweredExtractor(questions=3, llm=llm),
KeywordExtractor(keywords=10, llm=llm),
]
pipeline = IngestionPipeline(transformations=extractors)
nodes = await pipeline.arun(documents=documents, in_place=False)
for node in nodes:
node.embedding = embedding_model.get_text_embedding(node.get_content(metadata_mode="all"))Adds question and keyword metadata to nodes, then embeds metadata-rich content for retrieval.
Vertex AI Vector Search store
vector_store = VertexAIVectorStore(
project_id=PROJECT_ID,
region=REGION,
index_id="",
endpoint_id="",
gcs_bucket_name=GCS_BUCKET,
)
vector_store.add(nodes)
lp_index = VectorStoreIndex.from_vector_store(vector_store)Persists parsed and embedded nodes into a predefined Vertex AI Vector Search index.
Models & APIs used
- Models: gemini-2.5-flash, text-embedding-005
- APIs / services: Vertex AI, Vertex AI Vector Search, Cloud Storage
- SDKs / libraries:
google-cloud-aiplatform,vertexai,llama-index,langchain-community,llama-index-embeddings-vertex,llama-index-llms-vertex,llama-index-core,llama_parse,google.auth,termcolor
When to use this
Use this pattern when comparing document parsing strategies for RAG over dense PDFs with complex financial tables.
Gotchas & caveats
- Requires an initialized Google Cloud project with Vertex AI API enabled.
- Requires a GCS bucket and a preexisting Vertex AI Vector Search index and endpoint.
- Requires a LlamaParse API key.
- Colab authentication is handled separately with google.colab.auth.authenticate_user().
- The notebook refreshes Google credentials and uses a quota_project_id value in google.auth.default().
- The LlamaParse API key, Vector Search index ID, and deployed index endpoint ID are left blank for the user to fill.
- The notebook restarts the IPython kernel after setting up LlamaIndex model settings.
Best practices
- Compare multiple parsing approaches against the same source document and query set.
- Use similarity_top_k=2 consistently across query engines for apples-to-apples comparison.
- Use domain-specific parsing instructions for LlamaParse on 10-Q financial documents.
- Extract question and keyword metadata from parsed nodes before embedding for richer retrieval.
- Print response source nodes, relevance scores, file names, page labels, and file paths for answer inspection.
- Use an answer key with citation pages to evaluate generated answers.
Related
- Concepts: RAG & Grounding · Embeddings & Vector Search · Applied Use Cases
- Entities: Vertex AI · Vertex AI SDK · LlamaIndex · Vector Search · Cloud Storage · Gemini
- Area: Gemini Notebooks
- Best practices: RAG & Grounding - Best Practices · Embeddings & Vector Search - Best Practices · Applied Use Cases - Best Practices