production-rag-assistant
AGENTS.md65 starsChanged 50 days agoMITView on GitHub
make eval runs both gates that run on this account: These are local-only on purpose (issue #110). Both need paid API keys, and Voyage's 3 RPM trial cap means the retrieval gate spends ~13 minutes in pacing. CI runs lint and test only. Individually: Both must exit 0. The committed verify_results.json and retrieval_results.json are the baselines — refresh and commit them with the change. Gates: citation_precision 1.0 · citation_recall 0.75 · abstention_accuracy 1.0 · doc_hit@k · ground_truth_coverage@5. python3 eval/eval_runner.py is…
- Reads credentials
- Installs packages
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
22 rules. About 1 is common, 15 are distinctive, and 6 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 115
No coverage gate on PRs — keep ≥70% locally with the command above before pushing.
- Very specific: line 140
Never commit: .env, data/ outputs, venv/, keys/tokens.
- Very specific: line 145
Run ruff check src tests eval alembic + pytest -m "not slow" --cov-fail-under=70 + cd frontend && npm run build && npm run lint green …
- Distinctive: line 151
Keep diffs under ~400 lines.
- Common: line 152
No PR before local code review: Read your own git diff main...HEAD line by line — kill debug prints, dead code, secrets, stray files.
- Distinctive: line 157
Scalability: keep code and architecture modular and scalable.
- Distinctive: line 161
Simple over complex: if a solution needs more than one abstraction layer, you're overcomplicating it.
- Distinctive: line 167
Never swallow exceptions: every caught error must be logged or re-raised.
- Distinctive: line 169
Graceful degradation: if a non-critical dependency (Langfuse) is down, log and continue — never block core queries.
- Very specific: line 183
Test naming: some test_*.py, some *_test.py.
- Distinctive: line 188
Don't swap the stack (Groq / LangChain / Chroma / Voyage / FastAPI / React) without updating PLAN.md Locked decisions first.
- Distinctive: line 189
Don't hardcode workspace-specific logic (legal vs academic) into the pipeline — workspace profiles live in prompt config.
- Very specific: line 190
Don't run irreversible actions (force-push, git push --delete, wiping data/, resetting ChromaDB, pushing to main) without explicit …
- Distinctive: line 191
Don't polish the Streamlit UI before the underlying service/pipeline is proven by tests — service layer first.
- Very specific: line 192
Don't hardcode API keys or endpoints — env vars via src/config.py only.
- Distinctive: line 193
Don't keep long-lived feature branches — rebase on main frequently.
- Distinctive: line 194
Don't leave TODO comments without a linked PLAN.md ticket.
- Distinctive: line 195
Don't write clever one-liners that sacrifice readability.
- Distinctive: line 196
Don't over-engineer — start simple, iterate when constraints demand it.
- Distinctive: line 197
Don't write tests just to "make it pass" — write tests to verify correctness (edge cases, error paths, failure modes).
- Distinctive: line 198
Never loosen test assertions to pass: If a test fails, fix the code — not the test.
- Very specific: line 200
Never make cosmetic changes to pass time: No import reordering, no refactoring working code, no try/except → contextlib.suppress swaps …
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Build & Test Entrypoints
# Run API (FastAPI)
uvicorn src.api.app:app --host 0.0.0.0 --port 8001
# Run React frontend (Vite dev server)
cd frontend && npm run dev
# Lint (same as CI)
ruff check src tests eval alembic
cd frontend && npm run lint
# Local test gate (CI runs the same tests WITHOUT the coverage gate)
pytest tests/ -v -m "not slow" --cov=src --cov-report=term-missing --cov-fail-under=70
# Run all tests (including slow embedder tests, no coverage gate)
pytest tests/ -v
# Run evaluation (requires GROQ_API_KEY + Voyage API + pre-ingested docs)
python3 eval/eval_runner.py
# Frontend build
cd frontend && npm run buildQuality gates (local-only, by decision)
make eval runs both gates that run on this account:
make eval # both: verify_eval.py + retrieval_precision.py
make eval-fast # citation gates only — skips the ~13 min retrieval runThese are local-only on purpose (issue #110). Both need paid API keys, and Voyage's 3 RPM trial cap means the retrieval gate spends ~13 minutes in pacing. CI runs lint and test only.
Individually:
python3 eval/verify_eval.py # citation gates → verify_results.json
python3 eval/retrieval_precision.py # retrieval gate → retrieval_results.jsonBoth must exit 0. The committed verify_results.json and retrieval_results.json are the baselines — refresh and commit them with the change.
Gates: citation_precision 1.0 · citation_recall 0.75 · abstention_accuracy 1.0 · doc_hit@k · ground_truth_coverage@5.
Ragas: kept, not retired
python3 eval/eval_runner.py is maintained and works — it is simply not runnable on free-tier accounts. Two hard limits, established by measurement:
- Groq TPD is 200,000 tokens/day. A full run (~92 metric evaluations, several LLM calls each) exceeds it and dies with
429 Rate limit reached ... on tokens per day. - Voyage is 3 RPM / 10K TPM without a payment method. Ragas'
context_precisionissues an LLM call per candidate context, so most samples exceed the deadline. Ragas logsTimeoutError, returnsNaN, and everycontext_precisionsample scores nothing.
So results.json is currently a stale baseline — 5 samples from a 29-item dataset, last written before the dataset was expanded. Do not treat its numbers as current, and do not gate on it until it has been re-run.
eval_runner.py degrades rather than crashing: unmeasurable metrics are logged, omitted, then counted as FAIL against their gate so the run still exits non-zero. The deadline is configurable via RAGAS_TIMEOUT_S (default 900, against Ragas' 180 default).
To make it runnable: add a payment method to both providers. Voyage goes to 2000 RPM / 16M TPM (set VOYAGE_EMBED_PACE_S=0 afterwards — it becomes a needless 21s tax per query), and Groq's daily budget rises. Anyone with funded keys can reproduce the full metric set; the runner needs no changes.
Until then, verify_eval.py and retrieval_precision.py are the only trustworthy measurements available on this account. make ragas runs it for anyone with funded keys.
eval_runner.py degrades rather than crashing: unmeasurable metrics are logged, omitted, then counted as FAIL against their gate so the run still exits non-zero. The deadline is configurable via RAGAS_TIMEOUT_S (default 900, against Ragas' 180 default).
System Architecture
Two-tier: FastAPI backend + React SPA frontend. No monorepo.
src/
config.py # Centralized config, reads .env, validates at startup
ingestion/ # PDF → chunks → embeddings (Voyage) → ChromaDB
retrieval/ # BM25 + vector search → RRF fusion → cross-encoder rerank (Voyage)
generation/ # Citation prompt builder + Groq LLM call + Pydantic validation
services/ # RAGService facade + BM25 cache (pages call this)
db/ # ChromaDB client (LangChain Chroma wrapper)
monitoring/ # Langfuse tracing (optional, fails silently if unconfigured)
api/ # FastAPI routes: auth, documents, chat, answers, usage, billing
frontend/ # React 19 + TS + Vite 6 SPA
src/
pages/ # Landing, Chat, Documents, Dashboard, Settings, Billing, Auth
components/ # Reusable UI (Toast, TraceModal, WorkspaceSwitch, etc.)
api/client.ts # Typed fetch (Bearer, 401→login, 429 detail, 60s timeout)
auth/AuthContext.tsx # JWT storage, Google/guest/demo login, fragment token
public/ # favicon, static assets
eval/ # verify_eval (citation gates) + retrieval_precision (top-k) + eval_runner (Ragas)
tests/ # Pytest suite (backend)Runtime Invariants
- Python 3.12 required.
asyncio_mode = autoin pytest.ini. - GROQ_API_KEY + VOYAGE_API_KEY + JWT_SECRET required. App crashes at startup without them.
- Qdrant Cloud stores vectors in the managed cluster.
QDRANT_URLandQDRANT_API_KEYare required for retrieval. - BM25 index rebuilt in-memory from ChromaDB chunks on each API start or PDF upload. Not persisted separately.
- Cross-encoder reranker (
voyage-rerank-3-lite) runs via Voyage API. Accounts for major query latency. - Citation validation is Pydantic-enforced: every answer must contain
[SOURCE N]patterns or it raisesValidationError. - Langfuse optional. Traces skipped silently when keys absent.
- Eval datasets at
data/eval_dataset.json(29 items, Ragas) anddata/verify_eval.json(8 adversarial cases, citation gates). They mark abstention differently —class: abstainvsexpect: abstain— so readers must check both. - Frontend dev runs on
:5173, proxies API to:8001via Vite config. - CORS: single origin
Config.FRONTEND_URL(defaulthttp://localhost:5173), no cookies.
Continuous Integration Contract
GitHub Actions (.github/workflows/ci.yml) runs on PRs targeting main
and on every push to main:
- lint —
pip install ruff==0.15.10→ruff check src tests eval alembic+cd frontend && npm run lint - test —
pip install -r requirements.txt→pytest tests/ -v -m "not slow" --cov-fail-under=0+cd frontend && npm run build
CI runs fast tests only (slow embedder tests marked @pytest.mark.slow skipped).
No coverage gate on PRs — keep ≥70% locally with the command above before pushing.
The post-merge push run is not redundant with the PR run: the PR run covers the head branch, and a merge can land something it did not cover. On 2026-10-10 three PRs merged red on a pre-existing dependency failure that #131 then fixed — and nothing re-checked them, because no post-merge run existed. Keep the trigger.
Branch protection on main (live as of 2026-10-10)
- Required status checks:
lintandtest,strict: true(branch must be up to date withmainbefore merging). - Enforced on admins. No force-push, no branch deletion.
- No required approving review. This repo has exactly one collaborator with
push access, so requiring one review would deadlock every merge. If a second
maintainer is added, raise
required_approving_review_countthen.
Because enforce_admins is on, a red check blocks your own merge — that is the
point, but it means a stale failure cannot be merged past "just this once".
Version-Control Hygiene & Branch Discipline
- Never push directly to
main— branch protection enforces this (required checkslint+test,enforce_adminson). Every change goes through a PR branch. - Branch names:
type/short-slug—feat/,fix/,chore/,ci/,docs/,refactor/,test/,security/. - Commits: Conventional Commits —
type: subject, lowercase imperative, ≤50 chars. - One concern per branch. No mixed refactor + feature work.
- Never commit:
.env,data/outputs,venv/, keys/tokens. - Pre-push secret scan must be empty:
git log -p | grep -iE "sk-[a-zA-Z0-9]{20,}|pk_live_[a-zA-Z0-9]{10,}|ghp_[a-zA-Z0-9]{20,}|gsk_[a-zA-Z0-9]{20,}|AKIA[0-9A-Z]{16}" - Resolve conflicts inside the feature branch. No
merge:conflict-fix commits on main. - Branch policy: delete merged feature/fix/chore/docs branches after squash-merge; keep long-lived branches (
main,develop,release/*,gh-pages) and any unmerged branch. - Run
ruff check src tests eval alembic+pytest -m "not slow" --cov-fail-under=70+cd frontend && npm run build && npm run lintgreen locally before push (keep coverage ≥70%).
Change Review Protocol (PR Contract)
- PR title = Conventional Commit (becomes the squash subject on main).
- Body sections: What/Why · Changes (bullets) · Test plan (commands + results) · Screenshots if UI · Risk/rollback if breaking.
- Keep diffs under ~400 lines; split larger work.
- No PR before local code review. Read your own
git diff main...HEADline by line — kill debug prints, dead code, secrets, stray files. - Draft PR = WIP; mark ready before requesting review.
Software Quality Attributes
- Scalability: keep code and architecture modular and scalable.
- Modular architecture: each component is a separate unit with a clear interface.
- Clean, readable code: prioritize clarity over cleverness — code is read more than written.
- Production-focused: handle errors, log meaningfully, fail loudly; every line should be production-ready.
- Simple over complex: if a solution needs more than one abstraction layer, you're overcomplicating it.
Logging & Error-Handling Contract
- Structured logging:
loguruwith context fields — no rawprintstatements. - Log levels:
ERROR(needs attention),WARNING(degraded state),INFO(business events),DEBUG(dev detail). - Never swallow exceptions: every caught error must be logged or re-raised. Silent failures are bugs.
- Fail fast on startup: crash immediately when required env vars are missing (
Config.validate()). - Graceful degradation: if a non-critical dependency (Langfuse) is down, log and continue — never block core queries.
- Error responses: return structured error objects to callers — never stack traces or raw exceptions.
- Retry with backoff: exponential backoff for external API calls (Groq failover chain, Voyage 429 pacing). Don't hammer a failing service.
Container Orchestration
docker-compose.yml runs the FastAPI API against Qdrant Cloud. Secrets come from .env; free-tier disk is ephemeral.
Operational Pitfalls
src/ingestion/embedder.pycalls Voyage API (voyage-4-litedim 1024). Trial: 3 RPM / 10K TPM — client-side pacing implemented.src/retrieval/reranker.pycalls Voyagererank-3-lite. Same trial limits.- Frontend: Vite dev server on
:5173,VITE_API_URLdefaults tohttp://localhost:8001. load_all_chunks()reads every document from ChromaDB — expensive at scale.- Test naming: some
test_*.py, some*_test.py. Onlytest_*pattern auto-discovered by pytest. docs/CHAT_FIX_PLAN.mduntracked — do not commit.
Engineering Guardrails (Prohibited Patterns)
- Don't swap the stack (Groq / LangChain / Chroma / Voyage / FastAPI / React) without updating PLAN.md Locked decisions first.
- Don't hardcode workspace-specific logic (legal vs academic) into the pipeline — workspace profiles live in prompt config; the engine stays shared.
- Don't run irreversible actions (force-push,
git push --delete, wipingdata/, resetting ChromaDB, pushing tomain) without explicit confirmation. - Don't polish the Streamlit UI before the underlying service/pipeline is proven by tests — service layer first.
- Don't hardcode API keys or endpoints — env vars via
src/config.pyonly. - Don't keep long-lived feature branches — rebase on
mainfrequently. - Don't leave TODO comments without a linked PLAN.md ticket.
- Don't write clever one-liners that sacrifice readability.
- Don't over-engineer — start simple, iterate when constraints demand it.
- Don't write tests just to "make it pass" — write tests to verify correctness (edge cases, error paths, failure modes).
- Never loosen test assertions to pass. If a test fails, fix the code — not the test.
- Never edit
.env/.env.*without explanation first. Before touching one you MUST tell the user: (1) which variable, (2) current value, (3) new value, (4) why. Wait for explicit approval. - Never make cosmetic changes to pass time. No import reordering, no refactoring working code, no
try/except→contextlib.suppressswaps unless asked. src/stays framework-free (no FastAPI/Streamlit imports belowsrc/api).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

