about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-16 16:20:48 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-16 16:20:48 +0000
commitdc4c16203674191c4821b2f7b53e01febb7a11a6 (patch)
tree06bc8b8dc19e3b1d72b2fb9475a62bf6fb444243
parent4e3a785e6aec4f8b2eafad82cb35524359751946 (diff)
downloadai-memory-dc4c16203674191c4821b2f7b53e01febb7a11a6.tar.gz
index: title a reasoning doc with its gist, and make --rebuild stand alone
A reasoning document was titled with the subject of the commit it is attached
to (COALESCE(c.subject,'') through a LEFT JOIN), which is wrong twice over: an
entry recorded with --commit none -- every entry before its commit exists --
was indexed with an empty title, and its gist, the assessed one-line claim
that `list` and `why` show, was not indexed as text at all; an attached entry
merely repeated the title its commit document already carries. The title is
now the entry's own gist, from reasoning.gist, and the join is gone.

`update-index --rebuild` also died with "mkdir failed (No such file or
directory)" whenever the index directory was absent -- the state of every
store that has never been indexed, and the state README.md tells a reader to
produce by deleting the index. Only the non-rebuild path created the
directory; `mkdir -p` now runs before the database handle either way.

The check phase records a gist deliberately different from the body and
asserts both that it answers a search and that it is the document's title, so
a regression fails the build rather than the reader.

.gitignore covers *.sqlite.d/, the default index directory, which neither
*.sqlite nor *.sqlite-* matched -- the README already claimed the index was
ignored.

doc/SKILL.md says what `title` means in a search reply: the gist for a
reasoning entry, the subject for a commit.
-rw-r--r--.gitignore4
-rw-r--r--doc/SKILL.md6
-rw-r--r--guix.scm18
-rw-r--r--scripts/index.scm24
4 files changed, 43 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 0c2a929..c7bd2bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,5 +3,9 @@
 *.sqlite
 *.sqlite-*
 
+# The topic index is derived from the store and named <store>.d/index, which
+# '*.sqlite-*' does not match; it is disposable and never belongs in git.
+*.sqlite.d/
+
 # Local build output of `odin build . -out:bin/ai-memory'.
 /bin/
diff --git a/doc/SKILL.md b/doc/SKILL.md
index 9030f81..41b0af9 100644
--- a/doc/SKILL.md
+++ b/doc/SKILL.md
@@ -175,6 +175,12 @@ The JSON a search returns is the record as indexed -- `key`, `repo`, `session`,
 `kind`, `date`, `commit`, `title`, `body`, `terms` -- plus `docid` and
 `percent`. `count` is how many came back, `matches` how many the index found.
 
+For a reasoning entry `title` is its **gist** (the assessed one-line claim), not
+the subject of the commit it is attached to: that subject already titles the
+commit document, and an entry recorded with `--commit none` has no commit to
+borrow from. The gist is indexed as text too, so a claim written only in the
+gist is findable; a commit document's `title` is its subject, as before.
+
 ## Rules
 
 - **Never write to `commits`, `symbols` or `touches` by hand.**  They are derived;
diff --git a/guix.scm b/guix.scm
index 3f5691c..7733f83 100644
--- a/guix.scm
+++ b/guix.scm
@@ -274,8 +274,15 @@ to link the system SQLite3 instead of a bundled copy.")
                   ;; A session id is what gives the entry its topic: terms
                   ;; ("topic-index" -> topic:topic and topic:index), so the
                   ;; query below is a real concept query, not a text match.
+                  ;; The gist is given separately from the body on purpose:
+                  ;; it is what titles a reasoning document and it is indexed
+                  ;; as text, so a claim written only in the gist must still
+                  ;; answer a search. (Before that was true, an entry with no
+                  ;; commit was indexed with an empty title and its gist was
+                  ;; not searchable at all.)
                   (invoke "./bin/ai-memory" "record" "--kind" "conclusion"
                           "--session" "topic-index"
+                          "--gist" "gisttext names the document"
                           "--body" "the index answers topic: queries")
                   (invoke "./bin/ai-memory" "--index" "tmp/index" "update-index")
                   ;; The reply is JSON on stdout: pipe it into grep rather
@@ -284,7 +291,16 @@ to link the system SQLite3 instead of a bundled copy.")
                   (invoke "sh" "-c"
                           (string-append "./bin/ai-memory --index tmp/index"
                                          " search topic:index"
-                                         " | grep -q '\"count\":1'")))))
+                                         " | grep -q '\"count\":1'"))
+                  (invoke "sh" "-c"
+                          (string-append "./bin/ai-memory --index tmp/index"
+                                         " search gisttext"
+                                         " | grep -q '\"count\":1'"))
+                  (invoke "sh" "-c"
+                          (string-append "./bin/ai-memory --index tmp/index"
+                                         " search topic:index"
+                                         " | grep -q"
+                                         " '\"title\":\"gisttext names the document\"'")))))
             (replace 'install
               (lambda _
                 (install-file "bin/ai-memory"
diff --git a/scripts/index.scm b/scripts/index.scm
index 87e32f8..e812f94 100644
--- a/scripts/index.scm
+++ b/scripts/index.scm
@@ -123,10 +123,13 @@
 ;;; Database handles
 
 (define (open-writable index rebuild)
-  (unless rebuild
-    ;; Xapian creates its files inside DIR, but not DIR.
-    (unless (zero? (system* "mkdir" "-p" index))
-      (die "could not create ~a" index)))
+  ;; Xapian creates its files inside DIR, but not DIR -- and only the plain
+  ;; `update' path used to create it, so `update --rebuild' on a store whose
+  ;; index directory was deleted (the documented way to recover, and the state
+  ;; of every store that has never been indexed) died in new-WritableDatabase
+  ;; with "mkdir failed". `mkdir -p' is a no-op when the directory is there.
+  (unless (zero? (system* "mkdir" "-p" index))
+    (die "could not create ~a" index))
   (new-WritableDatabase index
                         (if rebuild (DB-CREATE-OR-OVERWRITE) (DB-CREATE-OR-OPEN))))
 
@@ -197,12 +200,18 @@
   (let ((entry (assq key record)))
     (and entry (second entry))))
 
+;;; The title is the entry's own gist -- the assessed one-line claim, which is
+;;; what `list' and `why' show. It is deliberately NOT the subject of the
+;;; commit the entry is attached to: that subject is already the title of the
+;;; commit document, and an entry recorded with `--commit none' has no commit
+;;; to borrow from, which left it indexed with an empty title and its gist
+;;; unsearchable.
 (define (reasoning-record repo row)
   (match row
-    ((id session step kind body commit_hash created_at subject)
+    ((id session step kind body commit_hash created_at gist)
      (let* ((key (format #f "reasoning:~a" id))
             (date (yyyymmdd created_at))
-            (title (if (string? subject) (string-trim-both subject) ""))
+            (title (if (string? gist) (string-trim-both gist) ""))
             (topics (if (non-empty-string? session)
                         (map (lambda (word) (term "O" word))
                              (string-split session #\-))
@@ -334,9 +343,8 @@
   (let ((db (sqlite-open store SQLITE_OPEN_READONLY)))
     (let ((reasoning (query db "SELECT r.id, r.session_id, r.step, r.kind, r.body,
                                       COALESCE(r.commit_hash, ''), r.created_at,
-                                      COALESCE(c.subject, '')
+                                      COALESCE(r.gist, '')
                                FROM reasoning r
-                               LEFT JOIN commits c ON c.hash = r.commit_hash
                                ORDER BY r.id"))
           (commits (query db "SELECT hash, subject, COALESCE(body, ''), author_ts
                               FROM commits ORDER BY author_ts"))