Skip to main content

LlamaIndex Node_Parser Integration: TopicNodeParser

Implements the topic node parser described in the paper MedGraphRAG, which aims to improve the capabilities of LLMs in the medical domain by generating evidence-based results through a novel graph-based Retrieval-Augmented Generation framework, improving safety and reliability in handling private medical data.

TopicNodeParser implements an approximate version of the chunking technique described in the paper.

Here is the technique as outlined in the paper:

Large medical documents often contain multiple themes or diverse content. To process these effectively, we first segment the document into data chunks that conform to the context limitations of Large Language Models (LLMs). Traditional methods such as chunking based on token size or fixed characters typically fail to detect subtle shifts in topics accurately. Consequently, these chunks may not fully capture the intended context, leading to a loss in the richness of meaning.

To enhance accuracy, we adopt a mixed method of character separation coupled with topic-based segmentation. Specifically, we utilize static characters (line break symbols) to isolate individual paragraphs within the document. Following this, we apply a derived form of the text for semantic chunking. Our approach includes the use of proposition transfer, which extracts standalone statements from a raw text Chen et al. (2023). Through proposition transfer, each paragraph is transformed into self-sustaining statements. We then conduct a sequential analysis of the document to assess each proposition, deciding whether it should merge with an existing chunk or initiate a new one. This decision is made via a zero-shot approach by an LLM. To reduce noise generated by sequential processing, we implement a sliding window technique, managing five paragraphs at a time. We continuously adjust the window by removing the first paragraph and adding the next, maintaining focus on topic consistency. We set a hard threshold that the longest chunk cannot excess the context length limitation of LLM. After chunking the document, we construct graph on each individual of the data chunk.

Installation

pip install llama-index-node-parser-topic

Usage

from llama_index.core import Document
from llama_index.node_parser.topic import TopicNodeParser

node_parser = TopicNodeParser.from_defaults(
    llm=llm,
    max_chunk_size=1000,
    similarity_method="llm",  # can be "llm" or "embedding"
    # embed_model=embed_model,  # used for "embedding" similarity_method
    # similarity_threshold=0.8,  # used for "embedding" similarity_method
    window_size=2,  # paper suggests window_size=5
)

nodes = node_parser(
    [
        Document(text="document text 1"),
        Document(text="document text 2"),
    ],
)

Metadata

Release files for llama-index-node-parser-topic 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-node-parser-topic 0.5.0
File Size Uploaded Provenance Actions
llama_index_node_parser_topic-0.5.0.tar.gz 7.6 kB Without provenance Details for llama_index_node_parser_topic-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-node-parser-topic 0.5.0
File Interpreter ABI Platform Actions
llama_index_node_parser_topic-0.5.0-py3-none-any.whl Python 3 none any Details for llama_index_node_parser_topic-0.5.0-py3-none-any.whl

Total release size: 15.0 kB

Release files / llama_index_node_parser_topic-0.5.0.tar.gz

Download URL llama_index_node_parser_topic-0.5.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6054e63bf58e99cff4337ba685f5cd16f44e40cf4186c1f728eae641b8c32fb8
BLAKE2b-256 checksum
How to use checksums
5770f05f440976aa933fe4937d3a7e8776359f1370451e36572de3e5a1f46dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_node_parser_topic-0.5.0-py3-none-any.whl

Download URL llama_index_node_parser_topic-0.5.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db208fa48e84ee7280fc6a60c6f15c4d66810c25998bede437a6bd5fa297ba9b
BLAKE2b-256 checksum
How to use checksums
160e38aa6513969b00723910e7f5c0939339912bc3b662cdcb22080d765be0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-node-parser-topic 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page