Context

Introduction
Context is the total raw user input sent to an AI Dynamic Storyteller's Model to generate each output.

Story
The bulk of a generation's input context is usually the Story text; it should be filled with Prose. The initial content of an AI Dynamic Story is a sharable piece of text known as a Prompt. Outputs generated by the AI are added to the Story, and benefit by a user's skill in Wrangling.

Memory
Memory is text inserted into the context separate from the Story. As such, Memory text can be retained consistently across multiple output generations.

Key-Activated Context
See also: Lore Repositories, Lorebooks Segments of text can be inserted into the context by certain strings in a user's input. In Novel AI parlance, Key-Activated Context is known as the 'Lorebook', while AI Dungeon refers to this concept as 'World Info'. Used intelligently, this can be a powerful tool to organically insert information that isn't desired to permanently remain in the context via the Memory or Author's Note fields. The most basic form of the Key-Activated Context (KAC) involves a block of text set to be inserted into context whenever a trigger word or phrase, known as a key, appears in the story field. Novel AI offers more customizable insertion settings and triggering mechanisms for advanced users to exploit. Key Relative Insertion tries to plug the Lorebook entry text near where the key appears in the context to make it read more closely as an associated concept by the AI model. Cascading Activation allows the Lorebook to search outside of the story field for keys, including in the Memory, Author's Note, and other Lorebook entries. Novel AI also offers the ability to trigger Biases upon activation of a lorebook entry, making chosen words or phrases more likely to be generated by the AI while the activated entry remains in context. Categories for the Lorebook, at is simplest, is a user-facing sorting system for Lorebook entries, but also possess the ability to activate entries sorted under the category with their own specific insertion locations in context, as well as phrase bias based on the entire category. Bias for Categories can also be utilized when the entries in the Category are inactive, meaning you can bias in favor of a chosen term which in turn triggers associated entries under the given category, without the user having to deliberately invoke the keys.

Keys
Activate a given Lore entry. Can benefit from intelligent use of RegEx.

Search Range
Specifies how many tokens/characters backwards in context an AI should search for lore keys.

Protip: You likely need a smaller Search Range than you think you do. Extending Search Ranges for too long will clutter the context with Lore entries that aren't immediately relevant; keep Search Ranges tight, and use Keys skillfully. Ideally, your Current Context will only have Lore entries loaded that are relevant to the current generation.

Author's Note
See also: Tags

If not using Tags, Author's Note is recommended to be kept short and sweet. A single sentence or two that hammers in the main focus of the scene; especially when not using [brackets], Author's Note should be written into prose that blends nearly seamlessly into the story.

Combined Context (using NAI as a sampler)
Combined context designates the combination of all of the above sources of text that the AI ultimately receives. As of the time of writing the only known service that lets you actually see what is being sent to the AI is NovelAI. Using NAI's context viewer you get a rundown of how many tokens you current context uses and what is actually inside. The text within is color coded by its source (Story, Memory, AN, Lorebooks [if any, on an individual basis]). You can also click it to check the list below for what it is if your context is so full it requires scrolling.

You can also view the creation of your current context step by step, or rather stage by stage, by clicking the previous / next page buttons. You will see all items entered in order, starting from the end.

By default in NovelAI has a lot of wacky options that affect how text is inserted. For the purposes of this explanation the only options that really matter are Insertion Order and Insertion Position. Also Insertion Type, kind of.

Insertion Order: Functions as a priority system, where the highest number gets inserted into context first.

Insertion Position: Defines the location new text is inserted.

- An insertion position of 0 puts it at the very top.

- An insertion position of 1 places it 1 unit lower down, counting from the top.

- An insertion position of -1 places it at the very end of the generation.

- An insertion position of -2 places it 1 unit away from the very end of the generation.

Insertion Type: The 'unit' being counted for placement of text parts. Usually Newlines, i.e. paragraphs but you can be weird and do it based on sentence or token count as well. The latter option will more than likely always fuck up words.

Anyway, on to the play-by-play: On pure defaults All text sources are set to insert based on newlines. The other values are as follows:

Memory:

Order: 800 (Highest, i.e. inserted as the very first)

Position: 0

Author's Note:

Order: -400 (Lowest, i.e. inserted as the very last)

Position: -4 (4 units (Newlines) above the end of the prior context stage)

Lorebook:

Order: 400 (Second)

Position: -1 (Below memory)

Story:

Order: 0 (Second to last)

Position: -1 (Below Memory and any default LBs)

What system any other service uses may be similar, though that isn't clear. Either way you always end up with a unified blurb of text.

Using the sample above we have a context that looks as follows: Now, this reads a bit weird if you were to find this in a book you tried to read, right? Well, more or less the same issue applies to the AI when it tries to make sense of this now. Despite being called Memory and Author's Note or whatever the hell else, these extra locales for you to insert text just boil down to regular text within what the AI receives. The names are a bit misleading in that regard.

With the base advice of writing your story the way you want your outputs to look, the most general consensus for optimizing the outputs you get from any AI is to ensure there is a kind of flow here as well. In other words, your current context should flow about as well as your "raw" story does.

For example, if you were to write a lengthy author's note in a sort of instructive and present tense while your story is past tense you may end up with muddy outputs dancing between tenses.