OntoPrune
Neuro-Symbolic Context Pruning Middleware for Local SLMs and Cloud LLMs
English | Español | 📄 Technical Whitepaper (PDF) | 📄 Whitepaper en Español (PDF)
OntoPrune is an ultra-lightweight (<12ms CPU) neuro-symbolic middleware that transforms multi-file source code into minimal dependency contracts. By isolating closed-world functional boundaries before attention computation, OntoPrune slashes input tokens by 83% to 92.4%, collapses Time-to-First-Token ($TTFT$) by 6.7x on CPU-bound local Small Language Models (SLMs), and guarantees 0% API hallucinations.
🚀 Multi-Language Empirical Benchmarks
Real-world evaluation across multi-file enterprise projects in four major software ecosystems:
| Ecosystem & Framework | Raw Project Context | OntoPrune Context (stubs) |
Token Reduction | Estimated TTFT Speedup |
|---|---|---|---|---|
| Python (Async Services) | 2,815 tokens | 393 tokens | -86.0% | 6.7x faster |
| Flutter / Dart (State & UI) | 1,650 tokens | 135 tokens | -91.8% | ~7.0x faster |
| Java / Spring Boot (Enterprise @Service) | 1,450 tokens | 110 tokens | -92.4% | ~7.2x faster |
| TypeScript / React (Frontend & APIs) | 1,380 tokens | 105 tokens | -92.4% | ~7.1x faster |
Local CPU Inference Benchmark (Qwen 2.5 Coder 3B via Ollama)
| Metric | Naive (Full File) | OntoPrune (stubs) |
Real Gain |
|---|---|---|---|
| CPU Overhead | 0.02 ms | 9.9 ms | $\le 10\text{ ms}$ (Target: $\le 15\text{ ms}$) |
| Input Tokens | 2,390 tokens | 406 tokens | -83.0% ($\approx 6\text{x}$ reduction) |
| TTFT (Time-to-First-Token) | 22.4 s | 3.3 s | 6.7x faster (saves 19.1 s) |
| Total Generation Time | 59.9 s | 16.5 s | -72.5% ($3.6\text{x}$ faster) |
| API Hallucinations | 1 invalid method | 0 invalid methods | 100% Contract Compliance |
📦 Installation
# Standard installation (native Python support):
pip install ontoprune
# With multi-language support (Flutter/Dart, Java, TypeScript via Tree-sitter):
pip install "ontoprune[languages]"
# For development, benchmarks, and tests:
pip install "ontoprune[dev,benchmark,languages]"
🌐 Universal Multi-Language Support
OntoPrune automatically detects file types and resolves dependencies across project boundaries:
| Language | Extension | AST Engine | Output Format |
|---|---|---|---|
| Python | .py |
Native Python ast |
def name(args) -> Ret: ... |
| Flutter / Dart | .dart |
tree-sitter-dart |
abstract class ... { Ret method(); } |
| Java / Spring Boot | .java |
tree-sitter-java |
public interface ... { Ret method(); } |
| TypeScript / React | .ts, .tsx, .js |
tree-sitter-typescript |
export interface ... { method(): Ret; } |
🛠️ Usage Modes
1. Native Model Context Protocol (MCP) Server
OntoPrune runs out of the box as an MCP server (ontoprune-mcp) compatible with Claude Desktop, Cursor, Gemini CLI, or Antigravity IDE:
ontoprune-mcp
Configuration in claude_desktop_config.json:
{
"mcpServers": {
"ontoprune": {
"command": "ontoprune-mcp"
}
}
}
Exposed MCP Tools:
prune_context(file_path, target_symbol, format='stubs'): Extracts the minimal dependency contract resolving cross-file imports.verify_response(response_code, contract_or_file): Deterministically validates generated code against authorized contracts.
2. Command Line Interface (CLI)
# Prune a target method across multi-file projects:
ontoprune translate src/services/OrderService.java processOrder --format stubs
# Direct streaming pipeline with local Ollama:
ontoprune translate services/order_service.py procesar_orden | ollama run qwen2.5-coder:3b
# Deterministically verify LLM output against contract:
ontoprune check --file generated_solution.py --contract contract.py
3. Python API
import ontoprune
# 1. Prune a multi-module project to a minimal typed contract
context = ontoprune.translate(
"services/order_service.py",
target="procesar_orden",
fmt="stubs",
multi_module=True,
)
print(context)
# 2. Verify model output against the contract
violations = ontoprune.check(llm_code_response, against=context)
if not violations:
print("Code is 100% compliant and free of hallucinations!")
🧪 Test Suite
uv run pytest
# 45 passed in 1.19s
📄 Whitepapers & Publications
- English Technical Whitepaper (PDF)
- Whitepaper Técnico en Español (PDF)
- Community Article / Blog Post
- Artículo Comunitario en Español
👤 Author
Vigmar Carlo
- GitHub: @vigmarcarlo
- Repository: https://github.com/vigmarcarlo/OntoPrune
- License: MIT
Metadata
Release files for ontoprune 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ontoprune-0.2.0.tar.gz | 337.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ontoprune-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 371.1 kB
Release files / ontoprune-0.2.0.tar.gz
| Download URL | ontoprune-0.2.0.tar.gz |
|---|---|
| Size | 337.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e70518e0e1926265ac5f34f12ff24d966ed5275ed0ae7d3f0625e00e677dd082
|
|
BLAKE2b-256 checksum How to use checksums |
5c6d779c3c10a2c70befdd522d67c3abcf538c22d7fda43b0c371a59dbb0bd4f
|
| 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":"Linux Mint","version":"21.1","id":"vera","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ontoprune-0.2.0-py3-none-any.whl
| Download URL | ontoprune-0.2.0-py3-none-any.whl |
|---|---|
| Size | 33.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b3e9479dc10d19218266bcc9fff9f8734ef57f9be21ec40aa51ab002c9c635d
|
|
BLAKE2b-256 checksum How to use checksums |
df524f82b4bbe0afb744c72b7f0e2e17e9ca2f732696bc650060d2b90dd2c19c
|
| 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":"Linux Mint","version":"21.1","id":"vera","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|