Files
rag-technical-docs-assistant/docs/guides/scoped-search-checkpoint.md
T
amirhosein mazaheri 7fa1c2dcc1 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.
2026-10-07 17:31:59 +03:30

89 lines
4.7 KiB
Markdown

# 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.