ChessMate

Retrieval over real master games: ask about a position and get analysis, best-move ideas and FEN puzzles in plain language.

LLM / RAG2025All work

Fig. 01ChessMate, chat alongside a rendered FEN board.
ChessMate, chat alongside a rendered FEN board.

What it is

What it does

ChessMate answers chess questions by retrieving real games rather than trusting model memory. It indexes Lichess games into Elasticsearch, pulls the closest matches for your position or opening, and has GPT explain errors, candidate moves, ideas and practice puzzles, with every answer graded for relevance and logged for monitoring.

Why it exists

Stockfish tells you +0.8 but not why, and a raw LLM will invent a line that never happened. I wanted answers that point to real master games ('here's where this idea worked before') instead of made-up theory.

2,000
Games indexed
2×
LLM calls per query
SQL
Monitoring panels

Repo Amit-kr26/ChessMateStack Streamlit · Elasticsearch · PostgreSQL · OpenAI API · python-chess · Chessboard.js · Docker · Grafana

Build8decisions

How it is built

Ingestion with python-chess

chat/utils/setup.py parses a 92.8 MB Lichess PGN export with chess.pgn.read_game and indexes games into Elasticsearch (2,000-game slice).

Whole-game documents

The chess-rag index stores moves, both players, Elo ratings, event, result and keyword-typed opening per document. Retrieval units are complete games, not loose positions.

Tuned lexical retrieval

Queries run multi_match BM25 with moves boosted ×3 alongside opening, returning the top 5 games as context.

Two LLM calls per question

GPT-3.5-turbo answers using prompt v5 (errors, best moves, one or two FEN-formatted puzzles, similar games), then grades its own output RELEVANT / PARTLY_RELEVANT / NON_RELEVANT.

Full observability

PostgreSQL tables log conversations with prompt/completion/total token counts (main + eval calls), response time and the relevance verdict; thumbs feedback attaches by foreign key.

Grafana over Postgres

Dashboard panels track thumbs ratio, relevance distribution, token usage over time and response latency straight from SQL queries.

Cheap repeat views

st.cache_data caches RAG answers with a ~6h TTL, so identical questions don't re-hit the API.

Four-service compose

elasticsearch 7.17.9 (single node), postgres 13, the Streamlit app and Grafana run together via docker-compose; Chessboard.js renders FEN positions client-side.

How the pieces connect

Ask and answer Index, log and watch Streamlit chat question + FEN BM25 multi_match moves ×3, top 5 Elasticsearch 2,000 whole games GPT-3.5 Turbo prompt v5, streaming Self-grade relevance verdict Lichess PGN 92.8 MB export python-chess chess.pgn.read_game PostgreSQL tokens, latency, verdict Grafana panels from SQL top 5 games as context