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.4.0

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

Source distribution (sdist)

Source distribution for cite-right 0.4.0
File Size Uploaded Provenance Actions
cite_right-0.4.0.tar.gz 83.6 kB Without provenance Details for cite_right-0.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for cite-right 0.4.0
File Actions
cite_right-0.4.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for cite_right-0.4.0-cp311-abi3-win_amd64.whl
cite_right-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for cite_right-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for cite_right-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
cite_right-0.4.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for cite_right-0.4.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 2.5 MB

Release files / cite_right-0.4.0.tar.gz

Download URL cite_right-0.4.0.tar.gz
Size 83.6 kB
Tags Source
SHA-256 checksum
How to use checksums
aba7de5d986ba17fdd397dc3282f2f282dbbac69e35bbf0f40eda38b8720266f
BLAKE2b-256 checksum
How to use checksums
b33af2880f7be43f5a85d218014e765a85abd288701947436c933a8104f57981
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.4.0-cp311-abi3-win_amd64.whl

Download URL cite_right-0.4.0-cp311-abi3-win_amd64.whl
Size 485.2 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
90e940cafcef977dc9e98ff54923dbc19ebbe345887e5251f255d554ec18c92d
BLAKE2b-256 checksum
How to use checksums
0fe9b8545c93a6e50c3da030d8a80a165ae10c76eb3ca0f62d625acb2004bbe1
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.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 668.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
feb97efe901e35a822b3f3eb5999fd7b3ed957cdf70338648c8f39a2921e8534
BLAKE2b-256 checksum
How to use checksums
c87db44f7a87254617c658e32668cb4c0ef246d786b337dbe1a38d411233d7f2
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.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL cite_right-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 658.2 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
1bc08a235c71b3a10d26c0a33923e2b4704cf4e695675ee2a46e15cb932f96fc
BLAKE2b-256 checksum
How to use checksums
4d41bb588346cba64e2b70fb52765d4db0fac7fc0b5124e6f8980aec91248af0
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.4.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL cite_right-0.4.0-cp311-abi3-macosx_11_0_arm64.whl
Size 599.2 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
27a7b04a9d76c50abd5e1c9ad5ae0f81c76a59f8d7db1019c4421521333430de
BLAKE2b-256 checksum
How to use checksums
be5cd11c4c366dadbbe02bb7888de0b1fec5549054d9db3d1e720082919094f4
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.4.0

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