Core operations
Add a memory
Store a text or a chat thread about one of your users. Korely saves it at once, then extracts facts from it.
add() saves a memory and
replies with status processing. A language model then reads
the text and extracts facts. For example: subject
Northwind Hosting, predicate costs, object 50 euro
per month. This usually takes about ten seconds.
Quick start
You need three things:
- Python 3.9 or later.
- The Python SDK:
pip install korely-memory. - An API key that starts with
kor_live_. Get a free one in the Quickstart.
The code writes one memory. After a wait, it reads the memory's status and its facts. With a wrong key, add() fails with 401 invalid_key.
from korely_memory import Korelyimport timekorely = Korely(api_key="kor_live_...")memory = korely.add("Northwind Hosting costs 50 euro per month since the June upgrade.", user_id="customer-4812")time.sleep(10) # the extraction usually takes about ten secondsprint(korely.get(memory.id).status) # readyfor fact in korely.get_facts(entity="Northwind Hosting", user_id="customer-4812"): print(fact.predicate, fact.object) # costs 50 euro per month entity is the subject of the facts you ask for: here, the
company (more in the Glossary). You see ready and one fact: predicate
costs, object 50 euro per month. If the status is
still processing, wait, then run the print(korely.get(...).status) line and the loop again. If it
is ready and the list is empty, the memory finished with no
facts. If it is error, the extraction failed for good: call add() again, and see status under
Response.
Node.js and cURL, and every parameter: the reference.
Call add() after any turn where the user reveals something
worth remembering: a preference, a decision, a fact about themselves.
What happens after an add
flowchart LR
A([add content]) --> B[Store memory]
B --> C[Embed memory]
C --> I([Reply: status processing])
C -.-> E[Extract facts]
E --> N[Entities: subjects, named objects]
E --> F{Contradiction?}
F -- yes --> G[Supersede old fact]
F -- no --> H[Record new fact]
The subject of each fact is an entity, and so is an object that names
something (a company, a person, a city) rather than a value such as
50 euro per month. With entities you retrieve everything known
about one person, company or product:
get_facts(entity="Northwind Hosting")
(more in The graph).
Korely then picks earlier facts that might conflict with each new fact, and a model judges them (contradiction). If the price goes from 50 to 80 euro, the 50 euro fact is superseded (closed).
If it takes longer
If the service restarts while a memory is being written, nothing is lost. The next process writes the memory again, which costs one more model call. Tests prove it: a real process was killed while it held a memory. It has not been measured on a deploy of the Cloud yet.
In a few cases a memory waits 15 minutes before it is written. One is a Self-hosted server set to extract before it answers (see the Self-hosted notes); the changelog lists the others under 1.0.22.
The most common errors
Every error carries a code: branch on it. Nothing is stored when a write fails.
401 invalid_key: the key is missing, malformed or revoked. Send a valid key in theAuthorizationheader.422 identity_required: the write names neitheruser_idnoragent_id. Add one of the two (why and how, in the Quickstart).422 invalid_request: a field failed validation. Themessagenames the field.429 quota_exceeded: your account used its monthly writes.resets_atsays when they come back.429 rate_limit_exceeded: too many requests. Wait the seconds in theRetry-Afterheader.
All errors, with their conditions: the reference.
Next
- Add a memory: reference: every parameter, response field and error, the write quota, and the Self-hosted notes.
- Get context: current facts plus relevant memories in one block.