feat: implement Hybrid Depth+Semantic pruning for Peripheral Vision
This commit is contained in:
@@ -102,28 +102,47 @@ Provides execution stats for a specific skill.
|
|||||||
Transforms the internal Object Store structures back into a human-readable (and LLM-readable) Org-mode string. It supports depth-based indentation and content suppression for peripheral nodes.
|
Transforms the internal Object Store structures back into a human-readable (and LLM-readable) Org-mode string. It supports depth-based indentation and content suppression for peripheral nodes.
|
||||||
|
|
||||||
#+begin_src lisp :tangle ../src/context.lisp
|
#+begin_src lisp :tangle ../src/context.lisp
|
||||||
(defun context-render-to-org (obj &key (depth 1) (foveal-id nil))
|
(defun context-render-to-org (obj &key (depth 1) (foveal-id nil) (semantic-threshold 0.75) (foveal-vector nil))
|
||||||
"Recursively renders an org-object and its children to an Org string."
|
"Recursively renders an org-object and its children to an Org string using a Foveal-Peripheral Hybrid model."
|
||||||
(let* ((is-foveal (equal (org-object-id obj) foveal-id))
|
(let* ((id (org-object-id obj))
|
||||||
|
(is-foveal (equal id foveal-id))
|
||||||
(title (or (getf (org-object-attributes obj) :TITLE) "Untitled"))
|
(title (or (getf (org-object-attributes obj) :TITLE) "Untitled"))
|
||||||
(id (org-object-id obj))
|
|
||||||
(content (org-object-content obj))
|
(content (org-object-content obj))
|
||||||
(children (org-object-children obj))
|
(children (org-object-children obj))
|
||||||
(stars (make-string depth :initial-element #\*))
|
(stars (make-string depth :initial-element #\*))
|
||||||
(output (format nil "~a ~a~%:PROPERTIES:~%:ID: ~a~%:END:~%" stars title id)))
|
(obj-vector (org-object-vector obj))
|
||||||
|
(similarity (if (and foveal-vector obj-vector (not is-foveal))
|
||||||
|
(cosine-similarity foveal-vector obj-vector)
|
||||||
|
0.0))
|
||||||
|
(is-semantically-relevant (>= similarity semantic-threshold))
|
||||||
|
;; We always render depth 1 and 2 (Projects and main tasks).
|
||||||
|
;; We always render the foveal node and its immediate children.
|
||||||
|
;; We render deeper nodes ONLY if they are semantically relevant.
|
||||||
|
(should-render (or (<= depth 2) is-foveal is-semantically-relevant))
|
||||||
|
(output ""))
|
||||||
|
|
||||||
;; Only include content if this is the foveal focus
|
(when should-render
|
||||||
(when (and is-foveal content)
|
(setf output (format nil "~a ~a~%:PROPERTIES:~%:ID: ~a~%" stars title id))
|
||||||
(setf output (concatenate 'string output content (string #\Newline))))
|
(when is-semantically-relevant
|
||||||
|
(setf output (concatenate 'string output (format nil ":SEMANTIC_SCORE: ~,2f~%" similarity))))
|
||||||
;; Recursively render children
|
(setf output (concatenate 'string output (format nil ":END:~%")))
|
||||||
(dolist (child-id children)
|
|
||||||
(let ((child-obj (lookup-object child-id)))
|
;; Only include full body content if this is the Foveal focus or highly relevant
|
||||||
(when child-obj
|
(when (and content (or is-foveal is-semantically-relevant))
|
||||||
(setf output (concatenate 'string output
|
(setf output (concatenate 'string output content (string #\Newline))))
|
||||||
(context-render-to-org child-obj
|
|
||||||
:depth (1+ depth)
|
;; Recursively render children
|
||||||
:foveal-id foveal-id))))))
|
(dolist (child-id children)
|
||||||
|
(let ((child-obj (lookup-object child-id)))
|
||||||
|
(when child-obj
|
||||||
|
;; If the current node is Foveal, its children should be rendered (depth effectively resets)
|
||||||
|
(let ((next-foveal (if is-foveal child-id foveal-id)))
|
||||||
|
(setf output (concatenate 'string output
|
||||||
|
(context-render-to-org child-obj
|
||||||
|
:depth (1+ depth)
|
||||||
|
:foveal-id next-foveal
|
||||||
|
:semantic-threshold semantic-threshold
|
||||||
|
:foveal-vector foveal-vector))))))))
|
||||||
output))
|
output))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
@@ -225,7 +244,8 @@ Verification of the peripheral vision extraction and rendering logic.
|
|||||||
|
|
||||||
#+begin_src lisp :tangle ../tests/peripheral-vision-tests.lisp
|
#+begin_src lisp :tangle ../tests/peripheral-vision-tests.lisp
|
||||||
(defpackage :org-agent-peripheral-vision-tests
|
(defpackage :org-agent-peripheral-vision-tests
|
||||||
(:use :cl :fiveam :org-agent))
|
(:use :cl :fiveam :org-agent)
|
||||||
|
(:export #:vision-suite))
|
||||||
(in-package :org-agent-peripheral-vision-tests)
|
(in-package :org-agent-peripheral-vision-tests)
|
||||||
|
|
||||||
(def-suite vision-suite
|
(def-suite vision-suite
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
:components ((:file "package")
|
:components ((:file "package")
|
||||||
(:file "protocol")
|
(:file "protocol")
|
||||||
(:file "object-store")
|
(:file "object-store")
|
||||||
(:file "context")
|
|
||||||
(:file "embedding")
|
(:file "embedding")
|
||||||
|
(:file "context")
|
||||||
(:file "skills")
|
(:file "skills")
|
||||||
(:file "neuro")
|
(:file "neuro")
|
||||||
(:file "symbolic")
|
(:file "symbolic")
|
||||||
|
|||||||
Reference in New Issue
Block a user