feat(search): add calibrated retrieval and LangChain knowledge tool

Add exact and semantic evidence admission, measured calibration, bounded tool execution, and independent held-out evaluation preparation with regression coverage and operator guides. Real-provider quality gates remain pending.

Validation: 1300 provider-free tests passed; 3 Windows symlink skips. PostgreSQL acceptance not rerun because TEST_DATABASE_URL is unset.
This commit is contained in:
amirhosein mazaheri
2026-10-08 12:58:59 +03:30
parent 4d36f2ba35
commit fef381c41b
36 changed files with 6679 additions and 45 deletions
+30 -9
View File
@@ -1,6 +1,6 @@
# Live document MVP TODO
Updated 2026-10-07 against the revision 1.3 specifications.
Updated 2026-10-08 against the revision 1.3 specifications and scoped-search repair review.
This checklist tracks implementation; it does not replace the governing
[delivery plan](../specifications/RAG-AI-Phase1-Delivery-Plan.md),
@@ -48,7 +48,7 @@ reported before promising a live demo.
The four supplied examples are acceptance fixtures, not a filename allowlist
or a four-document capacity limit.
## WP3 - Worker, review and publication (backend implemented; transport/selection pending)
## WP3 - Worker, review and publication (backend implemented; authenticated transport and Live invalidation pending)
- [x] Add reviewed forward extraction-state/audit changes without editing applied revisions.
- [x] Implement separate worker claim tokens, leases, heartbeats, bounded attempts and recovery.
@@ -60,22 +60,22 @@ or a four-document capacity limit.
- [x] Resume the same eligible failed document/job through the trusted retry backend/CLI after approval; fresh output requires fresh review. Authenticated D04 transport remains pending.
- [x] Retain faithful complete FAQ extraction and explicitly approve included factual Q&A groups.
- [x] Publish all validated chunks plus ready state in one transaction; keep new ready documents inactive.
- [ ] Implement activation/selection revisions, access epochs and invalidation with the documented lock order.
- [x] Implement atomic backend activation/selection, revision counters, access epochs and search-context rechecks with the documented lock order; see [search Phase 1/2 evidence](../agent-reference-map.md).
- [x] Verify duplicate workers, expired leases, stale approvals, retries and partial failures against isolated PostgreSQL.
## WP4 - Shared scoped search
- [ ] Implement one backend pgvector search service using compatible bounded query embeddings.
- [ ] Derive organization/user/conversation scope from backend identity.
- [ ] Filter to authorized, ready, active and undeleted documents.
- [ ] Combine semantic evidence with exact normalized identifiers and bounded context.
- [ ] Return faithful text and document_id/chunk_id/location sources.
- [x] Implement one backend pgvector search service using compatible bounded query embeddings; see [Phase 2 handoff](../guides/scoped-search-phase2.md).
- [x] Resolve persisted enabled actors and derive organization/user scope at the trusted operator boundary; model arguments cannot override scope. Browser identity and owned conversation integration remain pending in WP2/WP5.
- [x] Filter to authorized, ready, active, undeleted and unpurged documents in every retrieval branch.
- [x] Combine semantic evidence with exact normalized identifiers and bounded untrusted context in the same retrieval core.
- [x] Return faithful whole-chunk text, document_id/chunk_id/location and execution-wide source references within evidence budgets.
- [ ] Evaluate real Persian questions, numbers, conditions, exceptions and insufficient-evidence behavior.
- [ ] Record the measured decision on reranking/ANN; implement only if evaluation demonstrates a need.
## WP5 - LangChain and native Live
- [ ] Expose the shared search through a small LangChain retriever/tool boundary.
- [x] Expose the shared search through a strict sync/async LangChain tool with lazy imports, bounded admission/deadlines, cancellation and shutdown; see [Phase 3 handoff](../guides/scoped-search-phase3.md).
- [ ] Keep persistent secrets and provider-specific objects behind server adapters.
- [ ] Add minimal owned voice conversations, Live sessions and voice tool-call persistence through forward migrations.
- [ ] Implement session reservation and authenticated backend WSS audio relay to Gemini Live.
@@ -101,6 +101,27 @@ or a four-document capacity limit.
- [ ] Verify restart recovery, revocation, failure reporting and all MVP-01 through MVP-14 criteria.
- [ ] Record actual results, remaining limits and demo run instructions.
## Scoped-search technical checkpoint (2026-10-08)
Search milestone phases below are separate from ingestion Phases 1-6.
Implemented component checkmarks do not establish practical retrieval or Live readiness.
- [x] Phase 4 evaluation preparation and review repairs: 16 answerable and six unsupported original-derived draft annotations restored as UTF-8; status aligned; calibration-question overlap/malformed annotations rejected before settings/database/provider setup.
- [x] Final repair review: 52 targeted provider-free tests rerun and passed; original hashes/status/DOCX literal checks, pip check, tracked whitespace and all three applied-migration byte comparisons passed.
- [ ] Complete and freeze 20 answerable cases, including four unseen cases, plus six unsupported cases; obtain original approvals and required exact-output/factual DOCX human decisions. The unseen slots remain empty.
- [ ] Bind approved original hashes to actual eligible ready documents and select the corpus through the atomic selection service.
- [ ] Obtain funded-profile/provider-call authorization and separate bounded ingestion, calibration and evaluation budgets; measure and freeze the Phase 2 cutoff before held-out evaluation.
- [ ] Rerun mandatory isolated PostgreSQL acceptance with --require-postgres for the current repair checkpoint. TEST_DATABASE_URL is absent; the earlier 311-pass result is historical.
- [ ] Pass the real Phase 4 gate: at least 18/20, every critical case, all six unsupported cases returning no_evidence, and no unauthorized/ineligible sources.
The repair records a full provider-free run of 1300 passed with three existing
Windows symlink skips; that full run was not repeated during final review.
See the [Phase 4 operator guide](../guides/scoped-search-phase4.md),
[status snapshot](../calibration/phase4-status.json) and
[scoped-search plan](scoped-search-implementation-plan.md) for actual commands,
historical results and remaining prerequisites. Quality acceptance is not run;
provider calls are zero. Generated-answer and Live readiness remain unevaluated.
## Conditional delivery checkpoints
| Checkpoint | Required progress |