DEV Community

Cover image for Making Local AI Memory Readable
Alain Chan
Alain Chan

Posted on

Making Local AI Memory Readable

SQLite

http://github.com/Flow-Research/local-first-AI/pull/10

If you're an online business, imagine saying to your local AI, “Remember, we selected SQLite for offline storage.” Stores decision correctly, closes database and does not say anything else. One week later you ask him what he remembers. Silence.
If it doesn't display to you what it remembers, it's not a memory, it's a mysterious SQLite cave with commitment problems.
This is why it is important to have a read layer for local context. Data can be stored in a system by writing data. When read back it is evident that information still exists, in the right structure, and can be interpreted by people or other parts of an application.

Local-first AI shouldn't require users to put their faith in a black box. The users should be able to view the content that was stored, the source and time of the content.

Empty database is not an error! It's a legit state, particularly if it's an application that is new. Read functions must return an empty list if they fail to find any data or if they imagine data. This allows caller to have a definite answer: memory store works, but it doesn't show anything yet. An appropriate message, like “No context saved yet.” can then be provided by Interface.

Likewise same treatment for missing IDs. Records can disappear, links may be out of date or users might ask for an ID that never existed. None is returned to indicate that "Context item not found". A collision would make a bad day even worse. Forgetting should be dealt with gracefully with good memory.

missing data

The more you add to the list, the more noise there will be in the memory. The user notes, project notes, device log, learning record, decisions about configuration and context of conversation are separated by filtering on context_type. When users question the decisions being taken, AI should not conduct a random search of their device's logs, such as trying to find one receipt in the logs of all the kitchen drawers.

Most importantly, recent context is important; new information is more relevant than old information. When users need to check out the latest, it is beneficial to display the most recent items first. It also provides a reasonable initial point for subsequent search and prompt building systems. Sorting by created_at is a standard way to ensure the ordering of results is predictable, as determined by ID as tie-breaker.

Readable memory requires more than title/content. metadata describes the context of each record, source provides information about the origin of the data, tags allow to group related ideas together, importance indicates which memories might benefit from further investigation, created_at and updated_at indicate age or freshness of information. These fields don't ensure the truth but they provide the user with evidence to help make the decision whether or not to trust the memory.

layer

Read layer also will serve as a basis for subsequent AI features. Search requires accurate documentation to examine. There should be a structure for context to format prompt preparation. Selected memories with sufficient metadata are required to make inferences. Each subsequent component is more readily developed and tested if the read layer returns complete predictable dictionaries.

Local AI memory can come in handy only when it's in sight. System remembers it in Storage. Humans can check memory by reading. Search, prompts, and inference can then be used to go beyond the generic SQLite cave.

Top comments (0)