Korely

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 five.

  • 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.
  • closed_known_at: the date Korely learned that a fact had ended.

Quick example

You need Python 3.9 or later and pip install korely-memory. Then get a free API key in the Quickstart and run export KORELY_API_KEY=kor_live_.... The command prints nothing; Korely() reads the key from the environment. A wrong key makes the first write fail with 401.

The code writes two plans for the end user customer-4812. Here the customer is the fact's subject and also the end user (user_id); in general they can differ. It writes Starter from 1 May 2026, then Business from 1 June 2026, and reads both back.

from korely_memory import Korely
korely = Korely() # reads KORELY_API_KEY from the environment
korely.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 None
Starter plan 2026-05-01T00:00:00+00:00 2026-06-01T00:00:00+00:00
  • First line. new.invalidated holds the id of the Starter plan fact: the judge read the new plan as a replacement.
  • Second line. The Business plan is current: invalid_at is 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

At each write, Korely compares the new fact with the older facts of the same end user. If it finds a contradiction, it closes the old fact with a date instead of deleting it. It takes two steps.

  1. Find possible conflicts. Korely looks at the open facts of the same end user, whichever agent wrote them. It 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, because "the user" and "Maria" can be one person. This check runs only for a memory written with a user_id, and only between facts extracted from memories (text you saved with add());
    • up to 10 facts nearest in meaning, found as in a search, only for a memory written with a user_id.
    Not every check runs for every fact: the table below says which do.
  2. 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. If the new fact has no date, that is the moment of the write.

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.

Which facts the judge sees

It depends on how the new fact came in.

How the new fact came inEarlier facts the judge compares it with
You write it yourself: POST /v1/facts, the Python SDK's add_fact_triple, or a correction (correct_fact) that sets a subject. Only earlier facts with the same subject, and facts that link the same two things the other way round. A fact about one deploy cannot close a fact about another deploy.
Extracted from a memory (saved with add()) that has a user_id. All five checks above. An earlier fact that you wrote yourself counts only if it has the same subject, or links the same two things the other way round.
Extracted from a memory with no user_id: a team's shared memory, an agent's own notes, or no ids at all. Only facts of the same entity: 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.

Two spellings of one thing

  • "Cloud" and "Korely Cloud" are two subjects. A new value of one does not close the old value of the other.
  • To make them one subject, declare the name (POST /admin/aliases) in the namespace of the agent that writes it, with its agent_id.
  • "Maria" and the end user's user_id count as one subject for a fact you write yourself only after you declare the name. For a memory saved with no 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 with include_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).

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 sorts them by event time. If that ties, it uses the moment the memory was received. If that ties too, it uses 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 together in one database transaction (one all-or-nothing database write) share the received moment, so 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 reads valid_from and invalid_at.
  • known_as_of: what Korely knew on a date. It reads created_at, when Korely learned the fact, and closed_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 note "customer-4812 lives in Turin" with add(), passing the date of the move in the timestamp parameter: timestamp="2026-09-01".

The dates here are a story. The calls show how you read each clock once both facts exist:

korely.add("customer-4812 lives in Turin", user_id="customer-4812", timestamp="2026-09-01")
korely.get_facts(user_id="customer-4812", as_of="2026-09-20") # Turin
korely.get_facts(user_id="customer-4812", known_as_of="2026-09-20") # Milan

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.

Terminal window
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_fact is for a current fact with a wrong value: the new value counts from now on, the old fact is closed.
  • forget_fact(fact_id) closes a fact with no replacement; its optional at is 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 (one not forgotten) 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 closed by hand (forgotten, corrected or written as a past fact with POST /v1/facts) is never given back. A fact that a memory said is over stays closed while that memory is live and still says it (since 1.0.14). To let end users read, correct and forget their own facts, see Human in the loop.

Related