Metadata-Version: 2.4
Name: coreason_synthesis
Version: 0.2.0
Summary: A new Python project.
License: # The Prosperity Public License 3.0.0
         
         Contributor: CoReason, Inc.
         
         Source Code: https://github.com/CoReason-AI/coreason_synthesis
         
         ## Purpose
         
         This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
         
         ## Agreement
         
         In order to receive this license, you have to agree to its rules.  Those rules are both obligations under that agreement and conditions to your license.  Don't do anything with this software that triggers a rule you can't or won't follow.
         
         ## Notices
         
         Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
         
         ## Commercial Trial
         
         Limit your use of this software for commercial purposes to a thirty-day trial period.  If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
         
         ## Contributions Back
         
         Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
         
         ## Personal Uses
         
         Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
         
         ## Noncommercial Organizations
         
         Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
         
         ## Defense
         
         Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
         
         ## Copyright
         
         The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
         
         ## Patent
         
         The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
         
         ## Reliability
         
         The contributor can't revoke this license.
         
         ## Excuse
         
         You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
         
         ## No Liability
         
         ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
License-File: LICENSE
License-File: NOTICE
Author: Gowtham A Rao
Author-email: gowtham.rao@coreason.ai
Requires-Python: >=3.11
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Dist: aiofiles (>=25.1.0,<26.0.0)
Requires-Dist: anyio (>=4.12.1,<5.0.0)
Requires-Dist: coreason-identity
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Requires-Dist: loguru (>=0.7.2,<0.8.0)
Requires-Dist: numpy (>=2.4.1,<3.0.0)
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
Requires-Dist: requests (>=2.32.5,<3.0.0)
Project-URL: Documentation, https://github.com/CoReason-AI/coreason_synthesis
Project-URL: Homepage, https://github.com/CoReason-AI/coreason_synthesis
Project-URL: Repository, https://github.com/CoReason-AI/coreason_synthesis
Description-Content-Type: text/markdown

# coreason-synthesis

Grounded Synthetic Data Generation (SDG) for the CoReason-AI platform.

[![License](https://img.shields.io/badge/license-Prosperity%203.0-blue)](https://prosperitylicense.com/versions/3.0.0)
[![Build Status](https://github.com/CoReason-AI/coreason_synthesis/actions/workflows/main.yml/badge.svg)](https://github.com/CoReason-AI/coreason_synthesis/actions)
[![Code Style: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Documentation](https://img.shields.io/badge/docs-Product%20Requirements-blue)](docs/product_requirements.md)

## Overview

**coreason-synthesis** is the "Amplifier" of the CoReason platform. It solves the "Cold Start Problem" of evaluation by manufacturing high-quality, domain-specific Benchmark Evaluation Corpora (BEC) from a small set of user-provided examples.

Unlike standard GenAI approaches that rely on hallucination, this library implements a **Grounded Synthesis Pipeline**:

1.  **Learns** the testing pattern from user-provided Seeds.
2.  **Forages** for real, semantically similar documents via MCP.
3.  **Extracts** verbatim text slices (The "Real Data").
4.  **Composites** synthetic questions around that data (The "Fake Scenario").
5.  **Appraises** and ranks the results by complexity and diversity.

The output is a rigorous, stratified test suite that validates the agent against *actual* enterprise data variances, not idealized synthetic text.

## Features

*   **Pattern-Forage-Fabricate-Rank Loop**: A complete pipeline for generating high-quality test data.
*   **Few-Shot Intent Inference**: Infers testing intent from a few examples.
*   **Verbatim Defense**: Uses pixel-perfect copies of real data (preserving errors/formatting) as context.
*   **Lineage Transparency**: Distinguishes between "Verbatim/Real" and "Adversarial/Perturbed" data.
*   **Quality Ranking**: Appraises and ranks cases by complexity, ambiguity, diversity, and validity.
*   **Safety & Privacy**: Includes PII Sanitization filters.

For detailed requirements and specifications, see [docs/product_requirements.md](docs/product_requirements.md).

## Installation

```bash
pip install coreason-synthesis
```

## Usage

Here is a concise example of how to initialize and use the library (using built-in mocks for demonstration):

```python
import uuid
from coreason_synthesis.pipeline import SynthesisPipeline
from coreason_synthesis.analyzer import PatternAnalyzerImpl
from coreason_synthesis.forager import ForagerImpl
from coreason_synthesis.extractor import ExtractorImpl
from coreason_synthesis.compositor import CompositorImpl
from coreason_synthesis.perturbator import PerturbatorImpl
from coreason_synthesis.appraiser import AppraiserImpl
from coreason_synthesis.models import SeedCase, Document

# Import mocks for demonstration (replace with real implementations in prod)
from coreason_synthesis.mocks.teacher import MockTeacher
from coreason_synthesis.mocks.embedding import DummyEmbeddingService
from coreason_synthesis.mocks.mcp import MockMCPClient

# 1. Initialize Dependencies
teacher = MockTeacher()
embedder = DummyEmbeddingService()
mcp_client = MockMCPClient(
    documents=[
        Document(
            content="Standard Dose: 50mg. Included: Adults.",
            source_urn="doc:1"
        )
    ]
)

# 2. Initialize Components
analyzer = PatternAnalyzerImpl(teacher, embedder)
forager = ForagerImpl(mcp_client, embedder)
extractor = ExtractorImpl()
compositor = CompositorImpl(teacher)
perturbator = PerturbatorImpl()
appraiser = AppraiserImpl(teacher, embedder)

# 3. Assemble Pipeline
pipeline = SynthesisPipeline(
    analyzer=analyzer,
    forager=forager,
    extractor=extractor,
    compositor=compositor,
    perturbator=perturbator,
    appraiser=appraiser
)

# 4. Define Seeds
seeds = [
    SeedCase(
        id=uuid.uuid4(),
        question="Calculate BSA for 180cm, 80kg patient",
        expected_output={"bsa": 2.0},
        context="Formula: sqrt((height*weight)/3600)"
    )
]

# 5. Run Synthesis
config = {
    "target_count": 5,
    "perturbation_rate": 0.5,
    "sort_by": "complexity_desc"
}
user_context = {"user_id": "demo-user"}

results = pipeline.run(seeds, config, user_context)

# 6. Use Results
for case in results:
    print(f"Generated Case ({case.provenance}): {case.synthetic_question}")
```

