# Contributing to knowledge-rag Thank you for considering contributing! This project is used daily by 70+ companies and teams. Quality is non-negotiable, but the process should still be welcoming and clear. This guide explains how to propose changes, what we check, and what to expect from review. --- ## Table of contents - [Quick start](#quick-start) - [The 7 Pillars](#the-7-pillars-quality-gate) - [Local development](#local-development) - [Pre-commit hooks](#pre-commit-hooks) - [Running tests](#running-tests) - [Pull request lifecycle](#pull-request-lifecycle) - [Commit message convention](#commit-message-convention) - [Publishing a release](#publishing-a-release) - [Reporting bugs](#reporting-bugs) - [Reporting security issues](#reporting-security-issues) - [Code of Conduct](#code-of-conduct) --- ## Quick start ```bash git clone https://github.com/lyonzin/knowledge-rag.git cd knowledge-rag python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -e . pip install -r requirements-dev.txt # ruff, pytest, mypy, pre-commit pre-commit install # one-time ``` Run the full local check before pushing: ```bash pre-commit run --all-files pytest tests/ -v ``` --- ## The 7 Pillars (Quality Gate) Every PR is automatically evaluated against seven pillars. All must pass before manual review by [@lyonzin](https://github.com/lyonzin). | # | Pillar | What it covers | Tools | |---|---|---|---| | 1 | **Security** | SAST, secrets, dependency CVEs, supply chain | bandit, semgrep, gitleaks, pip-audit, Snyk, CodeQL, Socket | | 2 | **Stability** | Test determinism, coverage trend, flake detection | pytest-rerunfailures, codecov trend gate, test count guard | | 3 | **Memory Leak** | RSS growth under load, leak isolation | pytest-memray, baseline tests, nightly soak (1h continuous) | | 4 | **Versatility** | OS × Python matrix, format matrix, locale matrix, preset matrix | matrix CI on Linux/Windows/macOS × 3.11/3.12/3.13 | | 5 | **Scalability** | Performance regression, concurrent load | bench suite (MRR@5, p50/p95/p99 latency, throughput), perf gate at 10% regression | | 6 | **Versioning** | Atomic version sync, API surface stability, CHANGELOG enforcement | pre-commit hook, griffe, conventional commits, backwards-compat tests | | 7 | **Quality** | Style, types, docstrings, complexity, dead code | ruff, mypy strict, interrogate, radon, vulture | Your PR runs multiple checks across these seven pillars. Fix failing checks before requesting review. If a regression is intentional, explain its impact and discuss it with the maintainer before changing any acceptance threshold. --- ## Local development ### Recommended tooling ```bash # Required python >= 3.11 pip install -e . # Development pip install ruff pytest pytest-cov pytest-rerunfailures pip install mypy interrogate radon vulture pip install pre-commit hypothesis # Linux/macOS only; memray does not support Windows pip install pytest-memray # Optional (only if you touch benchmarks) pip install pytest-benchmark ``` ### Project layout ``` mcp_server/ # Production code tests/ # All tests (unit + property + integration + memory baseline) bench/ # Performance benchmarks (run on PRs + nightly) docs/ # User-facing documentation examples/ # Sample MCP client configs .github/workflows/ # CI definitions ``` --- ## Pre-commit hooks `pre-commit` runs lightweight checks before each commit. Run the hooks locally; CI independently enforces its configured checks and does not run every hook from `.pre-commit-config.yaml`. ```bash pre-commit install # install once pre-commit run --all-files # run on full repo (occasional manual run) ``` Hooks enforced: - `ruff check` and `ruff format --check` - `version-sync` — `pyproject.toml` / `mcp_server/__init__.py` / `npm/package.json` must agree - `gitleaks` — block secrets in commits --- ## Running tests ```bash # Fast: unit + property tests, no model downloads pytest tests/ -v # With coverage pytest tests/ -v --cov=mcp_server --cov-report=term-missing # Memory baseline (slow, requires pytest-memray) pytest tests/test_memory_baseline.py -v --memray # Property-based fuzzing (Hypothesis) pytest tests/test_ingestion_property.py -v --hypothesis-show-statistics # Benchmarks (slow, generates artifacts in bench/results/) pytest bench/ -v --benchmark-only ``` **HuggingFace offline mode is enforced in CI.** If a test triggers a real download it will fail fast. Use ``unittest.mock.patch("mcp_server.server.TextEmbedding")`` and ``patch("mcp_server.server.TextCrossEncoder")``. --- ## Pull request lifecycle 1. **Fork + branch** — `feat/` for features, `fix/-` for bugs, `docs/` for docs, `chore/` for chores. 2. **Open PR early as draft** — visibility helps avoid duplicate work. 3. **Fill the PR template** — every checkbox in the template is enforced. Mark `N/A` and explain if a section truly does not apply. 4. **Pass the 7 Pillars** — green checks across the board. 5. **Wait for review** — [@lyonzin](https://github.com/lyonzin) reviews every PR line by line, even after green CI. Response time target: 48h on weekdays. 6. **Address feedback** — push more commits, do not force-push during review (preserves discussion thread). 7. **Squash merge** — reviewer (or you with permission) squashes with a clean conventional commit message. ### What gets a fast track - Pure docs / typo fixes - New tests for existing behavior - Backwards-compatible bug fixes with regression test ### What needs more discussion - New MCP tools (public API surface) - Changes to embedding model, reranker model, or chunking strategy - Anything touching ChromaDB schema or `index_metadata.json` format - Changes to the 7 Pillars themselves ### What is generally rejected - Style-only refactors with no behavior change (use ruff) - Breaking API changes without strong justification + migration path - New dependencies without explaining why existing options were ruled out - PRs that disable failing tests instead of fixing them --- ## Commit message convention We use [Conventional Commits](https://www.conventionalcommits.org/). Enforced via `commitlint` in CI on PR titles and squash messages. ``` ():