How mantisai/sieves works
Project Type and Purpose
• Type: A library/toolkit (not a full-stack app) for zero- and few-shot NLP using structured generation.
• Purpose: Provide a unified, document-based pipeline for preprocessing, prompting LLMs (via multiple backends), and postprocessing, all with caching, serialization, and observability.
File Structure
• Top-level modules:
– sieves/data: document abstractions and parsers
– sieves/engines: core Engine class, wrappers, and adapter “Bridge” imports for each backend (dspy, gliner, huggingface, etc.)
– sieves/pipeline: pipeline orchestration and execution logic
– sieves/tasks: individual Task classes grouped by preprocessing, predictive, and postprocessing
– sieves/serialization.py: pipeline and Doc persistence
• Configuration/build: pyproject.toml, setup.py, mkdocs.yml, GitHub workflows, tests.
• Docs: extensive mkdocs-based documentation covering guides, pipelines, engines, tasks.
README for Architectural Insights
• Core abstractions: Pipeline, Doc, Task, Engine, Bridge
• Pattern: pipeline of tasks, each task instantiates a Bridge to connect to an Engine, which in turn standardizes calls to various structured-generation backends.
• Features: caching, serialization, extensibility for new tasks/engines.
Main Components
a. Pipeline (orchestrator)
b. Doc (data carrier)
c. Task nodes (preprocessing, predictive, postprocessing)
d. Bridge adapters (engine-specific prompt templates and type handlers)
e. Engine abstraction (unified interface)
f. External Model Backends (dspy, outlines, huggingface transformers, instructor, ollama, etc.)
g. Caching layer (prevents redundant calls)
h. Serialization store (pipeline.yml, pickled Docs)
i. Optional utilities: chunkers (chonkie), parsers (docling, marker, unstructured)
Relationships and Interactions
• Within Pipeline: for each Task:
Doc → Task → Bridge → Engine → Model Backend → Engine → Bridge → Task → Doc.results
• Caching: sits between Bridge/Engine and backends, intercepts requests/responses
• Serialization: Pipeline dump/load connects to disk storage (YAML + pickled state)
Architectural Patterns and Principles
• Pipeline pattern: sequential, configurable task graph
• Adapter/Bridge pattern: decouple Tasks from diverse backends via Bridge → Engine
• Single source of truth: Doc carries state/results
• Modular/extensible: plugin points in sieves/tasks and sieves/engines
• Separation of concerns: parsing, chunking, prompting, distillation, serialization
Technologies, Frameworks, Libraries
• Core: Python 3, pytest, black, mkdocs
• External libs: docling, unstructured, marker, chonkie, LangChain, HuggingFace Transformers, dspy, ollama, outlines
• CI/CD: GitHub Actions, codecov
• Packaging: setuptools, pyproject.toml