Skip to main content

A linter for your RAG knowledge base

Project description

corpuslint

PyPI version Python versions License: MIT

A linter for your RAG knowledge base. RAGAS & co. evaluate the answer. corpuslint evaluates the data that feeds it — before it reaches your users.

Why

Most bad RAG answers are a corpus problem, not a model problem: duplicates, near-duplicates, low-information chunks, size anomalies, embedding outliers, and contradictions. corpuslint scores your corpus and shows you exactly what to fix.

Install

pip install corpuslint            # core, runs offline and free
pip install "corpuslint[local]"   # + local embeddings (near-dupes, outliers)
pip install "corpuslint[llm]"     # + LLM contradiction check (OpenAI / Azure OpenAI)
pip install "corpuslint[azure]"   # + Azure AI Search source connector
pip install "corpuslint[mcp]"     # + MCP server (lint a corpus from an AI agent)

Use

corpuslint ./docs                       # terminal report
corpuslint ./docs --html report.html    # shareable HTML
corpuslint ./docs --fail-under 70       # CI gate (exit 1 if score < 70)
corpuslint ./chunks.jsonl               # pre-chunked input

# LLM contradiction check (needs the [llm] extra + an API key):
export OPENAI_API_KEY=sk-...
corpuslint ./docs --llm                             # OpenAI, default gpt-4o-mini
corpuslint ./docs --llm --llm-model gpt-4o          # pick a model
corpuslint ./docs --llm --llm-max-pairs 50          # cap paid calls (default 200)

# Azure OpenAI — reads AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT and
# AZURE_OPENAI_API_VERSION (default 2024-10-21) from the environment.
# --llm-model is the Azure *deployment* name.
export AZURE_OPENAI_API_KEY=...  AZURE_OPENAI_ENDPOINT=https://<res>.openai.azure.com
corpuslint ./docs --llm --llm-provider azure --llm-model my-deployment

The contradiction check is O(n²): it prefilters candidate pairs by embedding similarity, then asks the LLM about each. --llm-max-pairs bounds how many pairs reach the LLM (highest-similarity first) so cost stays predictable; skipped pairs are reported (--llm-max-pairs 0 skips the LLM entirely).

Sources

By default corpuslint reads files and directories. It can also pull the corpus straight from a vector store and run the same checks on it.

Azure AI Search

Needs the [azure] extra. Reads the endpoint and admin/query key from the environment; the index is passed with --index:

pip install "corpuslint[azure]"
export AZURE_SEARCH_ENDPOINT=https://<service>.search.windows.net
export AZURE_SEARCH_API_KEY=<key>

corpuslint --source azure-search --index my-index
corpuslint --source azure-search --index my-index --content-field body --id-field key

It pages through every document in the index (no silent cap), maps each to a document whose source is azure-search://<index>/<id>, and feeds them through the normal chunking + check pipeline. --content-field (default content) selects the field holding the text; --id-field (default id) selects the id field. Documents missing the content field are skipped with a warning.

MCP server

Needs the [mcp] extra. corpuslint-mcp runs a stdio Model Context Protocol server so an AI agent (Claude Desktop, etc.) can lint a corpus and get back the Quality Score plus findings.

pip install "corpuslint[mcp]"
corpuslint-mcp        # stdio server; usually launched by the MCP client, not by hand

It exposes one tool, lint_corpus(path, embedder="local", fail_under=None), which returns a structured dict: score, total_chunks, counts_by_check, top_offenders, and findings. With embedder="local" but the [local] extra missing, it falls back to embedder="none" (semantic checks skipped) and adds a warning instead of failing.

Claude Desktop config (claude_desktop_config.json):

{
  "mcpServers": {
    "corpuslint": {
      "command": "corpuslint-mcp"
    }
  }
}

Checks

exact duplicates · near duplicates · low-information chunks · chunk-size anomalies · embedding outliers · contradictions (opt-in).

Config

Optional .corpuslint.yml overrides thresholds and check selection.

Architecture

Library-first: corpuslint.analyze(paths, config) -> Report. The CLI is a thin wrapper; the same API backs the CLI, the MCP server, and the Azure AI Search connector. Eval-set generation and drift monitoring are on the roadmap.

MIT licensed.

Project details


Download files

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

Source Distribution

corpuslint-0.3.0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

corpuslint-0.3.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file corpuslint-0.3.0.tar.gz.

File metadata

  • Download URL: corpuslint-0.3.0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for corpuslint-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6c3aad027ec30d475366145ce3305b7dc83cdca035425bb7b19211b3f062bca2
MD5 83825fb4d2f330ce458712eb4d5a7781
BLAKE2b-256 a2329b8c58f1d96b03f95db2ccf7f441b2a05d125be6658d5230bce4aa71a714

See more details on using hashes here.

Provenance

The following attestation bundles were made for corpuslint-0.3.0.tar.gz:

Publisher: release.yml on mediapuls/corpuslint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file corpuslint-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: corpuslint-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for corpuslint-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49fa8f35abbc0b230bf75a5ede16bd11c46e5115d73896573626a0567fc849eb
MD5 4a98beab75cbdbc8d7304459ce7150bd
BLAKE2b-256 a6625eb9a079eda0a8a4962b0eb54803001114776b52dd0a6b9b33c2a07eae80

See more details on using hashes here.

Provenance

The following attestation bundles were made for corpuslint-0.3.0-py3-none-any.whl:

Publisher: release.yml on mediapuls/corpuslint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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