Skip to main content

🧩🔎 fragmenter

uv PyPI Python Version Tests License Code style: ruff Conventional Commits

Build powerful RAG (Retrieval-Augmented Generation) systems with multiple LLM providers and zero configuration hassle.


✨ Features

  • 🤖 Multiple LLM Providers: OpenAI, Anthropic, Ollama, and HuggingFace support out-of-the-box
  • 🔄 Smart Incremental Updates: Only processes changed files — no wasted computation
  • 📄 Intelligent Parsing: Automatic file-type detection for Markdown, Code, PDF, and more
  • 🎨 Beautiful CLI: Rich formatting with colors and progress indicators
  • 🌐 Web Scraping: Built-in scraper to ingest content from websites
  • 💾 Vector Store Persistence: Save and reload indexes efficiently
  • 🔍 Code Extraction: Automatically extract code blocks from LLM responses
  • ⚙️ Environment-Based Config: Simple .env file configuration
  • 🚀 Zero-Code Usage: CLI tools for complete workflows without writing code
  • 📦 Library Mode: Full programmatic API for custom integrations

📦 Installation

# Install globally as a tool
uv tool install 'fragmenter[openai]'

# Or run instantly without installing
uvx fragmenter init

Add as a project dependency

Install the core package plus the provider(s) you need:

# Pick one (or more) LLM provider extras:
uv add 'fragmenter[openai]'        # OpenAI  (default provider)
uv add 'fragmenter[anthropic]'      # Anthropic
uv add 'fragmenter[ollama]'         # Ollama  (local models)
uv add 'fragmenter[huggingface]'    # HuggingFace

# Or combine several:
uv add 'fragmenter[openai,ollama]'

# Or install everything:
uv add 'fragmenter[all-providers]'

Traditional pip install

pip install 'fragmenter[openai]'

🚀 Quick Start

Prerequisites

Before you begin, ensure you have:

  • Python: 3.12 or higher ✅
  • API Keys: For your chosen LLM provider (OpenAI, Anthropic, etc.) 🔑

1. Initialize your project

# Create .env template
fragmenter init

Edit the generated .env file with your API credentials:

# .env
OPENAI_API_KEY=sk-your-actual-key-here
LLM_PROVIDER=openai
LLM_MODEL=gpt-4o-mini
EMBED_PROVIDER=openai
EMBED_MODEL=text-embedding-3-small

2. Prepare your data

# Create data directory
mkdir data

# Add your documents (markdown, code, PDFs, etc.)
cp /path/to/your/docs/* ./data/

3. Build the index

fragmenter rebuild-index \
    --data-dir ./data \
    --storage-dir ./vector_store

What happens next? 🎬

  1. 📁 Scans your data directory
  2. 🔍 Detects file types and applies appropriate parsers
  3. ✂️ Chunks documents intelligently
  4. 🧮 Generates embeddings
  5. 💾 Stores vectors for fast retrieval

4. Query your data

# Ask a question
fragmenter query \
    --storage-dir ./vector_store \
    --query "What is this data about?"

🛠️ CLI Tools

init

Create a .env template file in your project.

fragmenter init

scrape

Scrape content from websites and save as markdown or HTML.

# Scrape as markdown (default)
fragmenter scrape \
    https://example.com \
    -o ./data

# Scrape as HTML
fragmenter scrape \
    https://example.com \
    -o ./data \
    --format html

rebuild_index

Build or update the RAG index with automatic incremental updates.

fragmenter rebuild-index \
    --data-dir ./data \
    --storage-dir ./vector_store

query_index

Query the index with natural language.

# Basic query
fragmenter query \
    -s ./vector_store \
    -q "Your question here"

# Query from file
fragmenter query \
    -s ./vector_store \
    -f question.txt

# Save output
fragmenter query \
    -s ./vector_store \
    -q "Generate code" \
    -o output.cpp \
    --code-only \
    --language cpp

# Use different provider
fragmenter query \
    -s ./vector_store \
    -q "Explain this" \
    --llm-provider anthropic \
    --llm-model claude-3-5-sonnet-20241022

inspect_index

View index statistics and contents.

fragmenter inspect-index \
    -s ./vector_store

⚙️ Configuration

All settings can be configured via environment variables. Create a .env file or set them in your shell.

LLM Providers

Provider Extra Configuration
OpenAI [openai] LLM_PROVIDER=openai
LLM_MODEL=gpt-4o-mini
Anthropic [anthropic] LLM_PROVIDER=anthropic
LLM_MODEL=claude-3-5-sonnet-20241022
Ollama [ollama] LLM_PROVIDER=ollama
LLM_MODEL=llama3.2
HuggingFace [huggingface] LLM_PROVIDER=huggingface
LLM_MODEL=meta-llama/Llama-3.2-3B-Instruct

Embedding Providers

Provider Configuration
OpenAI EMBED_PROVIDER=openai
EMBED_MODEL=text-embedding-3-small
HuggingFace EMBED_PROVIDER=huggingface
EMBED_MODEL=BAAI/bge-small-en-v1.5
Ollama EMBED_PROVIDER=ollama
EMBED_MODEL=nomic-embed-text

Complete .env Example

# LLM Configuration
OPENAI_API_KEY=sk-your-key-here
LLM_PROVIDER=openai
LLM_MODEL=gpt-4o-mini

# Embedding Configuration
EMBED_PROVIDER=openai
EMBED_MODEL=text-embedding-3-small

# Optional: Anthropic
ANTHROPIC_API_KEY=sk-ant-your-key-here

# Optional: HuggingFace
HUGGINGFACE_TOKEN=hf_your-token-here

💻 Using as a Library

If you need custom logic or want to integrate into your own application:

from dotenv import load_dotenv
from fragmenter.config import RAGSettings
from fragmenter.rag.ingestion import build_index
from fragmenter.rag.inference import load_index, query_index

# Load configuration
load_dotenv()
settings = RAGSettings()
settings.configure_llm_settings()

# Build index
build_index(input_dir="./data", persist_dir="./vector_store")

# Query
index = load_index("./vector_store")
response = query_index(index, "Your question")
print(response)

🌱 Usage Examples

Example 1: Documentation RAG

Build a RAG system for your project documentation:

# 1. Scrape your docs site
fragmenter scrape \
    https://docs.example.com \
    -o ./data/docs

# 2. Build the index
fragmenter rebuild-index \
    -d ./data \
    -s ./vector_store

# 3. Query
fragmenter query \
    -s ./vector_store \
    -q "How do I configure authentication?"

Example 2: Code Analysis

Analyze a codebase and generate examples:

# 1. Copy code files to data directory
cp -r /path/to/project/src ./data/

# 2. Build index
fragmenter rebuild-index -d ./data -s ./vector_store

# 3. Generate code examples
fragmenter query \
    -s ./vector_store \
    -q "Show me how to use the authentication module" \
    -o example.py \
    --code-only \
    --language python

Example 3: Research Assistant

Build a research assistant for papers and articles:

# 1. Add PDFs and markdown files to data/
# 2. Build index
fragmenter rebuild-index -d ./data -s ./vector_store

# 3. Query with different providers
fragmenter query \
    -s ./vector_store \
    -q "Summarize the key findings about neural networks" \
    --llm-provider anthropic \
    --llm-model claude-3-5-sonnet-20241022

🔧 Troubleshooting

� Missing Provider Errors

�🔐 Authentication Errors

📁 File Parsing Issues

💾 Vector Store Errors

🌐 Provider-Specific Issues

Ollama:

# Ensure Ollama is running
ollama serve

# Pull the model first
ollama pull llama3.2

HuggingFace:

  • Set HUGGINGFACE_TOKEN for private models
  • Some models require acceptance of terms on HuggingFace website

🛠️ Development

Setup

git clone https://github.com/RISE-Dependable-Transport-Systems/fragmenter.git
cd fragmenter
uv sync --all-groups

Common Tasks

just lint              # Run all linters via pre-commit
just fmt               # Auto-format code
just test              # Run unit tests
just test-cov          # Run tests with coverage
just build             # Build sdist and wheel
just check-all         # Lint + test
just all               # Full pipeline: clean → install → lint → test → build → verify → install-test

📖 Examples

  • Complete Real-World Example: See examples/waywise for a full setup with custom data, configuration, and evaluation scripts.
  • Developer Example: See examples/dev_examples/main.py for a programmatic usage demonstration of the RAG framework.

🙌 Contributing

Contributions welcome! Please ensure:

  • ✅ Code is formatted (just fmt)
  • ✅ All linters pass (just lint)
  • ✅ Tests pass (just test)
  • ✅ New features include tests and documentation
  • 🔒 No API keys or secrets in commits

📄 License

MIT License — see LICENSE file for details.

Metadata

Release files for fragmenter 0.1.1

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

Source distribution (sdist)

Source distribution for fragmenter 0.1.1
File Size Uploaded Provenance Actions
fragmenter-0.1.1.tar.gz 40.6 kB Without provenance Details for fragmenter-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 87.5 kB

Release files / fragmenter-0.1.1.tar.gz

Download URL fragmenter-0.1.1.tar.gz
Size 40.6 kB
Tags Source
SHA-256 checksum
How to use checksums
30f79d08a69eef1277c4a7fa03f775cb7a6933ba828ff48d35ae737fde159022
BLAKE2b-256 checksum
How to use checksums
0e10ad820e354dceb1d031906fa2d1dabf9293575334eb1c079814bdf163c26c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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 / fragmenter-0.1.1-py3-none-any.whl

Download URL fragmenter-0.1.1-py3-none-any.whl
Size 46.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39f82cac025c52f0589eeb76b995fd16af2c3a1ed89123544721d6deaeae4b43
BLAKE2b-256 checksum
How to use checksums
aaef0a997c0963656703246f64c0dac2840d5839fec5c59fb5050c44baaa43b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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 fragmenter 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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