October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

Building Multi-Tier AI Agent Memory with TypeScript and SQLite-vec

A practical architecture for persistent agent memory in TypeScript: separate episodes, distilled facts, and procedures, then retrieve them with vector, lexical, and structured searches.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build persistent memory for a TypeScript agent by giving different kinds of information different jobs: keep interaction history as episodic memory, distill durable facts into semantic memory, and store reusable condition/action rules as procedural memory. A retrieval step can then combine recent events, vector similarity, structured rule lookups, and—when exact wording matters—SQLite FTS5. This is an architecture to validate against your own workload, not a benchmark-backed promise of better recall or speed.

Why an agent needs more than a conversation log

A conversation log preserves what happened, but it is not automatically a useful memory system. An agent may need to recall a recent decision, retrieve a fact expressed in different words, or apply a recurring procedure. Those are different retrieval problems, so storing everything as undifferentiated text makes selection and lifecycle harder.

As an Amazon Associate I earn from qualifying purchases.

A multi-tier design separates the original interaction from information distilled out of it. Keep a traceable link from each distilled record back to its source episode. That provenance gives the agent or operator a way to inspect context when a fact is corrected, contradicted, or no longer reliable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a role for each memory tier

Tier What it stores How to retrieve it Lifecycle decision
Episodic Interaction turns and event metadata, such as session identity, order or timestamp, and token count. Filter by session and time; select recent episodes that have not yet been compacted. Decide retention, archival, and when an episode can be considered for compaction.
Semantic Distilled facts or knowledge, with content, metadata, source-episode references, and access tracking. Associate embeddings with stable record identifiers. Nearest-vector search; optionally combine with lexical search for literal terms. Define how to update, correct, re-embed, expire, and delete a fact and its associated index rows.
Procedural Explicit condition/action rules, with confidence and links to the episodes that support them. Match conditions or metadata relevant to the current task. Decide how corrections, contradictions, expiry, and confidence changes affect a rule.

Procedural memories should inform an agent, not become unquestionable instructions. Keep the supporting episode links and make the rule’s status inspectable so a stale or conflicting procedure can be reviewed rather than silently applied.

Model the records and their relationships

Keep searchable text and ordinary metadata in relational tables, and associate semantic records with the vector extension’s storage using stable IDs. The SitePoint Team tutorial describes a vec0 virtual table for vectors alongside regular content tables. Treat these as related parts of one record, not independent stores that can drift apart.

  • Episodes: assign a stable ID, session identifier, order or timestamp, content, and any metadata needed to select recent uncompacted turns.
  • Semantic records: assign a stable ID, store the distilled content and provenance references, and track access if it will inform retention or eviction.
  • Procedures: store a condition and action as structured fields, along with confidence and provenance, rather than relying on a free-text blob alone.
  • Embeddings: record which model and configuration produced each vector. Choose a vector dimension that matches that model’s output and plan how to re-embed records when the model or configuration changes.

The tutorial reports 384 dimensions for all-MiniLM-L6-v2 and a default output dimension of 1536 for text-embedding-3-small. These are figures stated by that September 25, 2026 tutorial, not independently verified here; check the current model documentation before treating either as a configuration constant. A dimension mismatch is a schema/configuration error, not a retrieval-quality tuning issue.

Make writes and deletes consistent

A single memory change may touch content, a vector row, and a lexical index. Use stable identifiers and design the write path so a failure cannot leave a content row without its vector, an orphaned vector, or an out-of-date full-text entry. Apply the same care to corrections and deletions as to inserts.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Record the episode: append the turn with its session and ordering metadata so it can be retrieved before compaction.
  2. Distill deliberately: when a lifecycle rule makes an episode eligible, extract candidate facts or procedures and retain references to the supporting episode or episodes.
  3. Write the related records together: coordinate content and vector updates in a transaction supported by the chosen driver and extension. If FTS5 is present, include its synchronization path too.
  4. Handle errors and retries: test what happens if embedding generation, an insert, or a delete fails midway. A retry should not create duplicate memories or conceal stale index rows.

SQLite’s FTS5 documentation makes clear that an external-content full-text table is not automatically kept synchronized with its content table by the application: the application remains responsible. Triggers are one documented way to propagate changes. The separate sqlite-memory project documents SAVEPOINT-wrapped synchronization as one implementation pattern; that is an example, not a guarantee that every driver and extension combination behaves identically.

Retrieve memories in a query-shaped way

Do not make vector search answer every question. Similarity can help find a paraphrased fact, while literal matching is important for names, identifiers, and exact phrases. FTS5 is SQLite’s full-text search module; it complements rather than replaces vector retrieval.

  1. Load recent context: select relevant recent episodes by session or time, excluding episodes already compacted if that is your policy.
  2. Search semantic memory: embed the query using the compatible model/configuration and retrieve nearest neighbors from the vector index.
  3. Match literal terms when needed: search FTS5 for exact names, identifiers, or wording that a semantic match could miss.
  4. Find applicable procedures: match structured conditions or metadata against the current task; include confidence and provenance in the result available to the agent.
  5. Combine and budget: deduplicate overlapping records, choose a ranking policy, and limit the assembled memories to the context budget available to the model.

Hybrid retrieval is a design choice, not proof that a particular weighting is best. Evaluate vector-only, lexical-only, and combined results on representative queries: exact names, paraphrases, recent events, and stale or contradictory facts. Tune ranking and weighting only after observing which results help your agent’s actual tasks.

Connect retrieval to the agent’s memory lifecycle

A practical agent loop has four distinct jobs: recall, apply relevant rules, generate a response, and decide whether the interaction should later be compacted into durable memory. Keeping compaction out of the immediate recall path helps preserve the distinction between raw evidence and derived knowledge.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Recall: gather the recent episodes and relevant semantic or procedural records before generating a response.
  • Apply carefully: present procedures as candidate guidance with their confidence and provenance, especially when memories conflict.
  • Respond: use the selected context, not the entire database, to construct the model input.
  • Compact by policy: define when an episode becomes eligible, what qualifies as a durable fact or reusable rule, and how the original source remains traceable.

Specify how a correction to an episode affects derived memories. Depending on the application, that may mean updating a semantic record, lowering a procedure’s confidence, marking a memory superseded, or deleting related rows. The design should make this propagation explicit; the tier architecture alone does not decide it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the vector and lexical components deliberately

Choice What it provides What to verify
sqlite-vec The SitePoint tutorial’s approach uses a vec0 virtual table associated with regular metadata/content tables. Confirm the installed extension’s API, vector dimensions, loading behavior, and update/delete handling for your environment.
SQLite-Vector A distinct project whose documentation describes vectors in BLOB columns in ordinary SQLite tables and its own scanning/quantization approaches. It is not a drop-in name for sqlite-vec; check its own interface and claims before choosing it.
FTS5 SQLite full-text indexing for lexical matches, such as literal terms and identifiers. Keep external-content indexes synchronized with source rows and validate how the combined ranker behaves on your query set.

Do not substitute SQLite-Vector for sqlite-vec while following instructions written for vec0: the projects describe different storage and search approaches. Likewise, FTS5’s internal index maintenance does not establish an application-level latency guarantee.

Validate the TypeScript and SQLite deployment

The tutorial’s named stack is TypeScript, better-sqlite3, and sqlite-vec, with runtime extension loading and WAL enabled. Compatibility and packaging depend on the actual Node.js version, driver, extension release, operating system and architecture, extension-loading configuration, and distribution format. The available source does not establish a compatibility matrix, so test the exact combination you plan to ship rather than assuming a command sequence will work everywhere.

  • Confirm that the extension can be loaded in the target runtime and packaged in the intended application format.
  • Check that WAL and the chosen transaction approach work as expected with the selected driver and deployment.
  • Exercise insert, update, correction, retry, and delete paths across content, vector, and lexical data.
  • Version the embedding model/configuration and test a deliberate re-embedding or migration path.
  • Measure recall quality, latency, storage, embedding-generation cost, and operational complexity on representative data before setting expectations.

No independent measurements establish performance or recall gains for this exact architecture. The separate SQLite-Vector project’s benchmark claims are project-reported and hardware-specific; they should not be presented as results for a TypeScript agent using sqlite-vec.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When this design fits—and when it needs another layer

A local SQLite design is a reasonable fit when one application needs an embedded store and can manage its own extension packaging and memory lifecycle. If multiple machines or agents must share and synchronize state, that is a separate deployment requirement: assess coordination, conflict handling, and operational needs rather than assuming a local database will provide them. The sqlite-memory project documents offline-first synchronization as one option, but it is separate from sqlite-vec and is not required by this design.

The architecture’s value comes from making distinctions explicit: raw episodes remain evidence, semantic records capture reusable knowledge, procedural records describe candidate actions, and retrieval combines the methods appropriate to the query. Whether those choices improve a particular agent must be established with that agent’s data and tasks.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.