Starts Nov 23Live Cohort 3 of Vibe Coding & AI Agents (Nov 23, 18:30 MSK): 3 weeks, 9 live hands-on sessionsCohort 3 (Nov 23) →
ReleaseInsight · On RadarHabr AI→ original

A Developer Built an AI Librarian for Role-Playing Games That Won't Leak Other Players' Secrets

A game master at a live-action role-playing event rarely has time to dig through files for player questions, so the author of Baza handed that job to an AI librarian. It answers in character and draws facts only from the game's materials. A secret document is removed from search before the model ever sees it, so the knight will never hear a letter marked "for witches only." The takeaway for any working knowledge base: enforce access rights at retrieval time, don't ask the model to keep quiet.

AI-processed from Habr AI; edited by Hamidun News
A Developer Built an AI Librarian for Role-Playing Games That Won't Leak Other Players' Secrets
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Five response checksrole, AI mention, forbidden words, truncation, fabrication
Access grants in YAMLroles, locations, teams, or specific players
Key metric #3No answer in the materials means the character honestly stays silent instead of making one up

At a role-playing event, game masters know this scene well. A player walks up with a ready question, the master holds a radio in one hand and someone else's prop in the other, and the answer sits in a folder of materials and in the heads of three different people. Either the master improvises and then argues with their own document, or they say "wait, let me find the file."

A developer who runs such games himself wrote Baza, a program that works as an AI librarian. It is a character at a station who answers players in place of the master, but takes its facts only from documents uploaded in advance. This scheme is called RAG: the neural network first searches for the relevant pieces of text, then answers based on them.

It does not reveal secrets, because closed documents are filtered out of the search before the neural network ever sees them. If a letter is meant only for witches, the knight will not learn of it, no matter how he asks.

What It Looks Like for a Player

The station has a screen, a column, and a microphone. They can be hidden inside a "glowing idol" or a magic cube. The first to greet players is a guard, who asks for a secret word. Instead of a word, a QR code for a cyberpunk game or a picture will do. Players get three attempts to authorize. After that, the system figures out who it is talking to and knows how to address them: "traveler," "Your Grace," or "My Lady."

If there are several knowledge keepers, the gatekeeper asks where the player wants to go: to the librarian or to the tavern keeper. Each character has its own voice and manner of speaking. Players can ask by text, by voice, or by voice with subtitles. While the NPC is "digging through the archives," the screen says exactly that, because it really is running a search.

If the materials contain no answer, the character does not invent a "biography of the king for atmosphere." It refuses without breaking character. The master writes examples of such refusals in advance so that they don't sound like a call-center reply.

What's Under the Hood

The world materials are Markdown files with a YAML header. On upload, they are split into chunks, and a vector is computed for each chunk (a numerical "fingerprint" of its meaning). Everything then goes into Postgres with pgvector. Alongside it runs ordinary keyword search, and the results are merged using RRF, a method that combines two rankings into one. Each game gets a separate project in the admin panel, and search runs only within it.

The answer pipeline works like this:

  • a search query is built from the player's latest message, taking the dialogue into account;
  • pgvector returns the matching fragments;
  • the fragments are filtered by access rights;
  • weak matches are cut off at a sharp drop in RRF scores (the author calls this an elbow cut);
  • what remains goes to the role-playing game engine.

The most useful part for engineers is access control. The file header specifies who can see it: everyone, specific roles, locations, teams, or individual players. An empty grant means "general material."

If a master writes "not for everyone" and names nobody, no one can see the document. Filtering happens at the search level, before the prompt is assembled. The model never receives the secret chunk, so it cannot reveal it, even if a player presses.

This is more reliable than asking the model in a system instruction not to mention such things. As a side effect, less extra text ends up in the context. The author does not provide token or cost figures, so this is only a logical consequence.

A simple prompt saying "answer as the NPC" did not work: the neural network kept giving itself away. So a validator was added. It checks the answer in a strict order:

  1. whether the answer broke character;
  2. whether it mentions the bot or AI;
  3. whether it uses words forbidden by the character card;
  4. whether the answer was cut off;
  5. whether all facts come from the retrieved context.

There is also basic protection against prompt injection, though the author doubts players will test it, since it breaks immersion. The stack includes FastAPI, SQLAlchemy, and JWT in an httponly cookie, with GigaChat or YandexGPT accessed via API and Yandex SpeechKit for voice.

What to Take From This, and the Limitations

The project looks like a personal development effort. There are no quality metrics: no share of wrongful refusals, no false-positive rate for the validator, no voice response latency. There is no cost estimate either. The validator most likely adds another pass through the model, which means extra time and money. For a live game where the player is waiting at the screen, this matters. The promise that "the neural network doesn't make up facts" is so far backed only by the author's word.

Still, three techniques carry over to ordinary working systems:

  • Access rights in document metadata. The filter runs before the prompt. This suits a corporate knowledge base where different departments have different permissions.
  • Refusal as a normal outcome. If the context is empty, the system stays silent or honestly says the information is not available.
  • A separate check of the answer. Role, prohibitions, and grounding in sources are verified after generation, not merely described in the prompt.

The author plans a narrator character, an inventory and quests tied to player status, NPC portraits, and export of game sessions to PDF as chronicles. For masters, it is a way to hand the routine of questions and answers to a machine. For everyone else, the project shows how to build RAG with real access control on a small stack of FastAPI, Postgres, and pgvector.

Story

Key Questions Answered

What It Looks Like for a Player?

The station has a screen, a column, and a microphone. They can be hidden inside a "glowing idol" or a magic cube. The first to greet players is a guard, who asks for a secret word. Instead of a word, a QR code for a cyberpunk game or a picture will do. Players get three attempts to authorize.

What's Under the Hood?

The world materials are Markdown files with a YAML header. On upload, they are split into chunks, and a vector is computed for each chunk (a numerical "fingerprint" of its meaning). Everything then goes into Postgres with pgvector. Alongside it runs ordinary keyword search, and the results are merged using RRF, a method that combines two rankings into one. Each game gets a separate project in the admin panel, and search runs only within it.

What to Take From This, and the Limitations?

The project looks like a personal development effort. There are no quality metrics: no share of wrongful refusals, no false-positive rate for the validator, no voice response latency. There is no cost estimate either. The validator most likely adds another pass through the model, which means extra time and money. For a live game where the player is waiting at the screen, this matters. The promise that "the neural network doesn't make up facts" is so far backed only by the author's word.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…