AgentDb.Seed (agent_db v0.1.0)

Copy Markdown View Source

Deterministic demo dataset for development and test environments.

One command builds the same baseline everywhere: documents under a demo prefix, one typed memory per taxonomy type, one session committed into the tree, one demo skill, and two indexed Elixir sources for the demo project. Every fixture carries a distinctive seedling-* keyword so demos and tests can assert on keyword search, find/2, and grep/2 hits.

{:ok, report} = AgentDb.Seed.seed()
{:ok, report} = AgentDb.Seed.seed(prefix: "viking://resources/custom", force: true)

Safety

The seed refuses a store that already holds data ({:error, :store_not_empty}) unless force: true (merge: missing seed URIs are created, present ones revised in place, nothing deleted) or clean: true (only the seed scope is removed first: the prefix subtree, the demo-* memories, the demo skill, and the demo code prefix; data outside that scope survives). A refusal writes nothing. An invalid prefix fails with :invalid_uri on the first write, also having written nothing.

Pass env: :prod (the Mix task passes Mix.env()) to engage the production guard: seeding in production without allow_prod: true is refused as {:error, :production_guarded} with nothing written. The library never reads Mix.env/0 itself, so releases without Mix behave the same through the explicit option.

Scope

The :prefix override (default "viking://resources/demo") scopes the documents and the committed session. Memories, the demo skill (user "demo"), and the demo code entries live at fixed global URIs by design, so a custom prefix still revises the same memories, skill, and code.

Report

Success answers {:ok, report} with the prefix used and per-kind counts:

%{prefix: ..., documents: 5, memories: 5, sessions: 1, messages: 3,
  session: "<prefix>/sessions/intro.md", skills: 1, skill_files: 2,
  indexed: 2}

Re-running converges: the same URIs are revised (memories supersede, the skill is replaced whole, the session document is rewritten), so the tree holds one active value per URI. Each run opens a new session row to commit from; only the committed document is part of the dataset.

Rollback is AgentDb.rm(prefix) plus forgetting the demo-* memory URIs; re-seeding afterwards converges. Reads need no model: keyword search, find, and grep reach seeded content immediately, while embeddings and summaries regenerate through the existing job queue.

Summary

Functions

The default demo prefix documents and the committed session live under.

Builds the demo dataset described in the module documentation.

Types

report()

@type report() :: %{
  prefix: String.t(),
  documents: non_neg_integer(),
  memories: non_neg_integer(),
  sessions: non_neg_integer(),
  messages: non_neg_integer(),
  session: String.t(),
  skills: non_neg_integer(),
  skill_files: non_neg_integer(),
  indexed: non_neg_integer()
}

Functions

default_prefix()

@spec default_prefix() :: String.t()

The default demo prefix documents and the committed session live under.

seed(opts \\ [])

@spec seed(keyword()) :: {:ok, report()} | {:error, term()}

Builds the demo dataset described in the module documentation.

Options:

  • :prefix - demo prefix for documents and the committed session (default "viking://resources/demo").
  • :force - merge into a non-empty store instead of refusing it.
  • :clean - remove only the seed scope, then seed.
  • :env - caller environment, e.g. Mix.env(); :prod engages the production guard.
  • :allow_prod - allow seeding when env: :prod (default false).