|
- #!/usr/bin/env bash
- # Retrieval benchmark (spec AC-04, section 18): loads the fixed corpus in tests/benchmark/fixtures.json into a
- # throw-away tenant, runs the labelled queries through /recall and /search with semantic retrieval (hybrid), then
- # again with the ollama container stopped (lexical baseline), and checks the thresholds stored in the fixtures.
- # Prints hit@5, MRR@10 and the false positive rate per query kind, and the hybrid misses.
- #
- # Needs the containers from docker-compose.yml (axonasp, ollama with nomic-embed-text, qdrant) and Python 3.
- # Stops and restarts the ollama container once; purges its tenant at the end. Set KEEP=1 to keep the result files.
- # bash tests/retrieval-benchmark.sh
- set -u
- cd "$(dirname "$0")/.."
- BASE=${BASE:-http://localhost:8801/api/v1}
- FX=tests/benchmark/fixtures.json
- PY="python -I tests/benchmark/run_benchmark.py"
- TMP=$(mktemp -d); TENANT=""
- prov() {
- MSYS_NO_PATHCONV=1 docker exec -u axonasp -e SERVER_WEB_ROOT=/opt/axonasp/site \
- -e "PROV_ACTION=$1" -e "PROV_ARG1=${2:-}" -e "PROV_ARG2=${3:-}" -e "PROV_ARG3=${4:-}" -e "PROV_ARG4=${5:-}" \
- axonasp ./axonasp-cli -r /opt/axonasp/site/scripts/provision.asp 2>&1 | tr -d '\015'
- }
- embed() { MSYS_NO_PATHCONV=1 docker exec -u axonasp -e SERVER_WEB_ROOT=/opt/axonasp/site -e "EMBED_ACTION=$1" axonasp ./axonasp-cli -r /opt/axonasp/site/scripts/embed.asp 2>&1 | tr -d '\015'; }
- field() { sed -n "s/^$1: *\([^ ]*\).*/\1/p" | head -1; }
- ollama_up() { for i in $(seq 1 60); do docker exec axonasp wget -qO- http://ollama:11434/api/version >/dev/null 2>&1 && return 0; sleep 1; done; return 1; }
- cleanup() {
- docker start ollama >/dev/null 2>&1
- [ -n "$TENANT" ] && prov purge "$TENANT" >/dev/null
- if [ -n "${KEEP:-}" ]; then echo "results kept in $TMP"; else rm -rf "$TMP"; fi
- }
- trap cleanup EXIT
-
- docker start ollama >/dev/null 2>&1; ollama_up || { echo "ollama is not reachable"; exit 2; }
- TENANT=$(prov tenant "bench" | field tenant_id)
- out=$(prov principal "$TENANT" bench agent); PID=$(echo "$out" | field principal_id); KEY=$(echo "$out" | field api_key)
- prov grant "$PID" /bench "read,write,verify" 1 >/dev/null
- NS=$(prov namespace "$TENANT" /bench | field namespace_id)
- [ -n "$NS" ] && [ -n "$KEY" ] || { echo "setup failed"; exit 2; }
-
- $PY load "$BASE" "$KEY" "$NS" "$FX" "$TMP/ids.json" || exit 2
- embed run >/dev/null
- embed status | grep -E '^ *(pending|failed): *[1-9]' && { echo "embedding backlog left; rerun"; exit 2; }
-
- $PY run "$BASE" "$KEY" "$FX" "$TMP/ids.json" hybrid "$TMP/hybrid.json" || exit 2
- docker stop ollama >/dev/null
- $PY run "$BASE" "$KEY" "$FX" "$TMP/ids.json" lexical "$TMP/lexical.json"; rc=$?
- docker start ollama >/dev/null; ollama_up
- [ $rc -eq 0 ] || exit 2
- echo
- $PY report "$FX" "$TMP/hybrid.json" "$TMP/lexical.json"
|