Skip to content

LlamaIndex Integration

LlamaIndex's built-in SentenceSplitter and HierarchicalNodeParser handle basic chunking, but they still produce isolated text fragments without structural context. POMA's LlamaIndex integration replaces the parsing step with chunkset nodes — structure-aware units that preserve the full document hierarchy from section headers down to individual sentences.

The integration provides drop-in replacements for LlamaIndex's document loading, node parsing, and retrieval steps — your existing index and query engine code stays the same.

Installation

Install the integration:

bash
pip install 'poma[llamaindex]'

The LlamaIndex integration gives you three helpers:

  • PomaFileReader to load supported files into Document objects
  • PomaChunksetNodeParser to turn documents into structure-aware nodes
  • PomaCheatsheetRetrieverLI to wrap an existing retriever and return cheatsheet nodes

Parse documents into chunkset nodes

python
from poma import PrimeCut
from poma.integrations.llamaindex import PomaFileReader, PomaChunksetNodeParser

client = PrimeCut()
documents = PomaFileReader().load_data("./docs")
parser = PomaChunksetNodeParser(client=client)
nodes = parser.get_nodes_from_documents(documents, show_progress=True)

print(len(nodes))
print(nodes[0].metadata.keys())

Each node keeps the original chunkset data and the matching chunks in metadata. The parser expects each input document to carry a valid metadata["source_path"].

Wrap an existing retriever

python
from llama_index.core import VectorStoreIndex
from poma.integrations.llamaindex import PomaCheatsheetRetrieverLI

index = VectorStoreIndex(nodes)
base_retriever = index.as_retriever(similarity_top_k=4)
retriever = PomaCheatsheetRetrieverLI(base_retriever)

response = retriever.as_query_engine().query("How do I authenticate?")
print(str(response))

PomaCheatsheetRetrieverLI groups hits by document and returns a structure-preserving cheatsheet per document.

Why replace SentenceSplitter?

LlamaIndex's SentenceSplitter and even HierarchicalNodeParser still treat documents as flat text — they pick better cut points, but the resulting nodes are still isolated fragments without structural context. POMA's PomaChunksetNodeParser preserves the document's hierarchy as chunkset nodes, so retrieval returns facts with their full lineage (section → subsection → paragraph). The result: more accurate answers with typically 77% fewer tokens.

For a detailed comparison of all chunking strategies, see The Ultimate Guide to RAG Chunking Strategies.

Continue reading