A language model only knows the text you send it. When a chat gets long, you can't send all of it, so you have to pick. RALC picks the messages that belong together, so the model gets the whole story inside a small token budget.
The model can't tell that hosting ever changed.
The model can answer: Heroku first, then AWS.
Two messages about the same thing look alike, so ordinary selection treats them as duplicates and keeps only one. RALC knows they are connected (one replaced the other), so it keeps both.
RALC sits between your program and the model. It never rewrites the question and never touches the model's answer. Its only job is choosing which past messages to include.
Each message becomes a point in a graph, saved in a local SQLite file.
An extractor reads each message for names and decisions, and RALC draws links between messages.
The free built-in extractor uses simple patterns. Gemma 4 can do this job instead and understands things a pattern can't, like one decision replacing another.
When a question arrives, a small embedding model on your machine finds the messages most similar to it.
From those starting points, RALC walks the links to related messages, even ones that share no words with the question.
Each candidate gets a score combining similarity to the question, how strongly it's linked, shared names, and how recent it is.
RALC adds the best messages until the token budget is used. It skips near-duplicates, but not linked messages, since those complete each other. It stops early when nothing useful is left, so it can use fewer tokens than allowed.
The chosen messages come back in conversation order. You add the unchanged question and send it to any model.
TEMPORALLY_FOLLOWSThis message came right after that one.ANSWERSThis reply answers that question.MENTIONSBoth messages talk about the same named thing.UPDATESThis decision replaces an earlier one. Gemma finds these; the pattern extractor found none in our test.Remember what was decided months ago and why it changed.
Connect a bug, its cause, the file, and the fix across hours of work.
Models with small context windows, or a tight token budget, get only what matters.
Keep the problem, the workaround, and the final fix together.
“What did we agree on, and why?” across reversed and re-made decisions.
Looking up one fact in documentation, or short chats where everything fits anyway. Ordinary search does as well there.
Requires Python 3.10 or newer.
git clone https://github.com/Vivek0x6b/Ralc.git cd Ralc pip install -e ".[embed,tokens]" # add ,gemma to use Gemma
The storage file keeps the graph between runs.
from ralc import ContextManager ralc = ContextManager(storage="memory.db")
Add one line wherever your program sends or receives a message. RALC links each new message to the history automatically.
ralc.add_message(role="user", content=user_message) ralc.add_message(role="assistant", content=reply) ralc.save()
Pick a token budget that fits your model and your costs.
result = ralc.retrieve(query=question, token_budget=1000) result.token_count # tokens actually used (never above the budget) result.nodes # the chosen messages, in conversation order result.metadata # what happened: candidates, nodes explored, skips
The question goes in unchanged. Use whichever model you like.
prompt = result.to_text() + "\n\n" + question # send prompt to Gemma, GPT, Claude, Llama, a local Ollama model...
Set GEMINI_API_KEY in your environment, then pass the Gemma extractor. Without it, RALC uses the free pattern extractor.
from ralc.extraction import GemmaExtractor
ralc = ContextManager(storage="memory.db",
extractor=GemmaExtractor(model="gemma-4-26b-a4b-it"))Your chat history stays on your machine. Only the messages RALC selects are sent to the model, and with Gemma enabled, each message is sent once to Gemma to find links.
Share of multi-message questions where every needed message was selected. Same system, same number of candidates, relationships on vs off.
“This replaced that” links in the 234-message test conversation.
Complete answers on multi-message questions at a 1,000-token budget (5 of 6 → 6 of 6). The one recovered question is the hosting example above.
Code, tests, and every benchmark result: github.com/Vivek0x6b/Ralc