Skip to main content

Plug-and-play, zero-shot document processing pipelines.

Project description



GitHub Actions Workflow Status GitHub top language PyPI - Version PyPI - Status Code style: black codecov DOI

A Unified Interface for Document AI Applications.

sieves provides a stable, framework-agnostic abstraction for building document AI pipelines. Just as sqlalchemy provides a unified interface for interchangeable database drivers, sieves offers a consistent API for predictive tasks while allowing you to swap the underlying language model frameworks without changing your core application logic.

This approach recognizes that different LM frameworks excel at different aspects of language model development:

  • outlines for high-performance, strictly constrained structured generation with local models.
  • dspy for sophisticated prompt optimization and few-shot example tuning.
  • langchain for broad compatibility with proprietary APIs and existing ecosystems.
  • gliner2 or transformers zero-shot pipelines for specialized, low-latency local inference.

sieves unifies the entire workflow:

  1. Ingestion: Parsing PDFs, images, and Office docs (via docling).
  2. Preprocessing: Intelligent text chunking and windowing (via chonkie).
  3. Prediction: Zero-shot structured generation using a unified interface. Supports multiple backends: dspy, langchain, outlines, gliner2, transformers zero-shot classification pipelines
  4. Distillation: Distill a specialized local model from zero-shot predictions (via setfit and model2vec).

Define your task pipeline once, then swap execution engines without rewriting your pipeline logic. Use the task library to skip having to define tasks from scratch.

[!WARNING] sieves is in active development (Beta). The API is stable within minor versions, but we recommend pinning your version for production use.

Features

  • :dart: Zero Training Required: Immediate inference using zero-/few-shot models
  • :robot: Unified Generation Interface: Seamlessly use multiple libraries
  • :arrow_forward: Observable Pipelines: Easy debugging and monitoring with conditional task execution
  • :hammer_and_wrench: Integrated Tools:
  • :label: Ready-to-Use Tasks:
    • Multi-label classification
    • Information extraction
    • Summarization
    • Translation
    • Multi-question answering
    • Aspect-based sentiment analysis
    • PII (personally identifiable information) anonymization
    • Named entity recognition
  • :floppy_disk: Persistence: Save and load pipelines with configurations
  • :rocket: Optimization: Improve task performance by optimizing prompts and few-shot examples using DSPy's MIPROv2
  • :teacher: Distillation: Fine-tune smaller, specialized models using your zero-shot results with frameworks like SetFit and Model2Vec. Export results as HuggingFace Dataset for custom training.
  • :recycle: Caching to avoid unnecessary model calls

Quick Start

1. Install

pip install sieves

Requires Python 3.12 (due to dependency constraints in docling and pyarrow).

2. Basic: text classification with a small local model

import outlines
import transformers
from sieves import Pipeline, tasks, Doc

# Set up model.
model_name = "HuggingFaceTB/SmolLM2-135M-Instruct"
model = outlines.models.from_transformers(
    transformers.AutoModelForCausalLM.from_pretrained(model_name),
    transformers.AutoTokenizer.from_pretrained(model_name)
)

# Define task.
task = tasks.Classification(labels=["science", "politics"], model=model)

# Define pipeline with the classification task.
pipeline = Pipeline(task)

# Define documents to analyze.
doc = Doc(text="The new telescope captures images of distant galaxies.")

# Run pipeline and print results.
results = list(pipeline([doc]))
docs = list(pipeline([doc]))
# The `results` field contains the structured task output.
print(docs[0].results) # {'Classification': [('science', 1.0), ('politics', 0.0)]}
# The `meta` field contains more information helpful for observability and debugging, such as raw model output and token count information.
print(docs[0].meta)    # {'Classification': {
                       #    'raw': ['{ "science": 1.0, "politics": 0 }'],
                       #    'usage': {'input_tokens': 2, 'output_tokens': 2, 'chunks': [{'input_tokens': 2, 'output_tokens': 2}]}}, 'usage': {'input_tokens': 2, 'output_tokens': 2}
                       #  }

3. Advanced: End-to-end document AI with a hosted LLM

This example demonstrates the full power of sieves: parsing a PDF, chunking it, and extracting structured data (equations) using a remote LLM via DSPy.

Requires pip install "sieves[ingestion]"

import dspy
import os
import pydantic
import chonkie
import tokenizers
from sieves import tasks, Doc

# Define which schema of entity to extract.
class Equation(pydantic.BaseModel, frozen=True):
    id: str = pydantic.Field(description="ID/index of equation in paper.")
    equation: str = pydantic.Field(description="Equation as shown in paper.")

# Setup DSPy model.
model = dspy.LM(
    "openrouter/google/gemini-3-flash-preview",
    api_base="https://openrouter.ai/api/v1/",
    api_key=os.environ["OPENROUTER_API_KEY"]
)

# Build pipeline: ingest -> chunk -> extract.
pipeline = (
    tasks.Ingestion() +
    tasks.Chunking(chonkie.TokenChunker(tokenizers.Tokenizer.from_pretrained("gpt2"))) +
    tasks.InformationExtraction(entity_type=Equation, model=model)
)

# Define docs to analyze.
doc = Doc(uri="https://arxiv.org/pdf/1204.0162")

# Run pipeline.
results = list(pipeline([doc]))

# Print esults.
for equation in results[0].results["InformationExtraction"]:
    print(equation)

This gives us:

id='(1)' equation="the observer measures not the linear but angular ... both cars are near the stop sign."
id='(3)' equation='\\omega(t) = \\frac{r_0 v(t)}{r_0^2 + x(t)^2}'
id='(4)' equation='\\tan \\alpha(t) = \\frac{x(t)}{r_0}'
id='(5)' equation='x(t) = \\frac{a_0 t^2}{2}'
id='(6)' equation="\\frac{d}{dt} f(t) = f'(t)"
id='(7)' equation='\\omega(t) = \\frac{a_0 t}{r_0} \\left( 1 + \\frac{a_0^2 t^4}{4 r_0^2} \\right)^{-1}'
id='(8)' equation='x(t) = x_0 + v_0 t + \\frac{1}{2} a t^2'

[Read the guides](https://sieves.ai/guides/getting_started)


Why sieves?

Building Document AI prototypes usually involves gluing together disparate tools: one library for PDF parsing, another for chunking, a third for LLM interaction, another one for distillation, and so on. Switching from one model/framework stack, e.g., using Outlines with a local model, to a different one, e.g. LangChain with a closed vendor LLM, often requires rewriting core logic and boilerplate.

sieves solves this by providing a vertical stack optimized for Document AI.

Best for:

  • Document AI: End-to-end pipelines from raw file to structured data.
  • Rapid Prototyping: Validate ideas quickly with zero-shot models; no training data needed.
  • Backend Flexibility: Switch between Local (GLiNER, Outlines) and Remote (DSPy, LangChain) execution instantly.
  • Observability: Built-in inspection of intermediate steps (chunks, prompts).

Not for:

  • ❌ Chatbots or conversational agents.
  • ❌ Simple, one-off LLM completion calls.

Feature Comparison

Feature sieves langchain dspy outlines transformers gliner2
Primary Focus Document AI General LLM apps Declarative LM development Structured generation Modeling Extraction
Backend Support Universal Own ecosystem Own ecosystem Own ecosystem Own ecosystem Specialized
Document Parsing Built-in Tool integrations ❌ No ❌ No ❌ No ❌ No
Structured Output Unified Pydantic API Framework-specific Framework-specific Core feature ⚠️ Limited Core feature
Prompt Optimization DSPy Integration ❌ No ✅ Core feature ❌ No ❌ No ❌ No
Model Distillation setfit/model2vec ❌ No ✅ Yes ❌ No ⚠️ Manual ❌ No

Core Concepts

  • Doc: The atomic unit of data. Holds raw text, metadata, parsed content, and extraction results.
  • Task: A functional step in the pipeline (e.g., Ingestion, Chunking, NER, Classification).
  • Pipeline: A composable sequence of tasks that manages execution flow, caching, and state.

Supported Backends

sieves allows you to bring your own model backend. We support:

  • DSPy: For optimizing prompts and working with remote/local models via LiteLLM.
  • Outlines: For strictly constrained structured generation with local models.
  • LangChain: For broad compatibility with the LangChain ecosystem.
  • GLiNER2: For high-performance, small-model Named Entity Recognition.
  • Transformers: For standard Hugging Face zero-shot classification pipelines.

See the Model Setup Guide for configuration details.

Installation

pip install sieves

Optional extras:

pip install "sieves[ingestion]"  # PDF/DOCX parsing (docling, marker)
pip install "sieves[distill]"    # Model distillation (setfit, model2vec)

Community & Support

Attribution

sieves is inspired by the design philosophy of spaCy and spacy-llm.

Sieve icons created by Freepik - Flaticon.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sieves-0.24.0.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sieves-0.24.0-py3-none-any.whl (599.8 kB view details)

Uploaded Python 3

File details

Details for the file sieves-0.24.0.tar.gz.

File metadata

  • Download URL: sieves-0.24.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sieves-0.24.0.tar.gz
Algorithm Hash digest
SHA256 85095be3fa8bc88c75d984f4c914807d75e374b6810a3322f4335cc36caddd16
MD5 881c76ee7cde9e69b1d105c36f00c9a6
BLAKE2b-256 807bf4cd075106b382126592ff1004a881a36a4bb8e7c4da890905c6a41eacb7

See more details on using hashes here.

File details

Details for the file sieves-0.24.0-py3-none-any.whl.

File metadata

  • Download URL: sieves-0.24.0-py3-none-any.whl
  • Upload date:
  • Size: 599.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sieves-0.24.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7e1f3b459e3586ab1c06cc64b143d31e65849d5c5719f1d4228d10da33bcbb4
MD5 1031b0cbae314bae23111b51e4138b56
BLAKE2b-256 2239bf5dca07500e17b02445550102d2df7ffabe1fa49db544bc3125096f3ac6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page