← All posts

Why SQLite belongs in your AI data pipeline

SQLite fits AI engineering better than many teams expect. A small local database, used with discipline, gives you repeatable ingestion, versioned model output, and queryable workflow state for retrieval and evaluation work.

SQLite keeps showing up in AI and data tooling for a reason. It is small, fast, easy to ship, and hard to beat for local pipelines. If you build agents, retrieval layers, or evaluation jobs in Go or Python, you will spend time moving semi-structured data into a form you can query with confidence.

Simon Willison notes the release of sqlite-utils 4.2.2. The interesting part for practitioners is not the release itself. It is the wider pattern: mature local data tools keep getting better, and they fit AI systems well. The more your workflow depends on repeatable ingestion, predictable schema changes, and portable datasets, the more SQLite starts to look like infrastructure, not a convenience.

For teams building AI features, this matters because a lot of failure hides in data preparation. You scrape pages, ingest logs, parse model outputs, attach embeddings, and then need to answer simple questions fast. Which rows failed parsing. Which prompts produced malformed JSON. Which chunking strategy produced the best hit rate. A local relational store gives you a disciplined place to ask those questions.

Use SQLite as the control plane for AI data work

A common mistake is to treat local AI workflows as a pile of files. JSON here, CSV there, embeddings in a side folder, evaluation output in another script’s temp directory. This works for a day. Then it becomes expensive.

SQLite gives you a control plane for the workflow.

You track:

  • source documents
  • fetch status and HTTP metadata
  • parse results
  • chunk boundaries
  • embedding model version
  • prompt version
  • evaluation outcomes
  • retry counts
  • operator notes

You do not need a large database server for this. In many cases, you need one file with a schema you understand.

A practical pattern looks like this:

create table documents (
  id integer primary key,
  source_url text unique,
  fetched_at text,
  http_status integer,
  content_sha256 text,
  parse_ok integer,
  parser_version text
);

create table chunks (
  id integer primary key,
  document_id integer not null,
  chunk_index integer not null,
  content text not null,
  token_count integer,
  foreign key(document_id) references documents(id)
);

create table runs (
  id integer primary key,
  task text not null,
  model text,
  prompt_version text,
  started_at text,
  finished_at text,
  success integer
);

This structure is plain, but it solves real problems. You stop guessing which script generated which output. You gain reproducibility. You gain a way to compare runs over time.

Where teams go wrong is skipping the metadata. They keep the content but not the conditions under which the content was produced. Then when output quality drops after a model change, there is no audit trail.

Inspect schema drift before it hurts retrieval and evals

AI pipelines drift fast. A parser changes. A model starts emitting slightly different JSON. A field which used to be optional becomes required. If your storage layer does not absorb this cleanly, bugs spread into retrieval and evaluation.

SQLite helps because it makes schema inspection cheap. Tools around it make migrations and ad hoc checks easier.

What to inspect:

  • Columns with mixed meanings, such as status holding both HTTP and parser states.
  • JSON blobs that should have been normalized after the format stabilized.
  • Duplicate rows caused by missing uniqueness constraints.
  • Nullable fields that your application now assumes are present.
  • Version fields missing from prompts, parsers, or embedding jobs.

A few useful checks:

select parser_version, count(*)
from documents
group by parser_version
order by count(*) desc;

select source_url, count(*)
from documents
group by source_url
having count(*) > 1;

select id
from runs
where finished_at is null and success = 1;

These are boring queries. That is the point. Reliable AI systems depend on boring checks.

Another common mistake is treating JSON support inside SQLite as a full substitute for schema design. JSON columns are helpful for raw model output, trace payloads, or temporary capture. They become a problem when core application logic depends on deep JSON paths spread across many queries. At that point, your data model is telling you to promote stable fields into first-class columns.

Store model output twice, raw and normalized

Model output is messy. Even with structured output modes, you will hit truncation, field drift, and formatting errors. If you store only the parsed form, you lose forensic value. If you store only the raw form, analytics become painful.

Store both.

One table design:

create table extraction_results (
  id integer primary key,
  run_id integer not null,
  document_id integer not null,
  raw_output text not null,
  normalized_json text,
  parse_error text,
  schema_version text not null,
  created_at text not null,
  foreign key(run_id) references runs(id),
  foreign key(document_id) references documents(id)
);

This gives you three operational benefits.

First, you retain the exact model response for debugging. If a prompt tweak creates malformed output, you have the evidence.

Second, you keep normalized data queryable. You can compare field completion rates, error rates, and downstream task success.

Third, you create a path for reprocessing. When your normalizer improves, you re-run it against stored raw output instead of paying the model again.

This matters in cost control and in incident response. If a bad deploy changes output shape for six hours, you want a recovery path.

Where it goes wrong is poor versioning. Teams store raw output and parsed JSON, but they do not record the schema version, prompt version, or model ID. Then they have the data but not the context.

Index for your real query patterns, not your ideal ones

SQLite performs well, but only if you respect access patterns. AI projects often start with broad exploration and end with repetitive operational queries. Your indexing strategy should follow the latter.

Good candidates for indexes in local AI systems include:

  • lookup by source_url
  • joins on document_id and run_id
  • filtering by created_at or fetched_at
  • selection by parse_ok, success, or retry state
  • deduplication by content hash

Examples:

create unique index idx_documents_source_url on documents(source_url);
create index idx_documents_content_sha256 on documents(content_sha256);
create index idx_chunks_document_id on chunks(document_id);
create index idx_runs_task_started_at on runs(task, started_at);
create index idx_extraction_results_run_id on extraction_results(run_id);

Do not index everything. Every extra index adds write cost and migration complexity. Start from the questions your system asks every day.

For retrieval work, also separate two concerns which teams often mix together.

One is vector search or nearest-neighbor retrieval. The other is workflow state and provenance.

Even if you use a vector extension or a separate vector store, SQLite still works well as the source of truth for document metadata, chunk lineage, prompt history, and eval results. This split tends to age better than forcing one layer to do every job.

Keep the database portable across scripts, laptops, and CI

One reason SQLite fits AI engineering is portability. A database file moves cleanly between a developer machine, a batch worker, and CI artifacts. This supports reproducibility if you keep a few rules.

Use deterministic migrations. Record schema versions. Avoid hidden state in notebooks. Export repeatable seed datasets for tests.

A practical checklist:

  • Keep schema creation in versioned files.
  • Record tool and model versions in tables, not in comments.
  • Add constraints early, unique keys, foreign keys, and required fields.
  • Run integrity checks in CI.
  • Snapshot small fixture databases for regression tests.

Useful built-in checks include:

pragma foreign_keys = on;
pragma integrity_check;

If your Go services touch the same database, keep the contract simple. Avoid clever ORM behavior that silently changes types or null handling. Write the schema explicitly. Test the queries your application depends on. For batch jobs, prefer idempotent writes with clear conflict handling.

For example, a content hash plus insert ... on conflict gives you a stable deduplication path. A runs table with explicit status transitions gives you a reliable operator view. Small decisions like these reduce confusion when a pipeline breaks at 2 a.m.

What to watch next

Local-first data tooling keeps getting stronger, and AI engineering benefits from it. Watch for better patterns around structured output storage, vector extensions, and reproducible local eval datasets. Also watch the boundary between SQLite and heavier services. Many teams move to larger infrastructure too early.

If your AI workflow still lives in scattered files and notebook state, the next improvement is simple. Put the operational facts in SQLite. Then inspect them with discipline. The quality gains often come from the storage layer before they come from the model layer.