Skip to main content

Refinery components for the Sayou Data Platform

Project description

sayou-refinery

Build Status License: Apache 2.0 Docs

sayou-refinery is the central data transformation and cleansing library for the Sayou Data Platform. It acts as the "smelter" in the data pipeline, taking raw extracted data and turning it into clean, usable content for downstream tasks like chunking, embedding, and RAG.

Philosophy: Transformation, Not Extraction

sayou-refinery does not extract data from files; that is the job of sayou-document or sayou-connector.

Instead, sayou-refinery's sole responsibility is transformation. It cleans, interprets, filters, and reformats data structures, making them intelligent and optimized for LLMs.

🚀 Key Features

sayou-refinery has a dual role:

  1. Document Refining: It "interprets" the rich, high-fidelity JSON output from sayou-document and transforms it into LLM-friendly formats like Markdown (ContentBlock objects).
  2. DataAtom Refining: It cleans and processes streams of DataAtom objects (from sayou-connector or sayou-wrapper) to reduce noise and enhance insights for RAG.

Core Components

  • Doc Refiners (doc/): Specialized tools for transforming sayou-document output.
    • DocToMarkdownRefiner: The (Tier 2) engine that converts a document JSON into a list of ContentBlock objects (Markdown, Images), interpreting raw_attributes to create semantic structure (like headings and lists).
  • Atom Processors (processor/): (1:1) Cleans or transforms single DataAtoms.
    • e.g., Deduplicator (removes duplicates), TextCleaner (strips HTML).
  • Atom Aggregators (aggregator/): (N:M) Summarizes or combines multiple DataAtoms into new ones.
    • e.g., AverageAggregator (calculates averages from time-series data).
  • Atom Mergers (merger/): (N+E:N) Enriches DataAtoms with external data.
    • e.g., KeyBasedMerger (joins atoms with a CSV or database lookup).

📦 Installation

pip install sayou-refinery

⚡ Quickstart

sayou-refinery provides different tools for different data types.

1. Refining a Document (from sayou-document)

This example shows how sayou-rag uses refinery to process a document.

import json
from sayou.refinery.processor.doc_to_markdown import DocToMarkdownRefiner

# 1. Load the JSON output from sayou-document
# (This assumes doc_data is a dict from doc.model_dump())
with open("my_document_output.json", "r", encoding="utf-8") as f:
    doc_data = json.load(f)

# 2. Initialize the Tier 2 refiner (default engine)
refiner = DocToMarkdownRefiner()
refiner.initialize()

# 3. Refine the dict into ContentBlocks (MD, image data, etc.)
content_blocks = refiner.refine(doc_data)

# 4. (Application Logic) Assemble and save the Markdown
final_markdown = []
for block in content_blocks:
    if block.type == "md":
        final_markdown.append(block.content)
    # (Add logic here to save images (block.type == "image_base64") and link them)

output = "\n\n".join(final_markdown)
# print(output)

2. Refining DataAtoms

This example shows how to clean a list of DataAtoms.

from sayou.core.atom import DataAtom
from sayou.refinery.core.context import RefineryContext
from sayou.refinery.processor.deduplicator import Deduplicator

# 1. Prepare DataAtoms (e.g., from sayou-connector)
atoms = [
    DataAtom("source_A", "item", {"id": "123", "data": "A"}),
    DataAtom("source_B", "item", {"id": "456", "data": "B"}),
    DataAtom("source_C", "item", {"id": "123", "data": "C_dupe"})
]
context = RefineryContext(atoms=atoms)

# 2. Initialize the Tier 2 processor
# We want to deduplicate based on the 'id' field in the payload
deduper = Deduplicator()
deduper.initialize(key_field="payload.id")

# 3. Process the context
refined_context = deduper.process(context)

# refined_context.atoms will now only contain the first two atoms
# print(len(refined_context.atoms)) # Output: 2

🗺️ Roadmap

  • Implementing more Tier 2 Aggregator templates (e.g., SumAggregator, TimeSeriesResampler).
  • Developing Tier 3 plugins for advanced HTML-to-Markdown conversion.

🤝 Contributing

We welcome contributions! If you are interested in building new refiner plugins, please check our contributing guidelines (TODO) and open an issue.

📜 License

This project is licensed under the Apache 2.0 License.

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

sayou_refinery-0.1.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

sayou_refinery-0.1.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file sayou_refinery-0.1.0.tar.gz.

File metadata

  • Download URL: sayou_refinery-0.1.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sayou_refinery-0.1.0.tar.gz
Algorithm Hash digest
SHA256 215f76e3f4044a29a3f1c51893bacb48fe422ddbff79f1ad42f23c55071ce78c
MD5 c1836b3ce1284516ee6402a626ca92d5
BLAKE2b-256 994192890f649161dd63e96fe1bbc3f7be23092615fedf2dd8b559495389487c

See more details on using hashes here.

File details

Details for the file sayou_refinery-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for sayou_refinery-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52a0eadd262f15f7fe38a530bfb55eb3ec49831b0710966be0a0ee10b2fa9dc0
MD5 e4b5cc7f4dc363b3156c053110bffe44
BLAKE2b-256 e9e62b5f9cf17a635d0dcceb6dbb916a5c0f87f3d1c99e4d905a76dabfc45b07

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