Files
rag-technical-docs-assistant/tests/support/search.py
T
amirhosein mazaheri fef381c41b 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.
2026-10-08 12:58:59 +03:30

53 lines
2.6 KiB
Python

"""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", newline="\n")
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"]