@digitalvibes/ai-knowledge-db 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,6 +38,25 @@ Initialise the schema once: `npx knowledge-db init`
38
38
 
39
39
  A search for a project automatically also pulls that **client's** shared knowledge and **global** knowledge, ranked together by relevance.
40
40
 
41
+ ## Freshness — keeping facts current (IMPORTANT)
42
+
43
+ Semantic search has no built-in notion of "newest", so facts that **change** (pricing, hours, contact, current offer) must be written with a stable **`key`** using `put` — not `add`. Writing the same key again supersedes the old version (kept as history) and makes the new one the only result in normal search.
44
+
45
+ ```bash
46
+ # first time
47
+ npx knowledge-db put "Basic plan is €50/mo." --key pricing.basic-plan --scope client
48
+ # price changes — same key; search now returns only €80, €50 kept as history
49
+ npx knowledge-db put "Basic plan is €80/mo." --key pricing.basic-plan --scope client
50
+ ```
51
+
52
+ - **Use `put --key …`** for any fact that can change. The newest version always wins.
53
+ - **Use `add`** only for accumulating notes that never need to override each other.
54
+ - **Use `add-file --source …`** for documents — re-ingesting supersedes the prior version of that source.
55
+ - Inspect history: `npx knowledge-db history --key pricing.basic-plan`
56
+ - Point-in-time / include old versions: `search "…" --as-of 2026-01-01` or `search "…" --history`.
57
+
58
+ Rule of thumb: **if updating it should replace the old answer, give it a `key` and use `put`.**
59
+
41
60
  ## CLI (preferred for quick ops)
42
61
 
43
62
  ```bash
@@ -45,9 +64,12 @@ A search for a project automatically also pulls that **client's** shared knowled
45
64
  npx knowledge-db search "what is the brand voice?"
46
65
  npx knowledge-db search "homepage hero copy" --project acme-website --json
47
66
 
48
- # add a fact (scope auto-derives: project if KNOWLEDGE_PROJECT_ID set, else client, else global)
67
+ # add a free-form note (accumulates; never overrides)
49
68
  npx knowledge-db add "Client prefers sentence case for all headings." --scope client
50
- npx knowledge-db add "Hero CTA finalised as 'Start free'." --source decisions.md
69
+
70
+ # put a CHANGEABLE fact (newer overrides older; old kept as history)
71
+ npx knowledge-db put "Basic plan is €80/mo." --key pricing.basic-plan --scope client
72
+ npx knowledge-db history --key pricing.basic-plan # list all versions
51
73
 
52
74
  # add / update a file or doc idempotently (re-running replaces prior rows for that source)
53
75
  npx knowledge-db add-file ./brand/voice.md --scope client --source brand/voice.md
@@ -70,10 +92,14 @@ const kb = createKnowledgeDB(); // reads .env
70
92
  const hits = await kb.search("brand voice and tone", { limit: 5 });
71
93
  const context = hits.map((h) => h.content).join("\n\n");
72
94
 
73
- // store a durable fact
95
+ // store a free-form note
74
96
  await kb.add({ content: "Client approved the green palette.", scope: "client" });
75
97
 
76
- // idempotently re-ingest a doc
98
+ // store / update a CHANGEABLE fact (newer supersedes older)
99
+ await kb.put({ key: "pricing.basic-plan", content: "Basic plan is €80/mo.", scope: "client" });
100
+ const versions = await kb.history("pricing.basic-plan", { scope: "client" });
101
+
102
+ // idempotently re-ingest a doc (supersedes prior version of this source)
77
103
  await kb.upsertSource({ content: fileText, source: "specs/sitemap.md" });
78
104
 
79
105
  await kb.close();
@@ -82,6 +108,6 @@ await kb.close();
82
108
  ## Workflow guidance for the agent
83
109
 
84
110
  1. **Before** building website copy/components or answering a "what do we know" question, run a `search` and ground your output in the results. Cite the `source` when relevant.
85
- 2. **After** the user states a durable preference/decision ("remember…", "from now on…", "the client wants…"), `add` it with the right scope. Prefer `client` scope for anything reusable across the client's projects; `project` for this build only.
86
- 3. When re-ingesting a known file/URL, use `add-file` / `upsertSource` (not `add`) so you don't create duplicates.
111
+ 2. **After** the user states a durable fact/decision, store it with the right scope (`client` = reusable across the client's projects, `project` = this build). Choose the verb by mutability: a **changeable** fact (pricing, hours, status) → `put` with a stable `key` so it overrides cleanly; a one-off note → `add`.
112
+ 3. When re-ingesting a known file/URL, use `add-file` / `upsertSource` (not `add`) so the prior version is superseded instead of duplicated.
87
113
  4. If a search returns nothing useful, say so rather than inventing context.