Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

49 lines
2.7KB

  1. #!/usr/bin/env bash
  2. # Retrieval benchmark (spec AC-04, section 18): loads the fixed corpus in tests/benchmark/fixtures.json into a
  3. # throw-away tenant, runs the labelled queries through /recall and /search with semantic retrieval (hybrid), then
  4. # again with the ollama container stopped (lexical baseline), and checks the thresholds stored in the fixtures.
  5. # Prints hit@5, MRR@10 and the false positive rate per query kind, and the hybrid misses.
  6. #
  7. # Needs the containers from docker-compose.yml (axonasp, ollama with nomic-embed-text, qdrant) and Python 3.
  8. # Stops and restarts the ollama container once; purges its tenant at the end. Set KEEP=1 to keep the result files.
  9. # bash tests/retrieval-benchmark.sh
  10. set -u
  11. cd "$(dirname "$0")/.."
  12. BASE=${BASE:-http://localhost:8801/api/v1}
  13. FX=tests/benchmark/fixtures.json
  14. PY="python -I tests/benchmark/run_benchmark.py"
  15. TMP=$(mktemp -d); TENANT=""
  16. prov() {
  17. MSYS_NO_PATHCONV=1 docker exec -u axonasp -e SERVER_WEB_ROOT=/opt/axonasp/site \
  18. -e "PROV_ACTION=$1" -e "PROV_ARG1=${2:-}" -e "PROV_ARG2=${3:-}" -e "PROV_ARG3=${4:-}" -e "PROV_ARG4=${5:-}" \
  19. axonasp ./axonasp-cli -r /opt/axonasp/site/scripts/provision.asp 2>&1 | tr -d '\015'
  20. }
  21. 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'; }
  22. field() { sed -n "s/^$1: *\([^ ]*\).*/\1/p" | head -1; }
  23. 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; }
  24. cleanup() {
  25. docker start ollama >/dev/null 2>&1
  26. [ -n "$TENANT" ] && prov purge "$TENANT" >/dev/null
  27. if [ -n "${KEEP:-}" ]; then echo "results kept in $TMP"; else rm -rf "$TMP"; fi
  28. }
  29. trap cleanup EXIT
  30. docker start ollama >/dev/null 2>&1; ollama_up || { echo "ollama is not reachable"; exit 2; }
  31. TENANT=$(prov tenant "bench" | field tenant_id)
  32. out=$(prov principal "$TENANT" bench agent); PID=$(echo "$out" | field principal_id); KEY=$(echo "$out" | field api_key)
  33. prov grant "$PID" /bench "read,write,verify" 1 >/dev/null
  34. NS=$(prov namespace "$TENANT" /bench | field namespace_id)
  35. [ -n "$NS" ] && [ -n "$KEY" ] || { echo "setup failed"; exit 2; }
  36. $PY load "$BASE" "$KEY" "$NS" "$FX" "$TMP/ids.json" || exit 2
  37. embed run >/dev/null
  38. embed status | grep -E '^ *(pending|failed): *[1-9]' && { echo "embedding backlog left; rerun"; exit 2; }
  39. $PY run "$BASE" "$KEY" "$FX" "$TMP/ids.json" hybrid "$TMP/hybrid.json" || exit 2
  40. docker stop ollama >/dev/null
  41. $PY run "$BASE" "$KEY" "$FX" "$TMP/ids.json" lexical "$TMP/lexical.json"; rc=$?
  42. docker start ollama >/dev/null; ollama_up
  43. [ $rc -eq 0 ] || exit 2
  44. echo
  45. $PY report "$FX" "$TMP/hybrid.json" "$TMP/lexical.json"

Powered by TurnKey Linux.