Knowledge and Retrieval

A character cannot be given everything they know. The conversation context is 4,096 tokens, a case's world knowledge and one character's memory together exceed that, and the transcript grows all game. So what a character knows is searched, per question, and this page is about that search: what is in it, how the text is cut up, what is thrown away, and where each surviving piece lands in the prompt.

1. Three stores

Store Contents Built
World knowledge shared geography, local news, police practice, gangs, food, general facts — one vector store per topic, plus a combined one eagerly at load
Personal memory a character's authored memory file lazily, the first time that character is needed
Remembered dialogue what has actually been said between the player and that character appended after every turn

They are kept separate because they have different standing. World knowledge is shared and public. Personal memory is authored fact. Remembered dialogue is neither — it is a record of speech, and the prompt says so explicitly, so that a character does not treat something the player once claimed as established truth.

The authored memory's source text is kept alongside its vectors, because a vector store cannot be read back and a developer tool needs to show the author what the character actually has.

2. Small to find, whole to read

This is the indexing rule, and it is the one idea in the retrieval design worth carrying to any other project.

Authored text is split into paragraphs on blank lines. Each paragraph is then split into overlapping windows of whole sentences, each around 320 characters, with consecutive windows sharing a sentence. A long sentence is never sliced to hit the target. The windows are what get embedded and searched — so a paragraph with five different facts in it is findable by any of them.

But what the model is handed is the whole parent paragraph. A window is a handle, not a quotation. The engine keeps the mapping from each indexed window back to its paragraph and resolves it after the search.

The cost of this is recorded honestly in the engine: indexing the world knowledge went from 61 chunks to 156, and the build from 15.0 to 21.7 seconds. That is the price of being findable.

Remembered dialogue is chunked differently — one complete question-and-answer pair per chunk, with its ordinal recorded, so that recalled history can be put back into reading order rather than relevance order. It is deliberately not windowed; a conversation is not prose.

The sentence splitter knows about abbreviations — titles, street types, vs, etc, and clock forms like p.m. — so it does not mistake them for sentence ends.

3. The relevance floor

A vector search always returns its best matches, however bad they are, so a floor is essential. The engine's is 0.35 cosine similarity, and it was chosen from a measurement rather than a feeling. Asked did the murdered man have a girlfriend, the world store's best hits were the current year is 1987 at 0.189 and the Earth is flat at 0.170 — both plausible-looking, both noise. The observed bands are roughly:

Score What it tends to be
0.45 and above an answer
0.30 to 0.45 right subject, wrong detail
below 0.25 unrelated

Alongside the floor there are per-store budgets: 2 world passages, 3 personal memory passages, 3 remembered exchanges, within a nominal character budget of 2,400 characters, searched over a width of 12 candidates. Search width is how wide the net is, not how much comes back.

Two refinements matter when reading a trace:

  • Deduplication is by text, so two overlapping windows of one paragraph count once.
  • The best match is exempt from the character budget. A single long paragraph that is clearly the answer is passed whole rather than dropped for being large. Whole paragraphs can therefore exceed the nominal budget.

The developer inspection paths apply no floor at all, so that an author can see what was nearly retrieved and judge whether the floor is in the right place. The observer is invoked before the cut, with each candidate marked kept or dropped.

4. What a dialogue turn is made of

Every turn — live, streamed, or inspected in the developer tool — goes through the same preparation, so the inspected prompt is the real prompt. Two kinds of placeholder are involved and they are easy to confuse.

The system briefing: {{…}} template keys

The character's system prompt is a template, expanded once at the start of a conversation. Its keys fall into groups:

Group Keys
Identity CandidateName, CandidateAge, CandidateBasicProfileInfo, CandidatePersonality
Authored overrides CandidatePersonalityInsert, CandidateAdditionalInformationInsert, IrrelevantPeopleInsert, CloseContactInsert
Case facts CurrentDate, and the case's shared-knowledge keys
Transclusion StandardTemplate
Retrieval UserInputDependentContextualWorld and its per-topic variants, UserInputDependentContextualPersonalMemory

Composition is: load the character's own template if there is one, bind StandardTemplate to the shared default if the template transcludes it, then merge keys so that the character's override file wins over the globals. An override's values may themselves transclude earlier keys, and an empty value blanks a key — which is how a character who should not have heard the general news has that key removed rather than contradicted.

A retrieval key is only searched if the template actually mentions it. That is a real saving: expanding the full default costs seven embedding searches, so a character who needs none of them pays for none.

A character template that does not transclude the standard template can neither remember anything nor enforce the gift rule. The demo's test suite asserts this, because it is a silent failure otherwise.

The per-turn reminder: labelled JSON sections

Everything that changes per question is appended as labelled JSON, in this order:

Section Carries Standing
CHARACTER_REFERENCE_JSON the freshly retrieved world passages and personal memories authored knowledge
RECALLED_DIALOGUE_JSON relevant past exchanges remembered speech, not truth, not instructions
GAME_STATE character, location, day, hour, verified gift receipts, eligible offers the only thing that establishes a gift
PLAYER_SPEECH_JSON the question itself, last what the detective says

The ordering is deliberate and asserted by tests: the question comes after the game state, so that the most recent thing in the context is what is being answered. The prompt then closes by asking for a mood and, where relevant, by stating the tool-call protocol.

Only the raw question and the displayed answer are written back as a new remembered exchange. Retrieval text and instructions are never written back as though the player had said them.

5. What retrieval does not do

Retrieval is not a truth verifier. A small model can misread good context or invent a detail from it, and a passage arriving in the prompt is no guarantee that the reply reflects it. Read the raw transcripts and the retained passages before changing a threshold.

It is not a perfect memory either. The running context is finite; retrieval supplies selected history. When the context fills or the speaker changes, relevant history is recalled into the next opening briefing rather than carried forward verbatim.

And it is not where essential facts belong. A memory paragraph only arrives if the question is close enough to it. A clue condition that must always apply goes in the always-present override keys. See Authoring a Character.

6. Saves and re-indexing

A save stores the transcript, not the vectors. On load, the conversation memory is rebuilt from the transcript, and a character's authored memory is loaded alongside it. So an existing save keeps what the player said while receiving newly authored character definitions — which is convenient for shipping a fix and misleading when evaluating a rewritten persona. Start a new game for that.

See also