Skip to main content

TopoRAG

TopoRAG is a Topological Data Analysis (TDA) library designed to detect conceptual gaps and blind spots in text documents, specifically useful for evaluating the context retrieved in Retrieval-Augmented Generation (RAG) pipelines.

By using Persistent Homology (via Ripser), it identifies topological "holes" in the semantic embedding space of your text, and then uses an LLM to label those missing concepts.

Installation

pip install toporag

(Note: Currently in development, install from source)

git clone <repository>
cd toporag_lib
pip install -e .

Setup

You need an OpenAI API key for text embeddings (text-embedding-3-small) and gap labeling (gpt-4o-mini).

export OPENAI_API_KEY="sk-..."

Basic Usage

import asyncio
from toporag import TopoAnalyzer

async def main():
    analyzer = TopoAnalyzer() # Automatically picks up OPENAI_API_KEY
    
    texto = """
    We started the project with great enthusiasm. The team was assembled, 
    requirements were gathered, and we had a solid plan for the architecture.
    
    Finally, we deployed the application to production and celebrated our success. 
    The customers loved the final result and our metrics improved dramatically.
    """
    
    gaps = await analyzer.analyze_text(texto)
    for gap in gaps:
        print(f"Missing Topic: {gap['topic_label']}")
        print(f"Explanation: {gap['explanation']}")
        print("---")

if __name__ == "__main__":
    asyncio.run(main())

API

TopoAnalyzer.analyze_text(text: str, threshold: float = 0.15, max_holes: int = 5, generate_suggestions: bool = True)

Splits the text into segments, embeds them, finds gaps with persistence above threshold, and uses the LLM to label up to max_holes gaps.

TopoAnalyzer.analyze_url(url: str, ...)

Scrapes the URL for readable text and runs the topological analysis.

TopoAnalyzer.analyze_segments(segments: List[str], ...)

Runs the analysis directly on a pre-chunked list of strings.

Metadata

Release files for toporag 0.1.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 toporag 0.1.0
File Size Uploaded
toporag-0.1.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toporag 0.1.0
File Interpreter ABI Platform
toporag-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / toporag-0.1.0.tar.gz

Download URL toporag-0.1.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a2d1f4d6b01c5618ab6785bbaea1f9cf438e02f69cd92e2be6724005575351d6
BLAKE2b-256 checksum
How to use checksums
9ee40be1cf34110a1b7ea26c01380bb7814ad81971cd522c3a0d6c014cd930b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / toporag-0.1.0-py3-none-any.whl

Download URL toporag-0.1.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81f10dcd7aa6cf7847a7426789071ded08fee3f03687082c63e1c655e5a0f9b9
BLAKE2b-256 checksum
How to use checksums
c338ae55b18edd891d1ae16d0d881f09c7a9b4f2e40c06fa24fadf09f5560553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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