Skip to main content

Cite-Right

CI Coverage

Character-accurate citations for AI outputs. Cite-Right aligns generated answers to source text and returns exact character offsets for highlighting, extraction, and verification. The Python API is the reference implementation, with an optional Rust extension for speed.

Core features

  • Document-source linking: Map each answer span to the exact source substring.
  • Character-accurate offsets: char_start / char_end are ready for UI highlights.
  • Multi-paragraph support: Works on RAG-style answers with multiple sentences.
  • Grounding metrics: Compute hallucination and groundedness stats.

How it works (high level)

  1. Segment the answer into spans (sentences/clauses).
  2. Find candidate passages in each source and align with Smith-Waterman.
  3. Return citations with absolute character offsets into the original source text.

Docs

Install

Requirements: Python 3.11+ (Rust is only needed when building from source or if no wheel exists for your platform).

pip install cite-right

For the embedding-backed quickstart below, install extras:

pip install "cite-right[embeddings,tiktoken]"

See docs/getting-started/ for optional extras (spaCy, embeddings, HuggingFace, tiktoken) and deeper examples.

Quickstart

from cite_right import SourceDocument, align_citations
from cite_right.core.citation_config import CitationConfig
from cite_right.models.sbert_embedder import SentenceTransformerEmbedder
from cite_right.text.tokenizer_tiktoken import TiktokenTokenizer

question = (
    "What method is introduced to improve sample efficiency, and what gains does it "
    "report over GRPO and MIPROv2?"
)
answer = (
    "GEPA (Genetic-Pareto) is introduced as a reflective prompt optimizer for compound AI systems. "
    "On Qwen3 8B, GEPA outperforms GRPO by up to 19% while requiring up to 35x fewer rollouts. "
    "It surpasses MIPROv2 with aggregate optimization gains of +14%, more than doubling MIPROv2's +7%."
)
sources = [
    SourceDocument(
        id="gepa_intro",
        text=(
            "To operationalize this, we introduce GEPA (Genetic-Pareto), a reflective prompt "
            "optimizer for compound AI systems that merges textual reflection with multi-objective "
            "evolutionary search."
        ),
    ),
    SourceDocument(
        id="grpo_results",
        text=(
            "Our results show that GEPA demonstrates robust generalization and is highly sample efficient: "
            "on Qwen3 8B, GEPA outperforms GRPO (24,000 rollouts with LoRA) by up to 19% while requiring up to "
            "35x fewer rollouts."
        ),
    ),
    SourceDocument(
        id="mipro_results",
        text=(
            "GEPA surpasses the previous state-of-the-art prompt optimizer, MIPROv2, on every benchmark and model, "
            "obtaining aggregate optimization gains of +14%, more than doubling the gains achieved by MIPROv2 (+7%)."
        ),
    ),
]

results = align_citations(
    answer,
    sources,
    config=CitationConfig(top_k=1),
    embedder=SentenceTransformerEmbedder("all-MiniLM-L6-v2"),
    tokenizer=TiktokenTokenizer(),
)
for result in results:
    print(result.answer_span.text, result.status)
    for citation in result.citations:
        source_doc = sources[citation.source_index]
        evidence = source_doc.text[citation.char_start:citation.char_end]
        print(" ", citation.source_id, evidence)

Why embeddings help here:

  • The last sentence paraphrases the source, so token overlap alone can fall below the supported threshold.
  • The embedder pulls semantically similar passages into the candidate set; alignment then confirms the exact span and returns precise offsets.
  • Embeddings improve recall, but only alignment-backed matches become citations. High-similarity passages without localized alignment remain retrieval support, not exact evidence.

High-Precision Configuration

If your application requires extremely high precision (e.g., minimizing or completely eliminating false positive citations on adversarial inputs like negations, numerical updates, or swapped entities), we recommend using the benchmarked optimal high-precision configuration:

from cite_right import CitationConfig, CitationWeights

# Custom weights optimized to balance alignment and semantic embedding similarity
high_precision_weights = CitationWeights(
    alignment=1.0,
    answer_coverage=1.0,
    evidence_coverage=0.0,
    lexical=0.5,
    embedding=0.5
)

# High-precision configuration
high_precision_config = CitationConfig(
    top_k=1,
    min_alignment_score=0,
    min_answer_coverage=0.4,
    supported_answer_coverage=0.6,
    min_embedding_similarity=0.3,
    min_final_score=2.6,  # Threshold designed to filter out adversarial and near-miss false positives
    weights=high_precision_weights
)

This configuration was derived using multi-dimensional grid optimization over a rich adversarial RAG dataset and successfully eliminates false positives while preserving robust recall on aligned citations.

Development

uv sync --frozen
uv run maturin develop
uv run pytest

Optional checks:

uv run ruff check .
uv run ruff format --check .
uv run pyright

License

Apache-2.0 (see LICENSE).

Metadata

Release files for cite-right 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for cite-right 0.3.1
File Actions
cite_right-0.3.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for cite_right-0.3.1-cp313-cp313-win_amd64.whl
cite_right-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for cite_right-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.3.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for cite_right-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
cite_right-0.3.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for cite_right-0.3.1-cp312-cp312-win_amd64.whl
cite_right-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for cite_right-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.3.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for cite_right-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
cite_right-0.3.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for cite_right-0.3.1-cp311-cp311-win_amd64.whl
cite_right-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for cite_right-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.3.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for cite_right-0.3.1-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 4.5 MB

Release files / cite_right-0.3.1-cp313-cp313-win_amd64.whl

Download URL cite_right-0.3.1-cp313-cp313-win_amd64.whl
Size 404.4 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
8929c950444cf33797c18d870f2e197e4e2b7510e8075c2116cfad70087e22ae
BLAKE2b-256 checksum
How to use checksums
06822320f35be5ed17cbebe63c17c043cbcbe919d45123ea19ae24d702c7d36a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 575.2 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a5f2dd4fcacf93afe036229b2c7fdd0e18a96c2b3746dcab0aee190dda7a3d71
BLAKE2b-256 checksum
How to use checksums
851d5b6fc56d42545f3d4a373b0df432311b45f77190f27a9658d60fba3a628f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL cite_right-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Size 515.9 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6ac9f73af74821c8be622be73ca6e244dc97446d954c47754b3dfa1efa32f120
BLAKE2b-256 checksum
How to use checksums
26b814d18cd2935b5fd66c0b0001dc5492b4ccb1913f736e7f48d92a8e831e87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp312-cp312-win_amd64.whl

Download URL cite_right-0.3.1-cp312-cp312-win_amd64.whl
Size 404.5 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
34d3411f535aea141ff263fe764baf483c5f41bdda1c7b61de6264dc4e7893bc
BLAKE2b-256 checksum
How to use checksums
75cb852291f31016c7c09231c0fe70c47af11eaaaaba12ca75563d17d1149381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 575.1 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ffe8e083c3c5e47ed8aad61e4fb8756d016152f8ef8c55658cbe2fd2185c3d26
BLAKE2b-256 checksum
How to use checksums
ea737285b5796e795d398a8f02f5e173c5befc0d5e77b7f0ae3ba3a4eea3ce12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL cite_right-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Size 516.1 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ebdc4dab09b51628a18abf07aa4a93761d419e6c46524d5ebeac67d139ff45f9
BLAKE2b-256 checksum
How to use checksums
74344be2081cc00b15f6fd7c3aa5e0c3e21621366d2a9aa47a9cf1f054e85e55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp311-cp311-win_amd64.whl

Download URL cite_right-0.3.1-cp311-cp311-win_amd64.whl
Size 406.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
f9a25ac89e01c053b2cafa917ee02f6b9bb1ff7d2ae906f759643d4381fe5b51
BLAKE2b-256 checksum
How to use checksums
1e8c927c530a702d9ceeab9f867f16fd2fce3511a51566fe0a9a6c5ca83d5127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 578.6 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
439f8dd9c40a0b515beb398b227b9847d4ecf9eb31a71dc0ec4003f9dcb7a5ac
BLAKE2b-256 checksum
How to use checksums
1d65fd081d9c8a320951066b44704bd9af7f4bf0921dd92351af4620ff8823fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cite_right-0.3.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL cite_right-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Size 519.8 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0d80df2c493ca67e6b64ec6ab9ac1b2c8b25f4c73363694c17a0e6b5902adfa4
BLAKE2b-256 checksum
How to use checksums
c714a64927ab84ada78921105d4d3c216bd24c61e36358679d1ee3ae1b02555d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for cite-right 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page