Skip to content

feat: claim confidence scoring, extraction hardening, Claude Code setup - #42

Open
arc-butler wants to merge 15 commits into
masterfrom
feat/claims-platform
Open

feat: claim confidence scoring, extraction hardening, Claude Code setup#42
arc-butler wants to merge 15 commits into
masterfrom
feat/claims-platform

Conversation

@arc-butler

Copy link
Copy Markdown
Collaborator

Summary

Implement claim confidence scoring with weighted running average, harden paper extraction pipeline, and add Claude Code project configuration.

Changes

Confidence Scoring (new):

  • backend/scoring/confidence.py — weighted running average scoring for claims
  • Stance polarity: supports (+1.0), contradicts (-1.0), qualifies (+0.3)
  • Paper-level confidence computed as weighted mean of claim scores
  • Source diversity multiplier for multi-source validation
  • Initial confidence heuristics based on claim/paper type

Extraction Hardenings:

  • Better error handling in paper extraction pipeline
  • Event emission on key state changes
  • Verification layer improvements

Claude Code Setup:

  • .claude/settings.json — project permissions and lint hooks
  • CLAUDE.md updated with git workflow section
  • Personal override files gitignored

Files Changed

  • backend/scoring/confidence.py — full scoring implementation (112 lines)
  • backend/tests/test_confidence.py — comprehensive test suite (290 lines)
  • backend/extraction.py, backend/events.py, backend/verification.py — hardening
  • .claude/settings.json, CLAUDE.md, .gitignore — tooling setup

Test Plan

  • pixi run test — all existing tests pass
  • backend/tests/test_confidence.py covers scoring edge cases

Reviewer: @ARC345

arnavrastogi-hapticware and others added 15 commits May 30, 2026 16:47
Approved design for rCiv civilization Constitution:
- Per-institution Graphiti nodes tagged constitution:<institution>
- JSON format, fixed schema, Harness-parseable
- Graphiti temporal edges as version control (no git, no extra table)
- Amendment flow via constitutional researcher agents + verification pipeline
- Task 8: verification pipeline detects [constitutional-amendment] tag after
  scoring; auto-tier calls apply_amendment, human-tier calls flag_for_human_review
- Task 9: GET /constitution, GET /constitution/{institution}, GET /constitution/amendments/pending,
  POST /constitution/amendments/{id}/approve — Graphiti reads stubbed, PostgreSQL writes real
- Wires constitution router into main.py
Add GET /webhooks (list all, optional ?event_type filter) and
DELETE /webhooks/{event_type}/{url} (unregister) endpoints to
complement the existing POST /webhooks registration.

- events.list_webhooks() returns a copy of the registry
- events.unregister_webhook() removes a specific URL and cleans
  up empty event_type keys
- Tests cover empty, populated, filtered list, 404 on unknown
  webhook, and idempotent unregister
Issue #7 - Claim confidence scoring:
- Replace NotImplementedError stubs with real implementations
- update_claim_confidence: weighted running average based on stance polarity
- derive_and_persist_paper_confidence: type-weighted mean of claim scores
- derive_paper_confidence from claims auto-triggers assign_tags
- Full test suite for all confidence functions

Issue #6 - Harden claim extraction:
- Minimum body length guard (50 chars minimum)
- Maximum body truncation (32K chars to avoid LLM context overflow)
- Retry LLM calls with linear backoff (2 attempts)
- Global extraction timeout (120s) via asyncio.wait_for
- Graceful degradation: persist to PostgreSQL even if Graphiti unavailable
- Graceful degradation: skip embedding dedup if embedder fails
- Failed extraction leaves paper in queue for retry
- All external calls wrapped in try/except with structured logging
- Creates .claude/settings.json with project permissions and hooks
- Adds CLAUDE.local.md with PR workflow guidelines
- Updates CLAUDE.md with git workflow section
- Adds .claude personal overrides to .gitignore
- graphiti_client.py: move all heavy imports (GroqClient, GeminiClient,
  google.genai, Graphiti) inside init_graphiti() — prevents module-level
  ImportError cascade when dependencies are missing in test env
- postgres.py: move psycopg_pool import inside init_pool() — libpq
  not needed until actual DB operations
- confidence.py: replace module-level from backend.db.postgres import
  get_pool with local imports inside each async function — pure
  function tests now load without libpq
- conftest.py: wrap DB setup in try/except, skipping gracefully when
  dependencies missing instead of crashing test collection
- test_confidence.py: fix mock patch targets (backend.db.postgres.get_pool)
  to match lazy import pattern; fix _make_pool_mock to handle arbitrary
  execute counts without StopAsyncIteration
Implements Issue #34 — Court ruling confidence score and tag update:

- Add POST /claims/{claim_id}/evaluate endpoint that accepts stance
  (supports|contradicts|qualifies), weight (0-1), and source_id
- Internally calls update_claim_confidence to adjust claim score,
  then derive_and_persist_paper_confidence to recompute parent paper
- Add update_claim_status to confidence.py — derives claim status
  from score using same thresholds as papers (verified/disputed/preliminary)
- Wire update_claim_status into update_claim_confidence so status
  updates automatically on each evaluation
- 7 new unit tests + 1 integration test for the evaluate endpoint
- All 47 tests pass (claims_api + confidence + verification)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants