diff options
| -rw-r--r-- | doc/SKILL.md | 9 | ||||
| -rw-r--r-- | scripts/index.scm | 61 |
2 files changed, 56 insertions, 14 deletions
diff --git a/doc/SKILL.md b/doc/SKILL.md index 570bde7..42f706e 100644 --- a/doc/SKILL.md +++ b/doc/SKILL.md @@ -95,7 +95,14 @@ text, stemmed. The default operator is AND; `--or` widens it. Topic terms come from the **session id**, split on hyphens: a session called `gemma-pve` answers `topic:gemma` and `topic:pve`. So the cheapest way to make -an entry findable by concept is to name the session after the concept. +an entry findable by concept is to **name the session after the concept** -- a +session called `gemma-wrapper-diagnostics` about the same work does not answer +`topic:pve`, while a plain-text `pve` search still finds it. That is the +difference between the two: `topic:` is the curated answer, free text is the +recall answer. + +A **commit inherits the topics of the reasoning attached to it**, so +`topic:pve` returns both the reasoning and the commits that carry it. Why a subprocess and a Guile script: `libxapian` is C++-only, so a foreign call from Odin needs a hand-written C shim. `guile-xapian` already has one, tested diff --git a/scripts/index.scm b/scripts/index.scm index ac83850..87e32f8 100644 --- a/scripts/index.scm +++ b/scripts/index.scm @@ -113,6 +113,9 @@ (define (repo-name store) (basename (dirname (canonicalize-path store)))) +(define (alist-set table key value) + (cons (cons key value) table)) + (define (non-empty-string? value) (and (string? value) (not (string-null? value)))) @@ -228,12 +231,20 @@ (field 'text (string-append title " " (or body ""))))))) (else (die "unexpected reasoning row: ~s" row)))) -(define (commit-record repo row) +(define (commit-record repo row sessions) (match row ((hash subject body author_ts) (let* ((key (format #f "commit:~a" hash)) (date (yyyymmdd author_ts)) - (subject (or subject ""))) + (subject (or subject "")) + ;; A commit inherits the topics of the reasoning attached to it: + ;; otherwise the pve story answers with its reasoning and not with + ;; the commits that carry it, which is exactly backwards for a + ;; reader following it. + (topics (append-map (lambda (session) + (map (lambda (word) (term "O" word)) + (string-split session #\-))) + sessions))) (list key (list (field 'type "commit") (field 'key key) @@ -241,17 +252,35 @@ (field 'date date) (field 'commit hash) (field 'title subject) - (field 'terms (list (term "T" "commit") - (term "R" repo) - (term "D" (number->string date)) - (term "C" (substring hash 0 7)))) + (field 'session (if (null? sessions) "" (car sessions))) + (field 'terms (append (list (term "T" "commit") + (term "R" repo) + (term "D" (number->string date)) + (term "C" (substring hash 0 7))) + (map (lambda (session) (term "S" session)) + sessions) + topics)) (field 'body (or body "")) (field 'text (string-append subject " " (or body ""))))))) (else (die "unexpected commit row: ~s" row)))) -(define (records repo reasoning commits) - (append (map (lambda (row) (reasoning-record repo row)) reasoning) - (map (lambda (row) (commit-record repo row)) commits))) +(define (sessions-by-commit attached) + (fold (lambda (row table) + (match row + ((commit_hash sessions) + (alist-set table commit_hash + (if sessions (string-split sessions #\,) (list)))) + (else table))) + '() + attached)) + +(define (records repo reasoning commits attached) + (let ((sessions (sessions-by-commit attached))) + (append (map (lambda (row) (reasoning-record repo row)) reasoning) + (map (lambda (row) + (commit-record repo row + (or (assoc-ref sessions (first row)) (list)))) + commits)))) ;;; --------------------------------------------------------------------- ;;; Writing @@ -310,9 +339,15 @@ 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"))) + FROM commits ORDER BY author_ts")) + ;; Which sessions' reasoning is attached to which commit, so a commit + ;; document can carry those sessions' topics. + (attached (query db "SELECT commit_hash, GROUP_CONCAT(DISTINCT session_id) + FROM reasoning + WHERE commit_hash IS NOT NULL AND session_id <> '' + GROUP BY commit_hash"))) (sqlite-close db) - (values reasoning commits)))) + (values reasoning commits attached)))) ;;; --------------------------------------------------------------------- ;;; Commands @@ -325,9 +360,9 @@ (unless index (die "update needs --index DIR")) (unless (file-exists? store) (die "no store at ~a" store)) (call-with-values (lambda () (store-rows store)) - (lambda (reasoning commits) + (lambda (reasoning commits attached) (let* ((repo (repo-name store)) - (records (records repo reasoning commits)) + (records (records repo reasoning commits attached)) (db (open-writable index rebuild)) (stemmer (new-Stem "english")) (written 0)) |
