Concepts
Temporal facts
Every fact has two dates: when it became true and when it stopped. When a new fact contradicts an old one, Korely closes the old one: it sets an end date on it and keeps it.
Korely turns what your agents save
into facts. A fact has three parts: a
subject, a relation (called predicate in the API) and an
object, such as customer-4812 / subscribes_to / Business plan.
Terms
The Glossary defines the shared words. This page adds four.
- Judge: a language model inside Korely that checks each write for contradictions with older facts.
valid_from: the date a fact became true.invalid_at: the date it stopped; empty while it is true. The two make the valid time.known_as_of: a read parameter for what Korely knew on a date.
Quick example
You need Python 3.9 or later and pip install korely-memory.
Get a key at
Get a free API key (Quickstart), then run
export KORELY_API_KEY=kor_live_....
The code writes two plans for the end user customer-4812. The customer is both the fact's subject and
the end user it belongs to (user_id); they can differ. It writes Starter from 1 May
2026, then Business from 1 June 2026, and reads both back.
from korely_memory import Korelykorely = Korely() # reads KORELY_API_KEY from the environmentkorely.add_fact_triple("customer-4812", "subscribes_to", "Starter plan", user_id="customer-4812", valid_from="2026-05-01")new = korely.add_fact_triple("customer-4812", "subscribes_to", "Business plan", user_id="customer-4812", valid_from="2026-06-01")print(new.invalidated)for f in korely.get_facts(user_id="customer-4812", include_invalidated=True): print(f.object, f.valid_from, f.invalid_at)You see this (ids are longer):
['fct_ad36...']Business plan 2026-06-01T00:00:00+00:00 NoneStarter plan 2026-05-01T00:00:00+00:00 2026-06-01T00:00:00+00:00- First line.
new.invalidatedholds the id of the Starter plan fact: the judge read the new plan as a replacement. - Second line. The Business plan is current:
invalid_atis empty. - Third line. The Starter plan closes on 2026-06-01, when the Business plan began.
Without include_invalidated=True, you get only the Business
plan. More filters: Get facts, the API reference.
If invalidated is empty, the judge saw no contradiction: close the old fact yourself with
forget_fact. If a write fails with 503
model_unavailable (the model could not be reached), nothing was
written: try again.
To run it again, use a new id in place of customer-4812.
How a new fact closes an old one
Korely checks whether a new fact contradicts an old one. If it finds a contradiction, it closes the old fact with a date instead of deleting it.
At each write, Korely takes two steps.
- Find possible conflicts. Korely looks at the
open facts of the same end user,
whichever agent wrote them, and keeps the ones that could clash with the new fact:
- the same subject and relation: costs 40 and costs 50;
- the same subject and object with another relation: likes tea and dislikes tea;
- the same two things with the relation the other way round: Maria manages Luca and Luca manages Maria;
- the same relation with another subject, only for a memory written with a
user_id, and only between facts read from memories: "the user" and "Maria" can be one person; - up to 10 facts nearest in meaning, found as in a search, only for a memory written with a
user_id.
- A fact you write yourself (POST /v1/facts, the Python SDK's
add_fact_triple, or a correction that gives its subject): only the earlier facts with the same subject, and the facts that link the same two things the other way round. A fact about one deploy cannot close a fact about another deploy. - A fact read from a memory with a
user_id: all five checks above, except that a fact you wrote yourself is compared with it only when both have the same subject, or link the same two things the other way round. - A fact read from a memory with no
user_id(a team's shared memory, an agent's own notes, or no ids at all): only the facts of the same entity, meaning facts whose subject is the new fact's subject, whose object is its subject, or whose subject is its object. A fact of another entity is not shown to the judge only because it is near in meaning.
POST /admin/aliases) in the namespace of the agent that writes it, with itsagent_id. "Maria" and the end user'suser_idcount as one subject for a fact you write yourself only after you declare the name. Without ids, the first person is stored as the subject "user". A declared name belongs to one agent, and every one counts against the account's 1,000 declared names. Declaring a name later does not check again the facts already written. Facts already closed stay as they are. A fact closed wrongly stays readable withinclude_invalidated=true; write it again with POST /v1/facts to make it true again. How the rules of each release changed, and what was measured, is in the changelog (1.0.12, 1.0.13 and 1.0.21, which also covers 1.0.19 and 1.0.20). - Judge. The judge reads the new fact next to these candidates and decides which ones it contradicts. Two plans for one subscription cannot both be true. "Likes coffee" and "likes tea" can.
The old fact ends when the new one begins (the moment of the write, if it has no date).
The judge can be wrong. It can miss a contradiction or
close a wrong fact. It may not read a change told in the past
tense, such as "Tom moved to Munich", as a replacement, so the earlier
fact can stay open. On 15 November 2026 we measured the eu region on a development build of Korely, not on a release. After a change told in the past tense, the model that writes the facts left the old fact open in at least 8 of 10 cases. Version 1.0.27 itself was not measured. Read what was measured. Check with get_facts and fix it with
correct_fact or forget_fact.
Where valid_from comes from
add() saves free text (a memory) and Korely extracts its facts.
add_fact_triple, used above, saves one fact already in its
three parts.
Korely uses the first that exists: the date you pass
(valid_from in add_fact_triple,
timestamp in add()); a date with a year in the
text ("Since June 2026" becomes 2026-06-01); the moment of the write.
When several memories carry the same event time, for example dates with no hour, Korely takes them in this order: the event time, then the moment its store received each one, then the id. So "moved to Paris" saved after "lives in Rome" is judged after it, and the newer fact stays open. The limit: memories saved in the same database transaction tie on the received moment, and the id decides. This holds since 1.0.0.
Add a memory, from text to facts, Write a fact, the API reference.
Read the past: as_of and known_as_of
as_of: what was true on a date, as Korely knows it today. It readsvalid_fromandinvalid_at.known_as_of: what Korely knew on a date. It readscreated_at, when Korely learned the fact, andclosed_known_at, when Korely learned that it had ended.
The answers differ when a change is told late. Korely knows
customer-4812 lives in Milan. On 5 October an agent learns of a move to
Turin on 1 September. It saves the present-tense note "customer-4812 lives in Turin"
with add(), passing the date of the move in the
timestamp parameter: timestamp="2026-09-01".
The Turin fact has created_at 5 October, when Korely learned
it. The Milan fact ends on 1 September (invalid_at), but its
closed_known_at is 5 October: Korely learned of the end only then.
as_of="2026-09-20"returns Turin: on 20 September the customer already lived there.known_as_of="2026-09-20"returns Milan: on 20 September Korely did not know of the move yet.
as_of on the Quick example
as_of returns the facts true on that date, each with the end
date it has today. A date without a time means midnight UTC.
Run this after the Quick example, in the same shell, for what was true on 15 May.
curl -G https://api.korely.ai/v1/facts \ -H "Authorization: Bearer $KORELY_API_KEY" \ --data-urlencode "user_id=customer-4812" \ --data-urlencode "as_of=2026-05-15"# 200 OK (some fields left out)# {"facts": [{"object": "Starter plan",# "valid_from": "2026-05-01T00:00:00+00:00",# "invalid_at": "2026-06-01T00:00:00+00:00"}], "total": 1}The Starter plan was true on 15 May, so it returns with its end date, 1 June.
Correct or forget a fact
-
correct_factis for a current fact with a wrong value: the new value counts from now on, the old fact is closed. -
forget_factcloses a fact with no replacement; its optionalatis the date it stopped being true. -
delete_all(user_id=...)erases every memory and fact of one end user, in the project of your API key. Database backups made before the call still hold the data.
Deleting the memory that closed a fact can give the fact back, as a new open fact, when a live memory still says it and no other value is open (since 1.0.2; Delete a memory has the rules and the limits). A fact you said is over by hand (forgotten, corrected or posted in the past tense) is never given back, and a fact that a memory said is over stays closed while that memory is live and still says it (since 1.0.14). Human in the loop: how end users read, correct and forget their facts.
Related
- The knowledge graph: how facts link names.
- The memory model: how memories and facts fit together.
- List events: whether a write has finished extracting its facts.