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

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.2.0
File Actions
cite_right-0.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for cite_right-0.2.0-cp313-cp313-win_amd64.whl
cite_right-0.2.0-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.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.2.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for cite_right-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
cite_right-0.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for cite_right-0.2.0-cp312-cp312-win_amd64.whl
cite_right-0.2.0-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.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.2.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for cite_right-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
cite_right-0.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for cite_right-0.2.0-cp311-cp311-win_amd64.whl
cite_right-0.2.0-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.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cite_right-0.2.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for cite_right-0.2.0-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 3.0 MB

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

Download URL cite_right-0.2.0-cp313-cp313-win_amd64.whl
Size 243.5 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
3e9970649176e8203369816777d43973c4a53e20557ebdb2f11833253b818ebd
BLAKE2b-256 checksum
How to use checksums
a896ae98aaa82a3c1f09370bd147d8ce76e11bf056a0271bf46873544ec02830
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.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 406.8 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
60bc294267553061a4d176852838ce3f12897297352ac2f1e4760aeb797c1dc0
BLAKE2b-256 checksum
How to use checksums
b63262e2e9d3c645d533cc6e8444e45399cda16019aec0d3b1355d4c90e2dc04
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.2.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL cite_right-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Size 357.9 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2fb11edfdedd3d61e154c48a1a54f7992b1bda09f5f4b180f0a92517d2517122
BLAKE2b-256 checksum
How to use checksums
c1be57974281dbe409952634b2aa1b5cc77809a5ba5c867c4cdeb6a377db16e1
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.2.0-cp312-cp312-win_amd64.whl

Download URL cite_right-0.2.0-cp312-cp312-win_amd64.whl
Size 243.5 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
20beb340eafd2a5fca8e76c207977a49cd4f1756d9de0b233fc8fa1ae9890852
BLAKE2b-256 checksum
How to use checksums
9264add87c2c8ce0fb6c2b822bc5c51f4a8564860eb88b0719dea23927b19d3e
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.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 406.6 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8b089ef22dad0b35c07aadfc3f07010db15689d0fc7614d77c862399a36b24f7
BLAKE2b-256 checksum
How to use checksums
424426a291cdde36ec5782d83fbd81dda469c51354c0f75b0488ccfd93b2f286
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.2.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL cite_right-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Size 357.9 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f99a7ed1aa4fc3682675071dbfaea21e3cf960df95938bbb8dcad73f6fe8fbce
BLAKE2b-256 checksum
How to use checksums
ae76ffd0c2e4c20284826ef7aae054d19ed2560c5d5923c2ea00dc8f736c7554
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.2.0-cp311-cp311-win_amd64.whl

Download URL cite_right-0.2.0-cp311-cp311-win_amd64.whl
Size 245.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
4512396ff56c46084c6097d65c2e2688498d3545f10b13654101c91d79de7ef5
BLAKE2b-256 checksum
How to use checksums
52af3a1fb2a413614e317e70e9bcb7af2065e8905a8a12caa54ed7d47d4556c3
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.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cite_right-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 408.9 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9d230ba3de7ca4b38b2c1d31c6579b70476c61ac5dd990951607944342d27bad
BLAKE2b-256 checksum
How to use checksums
5b8c75cc00d9891205820d54b83d4a0d0c21f2bc6a6bbd692dacec3c29a0ce40
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.2.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL cite_right-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Size 359.3 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
30de475946b705c8a89c4c14d9b907f646c2858b6e1d2af5d8fb4b693a642cf1
BLAKE2b-256 checksum
How to use checksums
8d711ab083594038cd089b135ac41c932c731facfe04b5423943a81d7ef2fd89
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.2.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