Skip to content

Commit 642a1ae

Browse files
committed
infra: add controller-pipeline check to advanced-backends smoke
Beyond the isolated ES/Neo4j backend checks, add a third check that builds the real RetrievalController with MEMTRACE_RETRIEVAL_HYBRID_BACKEND=elasticsearch and confirms a BM25 score reaches the candidates — proving the full retrieval pipeline routes through ES when the flag is set, not just the backend class. Skips cleanly when the extra/endpoint is absent (verified).
1 parent 5e0c41f commit 642a1ae

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

scripts/smoke-advanced-backends.sh

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,51 @@ async def check_neo4j():
8686
return "pass", f"Neo4j returned distance-weighted neighbors ({related})"
8787
8888
89+
async def check_pipeline_through_controller():
90+
"""Prove the FULL retrieval pipeline routes through Elasticsearch when the flag
91+
is set — not just the isolated backend class. Seeds memories in-process, builds
92+
the real RetrievalController with the backend enabled, and confirms a BM25 score
93+
reaches the candidates."""
94+
try:
95+
from elasticsearch import Elasticsearch # type: ignore
96+
except ModuleNotFoundError:
97+
return "skip", "elasticsearch package not installed"
98+
try:
99+
if not Elasticsearch(ES_URL, request_timeout=5).ping():
100+
return "skip", f"Elasticsearch not reachable at {ES_URL}"
101+
except Exception as exc: # noqa: BLE001
102+
return "skip", f"Elasticsearch not reachable ({type(exc).__name__})"
103+
os.environ["MEMTRACE_RETRIEVAL_HYBRID_BACKEND"] = "elasticsearch"
104+
os.environ["MEMTRACE_ES_URL"] = ES_URL
105+
os.environ["MEMTRACE_RETRIEVAL_USE_VECTOR"] = "false"
106+
from app.config import get_settings
107+
get_settings.cache_clear()
108+
from app.retrieval.controller import RetrievalController
109+
from app.runtime.repository import InMemoryRepository
110+
repo = InMemoryRepository()
111+
for mem in (_mem("m_region", "the deploy region is us-west"),
112+
_mem("m_cache", "the cache layer is redis"),
113+
_mem("m_db", "the primary database is postgres")):
114+
await repo.add_memory(mem)
115+
controller = RetrievalController(repo)
116+
backend = getattr(controller, "_hybrid_backend", None)
117+
if backend is None or not backend.available:
118+
return "fail", "controller did not construct an available ES hybrid backend from the flag"
119+
cands = await controller._select_candidates( # noqa: SLF001
120+
workspace_id="smoke_ws", run_id="r", query="which cache layer do we use", top_k=5)
121+
max_bm25 = max((c.bm25_score for c in cands), default=0.0)
122+
name = getattr(controller, "_hybrid_backend_name", None)
123+
if max_bm25 <= 0.0:
124+
return "fail", f"controller retrieval produced no BM25 score (backend={name})"
125+
return "pass", f"controller routed retrieval through ES (backend={name}, max bm25={max_bm25:.4f})"
126+
127+
89128
async def main() -> int:
90-
results = {"elasticsearch": await check_elasticsearch(), "neo4j": await check_neo4j()}
129+
results = {
130+
"elasticsearch": await check_elasticsearch(),
131+
"neo4j": await check_neo4j(),
132+
"pipeline(controller->ES)": await check_pipeline_through_controller(),
133+
}
91134
icon = {"pass": "✅", "skip": "⏭️ ", "warn": "⚠️ ", "fail": "❌"}
92135
for name, (status, detail) in results.items():
93136
print(f" {icon[status]} {name}: {detail}")

0 commit comments

Comments
 (0)