TouchlineAI

How it works

Under the hood

A football question goes in. A checked answer comes out. This page shows the machinery: the stack as a starting eleven, the path one question takes, a VAR check you can try to fool, and the numbers I measured, including where it comes up short.

The stack

The Starting XI

Eleven pieces, drawn as a 4-3-3. Hover, focus or tap a player to see what it does and where it lives in the code.

1Postgres2Alembic3Models4Ingest5Docker6Analytics7RAG8Tools9FastAPI10Agent + VAR11Next.js
10FWD

Agent loop + VAR check

A custom tool loop. Every finding must cite its tool calls and event ids; the validator checks each number against what the tools returned.

apps/api/app/agents/analyst.py

The build-up

One question, five touches

Every answer follows the same move, and each step can be tested on its own.

  1. 1

    Ingest

    StatsBomb events, lineups and 360 frames load into Postgres, with the full raw JSON kept.

    Idempotent. Shootout kicks and the extra-time clock reset handled.

  2. 2

    Measure

    xG, PPDA, minutes, heatmaps and shooting-lane context are computed from those events.

    Recounted from the raw files in tests.

  3. 3

    Retrieve

    156 documents are embedded with a local model. pgvector finds them by meaning; exact filters catch attributes.

    recall@3 of 1.00 on 20 questions.

  4. 4

    Reason

    A language model picks from eight validated tools, up to eight turns, and submits structured findings.

    OpenAI by default; Anthropic also wired in.

  5. 5

    Check

    The validator checks every cited number and event id against the tool results. Failures go back once, then get flagged.

    Each rule broken on purpose to prove tests catch it.

The big idea

The VAR check

A language model will happily state a number it made up. So the analyst can't just say things: each finding must cite the tool call that produced its numbers, and a validator checks them. The same rule runs here, in your browser, on a real slice of a tool result.

1 · What the database returned (tool call c1)

{
  "call_id": "c1",
  "home": { "team": "Argentina",
            "goals": 1, "shots": 15,
            "xg": 2.49 },
  "away": { "team": "Saudi Arabia",
            "goals": 2, "shots": 3,
            "xg": 0.15 }
}

2 · What the analyst claims. Try to fool it.

“Argentina's expected goals were ,” citing c1.

VAR: goal stands

2.49 appears in the cited tool result.

The finding is shown with a green VAR badge.

The moments

Search by meaning, filter by fact

156 documents (tactical concepts, match summaries, and one entry per shot) are embedded with a small local model and searched in Postgres with pgvector. Meaning-based search is great at “why does the better team lose?” and bad at exact attributes, which the table shows honestly. Exact filters (corner, header, penalty, player) cover that.

Question setQueriesFirst runAfter fixing the documents
Concept questions200.90 recall@3 · 0.85 top-11.00 · 0.95
Which match was it?40.50 top-10.75 top-1 · 1.00 in top 3
Find a named moment51.00 hit@31.00
Attribute only (“goal from a counter-attack”)40 of 3 rightsame: that is why exact filters exist

The numbers

What I measured

Every figure here came from running the code. Where a check failed on the first try, that is in the notes too.

130

API tests

Metrics recounted from the raw StatsBomb JSON, the official scores, and known facts.

45

Browser and unit tests

Playwright drives the real API; only the language model is mocked.

1.00

Search recall@3 (20 questions)

Started at 0.90; fixed by rewording documents, not by editing the questions.

11

Players per team, every match

Minutes played are checked: each side always adds up to eleven on the pitch.

11/25

Blocked shots with no visible defender

So the 360 shooting-lane count is a lower bound. The app says so.

345 MiB

API memory, model loaded

Measured in Docker, so a 1 GB host has room to spare.

The analyst itself

On nine golden questions (gpt-5.6-luna, live): 100% passed and 100% of findings were verified, at a median 5 s and about $0.001 per question. The first run scored 89%: the one miss was a miscounted tally, fixed by making the tool return the totals. Nine questions is a smoke test, not a benchmark.

The limits

Offside lines

Where Touchline AI stops, so nobody has to find out the hard way.

  • Event data only.

    No player tracking and no video-derived formations. Ask for a formation or a sprint speed and the analyst has to say it can't tell you.

  • Small sample.

    Five World Cup 2022 matches. One game is also a noisy sample, and the analyst is told to say so.

  • The 360 lane count is a lower bound.

    11 of 25 blocked shots show no visible defender in the lane, so a zero never proves a clear lane.

  • xG is not the whole story.

    It ignores game state: a team that scored early may simply have sat back.

  • Search is exact, not tuned.

    A plain vector scan over 156 documents. That is right at this size and would need an index at ten thousand.

  • One model at a time.

    The loop is provider-neutral (OpenAI by default, Anthropic wired in), but it has been tuned for neither. Swap models and compare with the eval.

Match data comes from StatsBomb Open Data, used under their terms with attribution. The embedding model is BAAI/bge-small-en-v1.5 (MIT). Built by Vishnu K. Source on GitHub.

Kick off in the Match Centre