feat(search): implement Phase 1 scoped search vertical slice
Resolve persisted enabled actors and atomically replace knowledge selection with revision checks, removal epochs, stable locking and audit updates. Reuse compatible query embeddings for scoped pgvector cosine retrieval, revalidate authority after remote work, and expose opt-in operator inspection with uncalibrated candidates. Validation: 37 targeted tests passed (14 unit, 23 PostgreSQL); provider-free inactive-to-active demonstration passed. Real-provider demonstration remains pending ingestion database connectivity. Applied migrations are unchanged.
This commit is contained in:
@@ -68,7 +68,7 @@ Prototype runtime prerequisites remain unverified: configured credentials, appro
|
||||
## Gaps and decisions
|
||||
|
||||
- Required document content is available under `specifications/`; no reference-dependent workflow is currently blocked by missing content. If a linked document later disappears, mark only dependent contract work blocked, report its exact path, and continue unrelated work without inventing it.
|
||||
- Material implementation gap: prototype Chroma/local Markdown/in-memory chat does not search the uploaded-document pipeline. Worker/publication/retry are implemented; remaining work includes authenticated review transport, scoped pgvector search, HTTP identity/upload, LangChain integration, native Live and UI. Full durable text turns/history are deferred; no component test certifies this integration.
|
||||
- Material implementation gap: prototype Chroma/local Markdown/in-memory chat does not search the uploaded-document pipeline. Worker/publication/retry are implemented; remaining work includes authenticated review transport, calibrated search/exact identifiers, HTTP identity/upload, LangChain integration, native Live and UI. The Fast-Track Search Phase 1 core and operator selection/inspection CLIs now exist; see the checkpoint below. Full durable text turns/history are deferred; no component test certifies this integration.
|
||||
- Open validations: exact format/size caps, funded model profiles/vector dimension, Gemini Live WSS/tool/transcript and Persian speech proof, hosting/connectivity, account/session/retention policy, quality target and delivery date. Direct Gemini Live, LangChain, new browser uploads, existing embedding reuse and all supplied example structures are confirmed MVP direction. See guide 13 and plan 2. Do not turn proposals into recorded approvals.
|
||||
- The 2026-10-06 MVP supersedes provisional SDP/WebRTC with backend-managed direct Gemini Live WSS; see API Section 7. Current-session provider answer transcripts/sources are displayed when available; durable full voice history remains deferred. Broader features do not authorize model selectors or CTI.
|
||||
- Project documentation now lives under `docs/`; sample corpus files remain under `data/documents/`. A future default corpus rebuild excludes the moved specifications and reference map. Existing vector indexes are not rebuilt or cleaned by this reorganization and may retain previously indexed project documentation. Use an approved corpus for real-provider evaluation.
|
||||
@@ -1323,3 +1323,43 @@ Affected repair files (all other baseline files are unchanged):
|
||||
- docs/specifications/RAG-Phase1-Implementation-Guide.md
|
||||
- tests/integration/test_phase6.py
|
||||
- tests/unit/test_phase6.py
|
||||
|
||||
## Fast-Track Search Phase 1 first-result checkpoint (2026-10-07)
|
||||
|
||||
Current inventory supersedes historical statements that scoped search and
|
||||
selection are still entirely absent. [Shared selection/search core](../app/modules/knowledge/service.py),
|
||||
[selection CLI](../app/knowledge.py), [inspection CLI](../app/search.py),
|
||||
[targeted PostgreSQL tests](../tests/integration/test_scoped_search.py),
|
||||
[input/CLI tests](../tests/unit/test_scoped_search.py), and
|
||||
[provider-free demonstration](../tests/search_demo.py) now exist.
|
||||
See the [operator checkpoint guide](guides/scoped-search-checkpoint.md)
|
||||
for setup, commands, exact observed source IDs/text and limitations.
|
||||
|
||||
Implemented: persisted enabled actor/organization resolution; full-set selection
|
||||
with expected knowledge revision, settings-first document locks in UUID order,
|
||||
no-op counter preservation, knowledge revision increments, removal epochs and
|
||||
atomic change audit; compatible bounded one-input query embeddings outside
|
||||
transactions; exact pgvector cosine eligibility joins; actor/epoch revalidation;
|
||||
whole-chunk diagnostic results (five chunks, 12000 text characters).
|
||||
No migration, dependency, prototype retriever, HTTP search or framework was added.
|
||||
The inspection format is uncalibrated_candidates, not the model-tool contract.
|
||||
|
||||
Actual checks:
|
||||
- PostgreSQL prerequisite probe passed: PostgreSQL 16.15 / pgvector 0.8.7 in a
|
||||
fresh dedicated container/database on 127.0.0.1:54938.
|
||||
- `.venv/Scripts/python -m pytest tests/unit/test_scoped_search.py tests/integration/test_scoped_search.py --require-postgres -q --tb=short`:
|
||||
**37 passed** (14 unit, 23 PostgreSQL), zero skips, 28.46 seconds.
|
||||
- `.venv/Scripts/python -m tests.search_demo` with isolated TEST_DATABASE_URL:
|
||||
inactive=0 candidates; after legitimate selection revision=2/epoch=1,
|
||||
one faithful pump-limit candidate with document/chunk IDs and actual locator.
|
||||
- Selection/search CLI help verified; tracked and new-file whitespace passed;
|
||||
all applied migration files compared byte-for-byte with HEAD and preserved.
|
||||
|
||||
The available operator URL was rejected by the isolated-test guard because its
|
||||
database name was not suffixed _test; it was not used for test writes.
|
||||
The deployment ingestion database connection failed with OperationalError.
|
||||
Credentials/configuration were present but no hosted call was attempted;
|
||||
approved ready real-document/provider demonstration remains pending a reachable
|
||||
compatible ingestion database. This is provider-free database validation, not
|
||||
semantic-quality acceptance. Full regressions/calibration/LangChain/UI/Live/ANN
|
||||
were not run or built; Fast-Track phases 2-4 remain pending.
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
# Fast-Track Search Phase 1 checkpoint
|
||||
|
||||
This checkpoint provides atomic selected-knowledge replacement and one scoped
|
||||
pgvector cosine search through a trusted operator CLI. User UUID arguments are
|
||||
operator authority inputs, not HTTP authentication. Search resolves enabled
|
||||
actors and their organization from persisted users. Administrators manage
|
||||
selection; enabled users and administrators can inspect candidates.
|
||||
|
||||
Reuse the ingestion setup and worker to publish a ready document. Configure
|
||||
the existing INGEST_DATABASE_URL and complete compatible embedding identity,
|
||||
input limits/tokenizer and credentials. No new dependency or migration is needed.
|
||||
|
||||
```powershell
|
||||
.venv/Scripts/python -m app.knowledge selection get --administrator-id <admin-id>
|
||||
.venv/Scripts/python -m app.knowledge selection replace --administrator-id <admin-id> --expected-revision <knowledge-revision> --document-id <ready-document-id>
|
||||
.venv/Scripts/python -m app.search --inspect --user-id <user-id> --query "<question>" --allow-provider-calls
|
||||
```
|
||||
|
||||
Repeat --document-id for a full selected set. --clear explicitly replaces it
|
||||
with an empty set and cannot accompany document IDs. A no-op preserves all
|
||||
counters and creates no change audit. Additions increment knowledge revision;
|
||||
removals also increment access epoch. Configuration revision is preserved.
|
||||
Flags, counters and change audit commit atomically, with settings locked before
|
||||
documents in UUID order. A stale expected revision fails; read selection again.
|
||||
|
||||
Inspection performs exactly one query embedding call, outside database
|
||||
transactions. It uses the existing adapter, preprocessing, limits/tokenizer,
|
||||
float32 validation and database compatibility checks. SQL statement/lock
|
||||
timeouts are 5/2 seconds; the provider uses the finite configured timeout.
|
||||
Before retrieval it rechecks enabled actor, organization/role and access epoch.
|
||||
Search joins document/chunk organization identities and excludes inactive,
|
||||
unready, deleted and purged content. It retrieves at most 50 cosine candidates,
|
||||
returning at most five whole chunks within 12,000 text characters.
|
||||
|
||||
JSON on stdout labels results as uncalibrated_candidates with
|
||||
semantic_quality=not_assessed. Candidates contain faithful text, title,
|
||||
document_id, chunk_id, actual location and cosine distance. This is a diagnostic
|
||||
format, not a model tool response, evidence-sufficiency verdict or semantic
|
||||
quality certification. Failures go to stderr and return a nonzero exit code.
|
||||
|
||||
## Observed demonstration, 2026-10-07
|
||||
|
||||
The configured ingestion database could not connect (OperationalError). Hosted
|
||||
embedding credentials/configuration were present but were not exercised, and
|
||||
no processed approved real document could be verified. The missing prerequisite
|
||||
for the real demonstration is a reachable compatible ingestion database with
|
||||
an approved ready document. No deployment data was changed.
|
||||
|
||||
A dedicated local test container ran PostgreSQL 16.15 and pgvector 0.8.7.
|
||||
The exact provider-free demonstration command was:
|
||||
|
||||
```powershell
|
||||
$env:TEST_DATABASE_URL = 'postgresql+psycopg://postgres:search-test-only@127.0.0.1:54938/rag_scoped_search_test'
|
||||
.venv/Scripts/python -m tests.search_demo
|
||||
```
|
||||
|
||||
The demo used actual intake, extraction, embedding staging and worker publication
|
||||
in a disposable schema, with deterministic embeddings and no provider calls.
|
||||
Question: "When is pump pressure 25 bar?"
|
||||
|
||||
Observed: inactive_candidate_count=0; selection revision=2, access_epoch=1;
|
||||
one uncalibrated candidate after selection. Title: "Pump operating limits".
|
||||
Text: "Pump pressure is 25 bar only when temperature is below 60 C. Do not open
|
||||
the bypass except during shutdown." Location: page=null,
|
||||
section="text/paragraph/1". Observed document ID:
|
||||
568e01ca-cacb-4a0b-bff8-1e6b071dac3d; chunk ID:
|
||||
1404092e-d8cf-4cc2-a72a-dda898baa625; cosine distance:
|
||||
0.35838125217767736. IDs are disposable and change on each run.
|
||||
|
||||
Targeted checks:
|
||||
|
||||
```powershell
|
||||
.venv/Scripts/python -m tests.postgres_prerequisites
|
||||
.venv/Scripts/python -m pytest tests/unit/test_scoped_search.py tests/integration/test_scoped_search.py --require-postgres -q --tb=short
|
||||
```
|
||||
|
||||
The final targeted run passed 37 tests (14 unit, 23 PostgreSQL), with zero skips.
|
||||
The dedicated container was stopped after validation and retained for reuse;
|
||||
restart it with docker start rag-scoped-search-20261007 before repeating the
|
||||
command above. A fresh environment can create it with:
|
||||
|
||||
```powershell
|
||||
docker run --name rag-scoped-search-20261007 -e POSTGRES_PASSWORD=search-test-only -e POSTGRES_DB=rag_scoped_search_test -p 127.0.0.1:54938:5432 -d pgvector/pgvector:pg16
|
||||
```
|
||||
|
||||
Wait for PostgreSQL readiness and rerun the prerequisite probe first. Applied migration
|
||||
files were preserved. Full regression and real-provider semantic-quality
|
||||
acceptance are outside this checkpoint; phases 2-4 remain pending.
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
**Date:** 2026-10-07
|
||||
**Target file:** `docs/plans/scoped-search-implementation-plan.md`
|
||||
**Status:** Approved planning direction; implementation and acceptance remain pending. This four-phase plan replaces the earlier seven-phase proposal.
|
||||
**Status:** Phase 1 first-result checkpoint implemented with provider-free PostgreSQL acceptance (2026-10-07); real-provider demonstration is pending ingestion database connectivity. Phases 2-4 remain pending. This four-phase plan replaces the earlier seven-phase proposal.
|
||||
|
||||
## 1. Delivery Strategy
|
||||
|
||||
|
||||
Reference in New Issue
Block a user