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

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.
Repo Amit-kr26/ChessMateStack Streamlit · Elasticsearch · PostgreSQL · OpenAI API · python-chess · Chessboard.js · Docker · Grafana
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
Drawing is wider than the frame. Drag to pan.
Also filed under LLM / RAG