How Smritea turns text into memories: facts, skips and duplicates

How Smritea turns text into memories: facts, skips and duplicates

by Tushar Dwivedi
Ask AI about this page

Fact extraction is the step that turns the text you send to add into separate memories. A memory is one stored fact. How many memories a call creates depends on the storage engine you chose for the app.

Two storage engines, two results

You pick the storage engine when you create the app. You cannot change it after the app has memories.

Quick Search appDeep Search app
Splits text into separate factsNoYes
Memories per add callOne, holding your text as sentZero or more, one per fact
Skips text with nothing to rememberNoYes
Builds entities and relationshipsNoYes

A Quick Search app runs no language model on add. It stores your text as sent, which keeps cost low for high-volume apps.

The four extraction steps

A Deep Search app runs the text through four steps.

  1. A language model splits the text into short, separate facts. A fact can carry a date, tags and an importance score.
  2. Smritea compares each fact with the memories you already have. Each fact gets one verdict: new, same or update.
  3. New facts become new memories. Smritea skips a same fact. An update fact merges into the existing memory.
  4. In the background, Smritea finds people, places and other entities in the new memories and links them in a knowledge graph.

A call can succeed and store nothing

Three outcomes are normal, and none is an error.

CaseWhat you see
The text holds nothing worth keeping, such as a greetingmemories is empty and explicit_skip is true
Every fact matches a memory you already havememories is empty and skipped_count is above zero
A fact refines an existing memoryThe merged memory is in memories and updated_count is above zero

Each call still costs one memory credit.

See it in code

This sample sends the same sentence twice to a Deep Search app. It prints the counts that the result reports.

import os

from smritea import MemoryScope, SmriteaClient, SmriteaError

client = SmriteaClient(
    api_key=os.environ["SMRITEA_API_KEY"],
    app_id=os.environ["SMRITEA_APP_ID"],
)
alice = MemoryScope(actor_id="alice", actor_type="user")
text = "Alice is vegetarian and loves hiking"

try:
    for attempt in (1, 2):
        result = client.add(text, scope=alice)
        print(
            attempt,
            len(result.memories),
            result.facts_extracted,
            result.skipped_count,
        )
except SmriteaError as e:
    print(e.http_status, e.code, e.request_id)

Expect the first call to report new memories. Expect the second call to report skipped facts, because Smritea already holds them. The exact counts depend on how the language model splits the sentence.

Learn more

The docs page How Smritea stores memory lists every field of the add result. The limits page explains what each call costs.

Related posts

Comments