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:
amirhosein mazaheri
2026-10-07 17:31:59 +03:30
parent ff9c32823c
commit 7fa1c2dcc1
11 changed files with 798 additions and 2 deletions
+52
View File
@@ -0,0 +1,52 @@
"""Provider-free search pipeline fixtures on an isolated migrated database."""
from pathlib import Path
from uuid import uuid4
from sqlalchemy import text
from app.infrastructure.extraction_candidates import LocalExtractionCandidates
from app.infrastructure.file_store import LocalFileStore
from app.infrastructure.intake_repository import SqlIntakeRepository
from app.infrastructure.worker_repository import SqlWorkerRepository
from app.modules.documents.embeddings import EmbeddingLimits
from app.modules.documents.extraction import PageBlockExtractor
from app.modules.documents.intake import import_document
from app.modules.documents.worker import Worker
from tests.support.embedding import DeterministicEmbeddings
EVIDENCE = "Pump pressure is 25 bar only when temperature is below 60 C. Do not open the bypass except during shutdown."
QUERY = "When is pump pressure 25 bar?"
def configure(settings):
return settings.model_copy(update=dict(embedding_limits=EmbeddingLimits(
unit="utf8_bytes", max_input_units=4096, max_batch_units=8192, max_batch_inputs=2)))
def administrator(engine):
org, user = uuid4(), uuid4()
with engine.begin() as conn:
conn.execute(text("INSERT INTO organizations(id,name) VALUES (:id,'search fixture')"), dict(id=org))
conn.execute(text("""INSERT INTO users(id,organization_id,username,password_hash,role)
VALUES (:id,:org,:name,'test-only','admin')"""), dict(id=user, org=org, name=str(user)))
conn.execute(text("""INSERT INTO organization_settings(organization_id,assistant_name,instruction)
VALUES (:org,'Fixture','Answer from documents')"""), dict(org=org))
return org, user
def publish(engine, settings, root, user, evidence=EVIDENCE):
root = Path(root)
root.mkdir(parents=True, exist_ok=True)
source = root / "pump.md"
source.write_text(evidence, encoding="utf-8")
store = LocalFileStore(root / "originals")
candidates = LocalExtractionCandidates(root / "extractions", original_directory=store.directory)
document = import_document(SqlIntakeRepository(engine), store, settings, path=source,
administrator_id=user, request_id=uuid4(), title="Pump operating limits")["document"]
provider = DeterministicEmbeddings(settings)
worker = Worker(SqlWorkerRepository(engine, settings), store, candidates,
lambda _: PageBlockExtractor(), lambda _: (provider, None), settings)
worker.run_once(str(uuid4()))
with engine.connect() as conn:
assert conn.execute(text("SELECT status FROM documents WHERE id=:id"),
dict(id=document["id"])).scalar_one() == "ready"
return document["id"]