Skip to main content

Text alignment library for citation extraction using Smith-Waterman.

Project description

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.
  • If you want embeddings to directly mark a span as supported with low lexical overlap, tune supported_embedding_similarity or use allow_embedding_only=True in CitationConfig.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

cite_right-0.1.0-cp313-cp313-win_amd64.whl (215.8 kB view details)

Uploaded CPython 3.13Windows x86-64

cite_right-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (381.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

cite_right-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (336.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cite_right-0.1.0-cp312-cp312-win_amd64.whl (215.7 kB view details)

Uploaded CPython 3.12Windows x86-64

cite_right-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (381.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cite_right-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (336.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cite_right-0.1.0-cp311-cp311-win_amd64.whl (218.0 kB view details)

Uploaded CPython 3.11Windows x86-64

cite_right-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (385.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cite_right-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (339.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file cite_right-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cite_right-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 215.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cite_right-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b27063bf4ed69128e44605c71ef1a97a843425b4378cfc8a9852bd2314251b41
MD5 15ada4724b53af1b0b1b8a65417c7147
BLAKE2b-256 3ee4f98991f5818981738266c415d50ebbfb160b508a9e7eae99d11c4595d307

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cite_right-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6464306331bb152b992e3b1404b850b51a6a649ef021e2087361bfed6e53b3c
MD5 535209efee29fe9a90153add18362ad5
BLAKE2b-256 d514c17d2dbad5b0ac5b3a426d637f6fcadec363f4d24c177bcaf1cf89329a34

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cite_right-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15aae854702464d143e50754404c0bf206727fc8eba0845778ea5912878eb74e
MD5 2d125575fd9283d4772d6b0f31a5a9a9
BLAKE2b-256 8b2df8146a8657a402f28424bf33e3ce3c447c72d0310ae50c80b3f04ed366dd

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: cite_right-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 215.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cite_right-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e25413c6e9cfc7e86ef066faab768d12a8f7b9655576521d6cfca82f0f37f8d9
MD5 da380e8587c6e59f66ec8ae68a40b478
BLAKE2b-256 cb047392442b359daf52e7c675ba904a54d100e1427ac67fa4f36afb6875fbf9

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cite_right-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e254af89dd158cd2fbe4b662d17f2456fede962ea3a05c1a2c14056cb09d871f
MD5 2a29adb5216c2901774e66d31fbd44a6
BLAKE2b-256 649f4de451152a7f564f36b1f8a6c0a9bee0f4783ef1fed5ae14a1cac984c28f

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cite_right-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9cedf298b453149169989085399def1085cc0c63eb085ce9eecbe73074139398
MD5 bb85617ed62dafa3f183d5208f9737ce
BLAKE2b-256 38b73df4073890d4e551acaad91f4d254fdd5520adc51e5af1c1f0dacdf55e59

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: cite_right-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 218.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cite_right-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8787d271407bb52afb88e6d299299858629f043c8e27c82ca5255269ee015140
MD5 a8bff4bc516e5240d1d148e3a96b330e
BLAKE2b-256 87c0057ff8a3c84e331c81053d95969799389b0b0a88f401a296f3c6fbfbccda

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cite_right-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 719447006826d550501d560559f06e4c8b62c1279c50bd55a1e03638d6a7effd
MD5 e5106599373426450c563815e0b4098f
BLAKE2b-256 f693593200c9da7d0b2d8434241f6481aefa138f49fbcc093fff460f0cdde60d

See more details on using hashes here.

File details

Details for the file cite_right-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cite_right-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15289b7aae5441815b20035d0b09f8e311e854972f6fa2c43a2f1b4a005292c1
MD5 06cfcacf32dde702b89b004ac5d13a9f
BLAKE2b-256 8cb345d3f260cd00373d1a84e34e455667a5f6932a14c68a5da039f0f8063b01

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