PSF: Complete 'Thin Harness' refactor and move kernel logic to skills
This commit is contained in:
@@ -181,67 +181,11 @@ The primary context generator. It identifies active projects and the current fov
|
||||
output))
|
||||
#+end_src
|
||||
|
||||
* Semantic Search (embedding.lisp)
|
||||
The `embedding.lisp` module handles vector representations and cosine similarity for semantic discovery.
|
||||
|
||||
** Package Context
|
||||
#+begin_src lisp :tangle ../src/embedding.lisp
|
||||
(in-package :org-agent)
|
||||
#+end_src
|
||||
|
||||
** Embedding Retrieval (get-embedding)
|
||||
Fetches a numerical vector representation of text from the configured provider (defaults to Gemini `text-embedding-004`).
|
||||
|
||||
#+begin_src lisp :tangle ../src/embedding.lisp
|
||||
(defun get-embedding (text)
|
||||
"Retrieves a vector representation of text via the configured neural provider."
|
||||
(let* ((auth (get-provider-auth :gemini)) (api-key (getf auth :api-key))
|
||||
(endpoint "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent"))
|
||||
(unless api-key (return-from get-embedding nil))
|
||||
(let* ((url (format nil "~a?key=~a" endpoint api-key)) (headers `(("Content-Type" . "application/json")))
|
||||
(body (cl-json:encode-json-to-string `((model . "models/text-embedding-004") (content . ((parts . ((text . ,text)))))))))
|
||||
(handler-case (let* ((response (dex:post url :headers headers :content body))
|
||||
(json (cl-json:decode-json-from-string response)))
|
||||
(cdr (assoc :values (cdr (assoc :embedding json)))))
|
||||
(error (c) (kernel-log "EMBEDDING FAILURE: ~a" c) nil)))))
|
||||
#+end_src
|
||||
|
||||
** Vector Math
|
||||
Simple implementations of dot product and magnitude for similarity calculations.
|
||||
|
||||
#+begin_src lisp :tangle ../src/embedding.lisp
|
||||
(defun dot-product (v1 v2)
|
||||
"Calculates the dot product of two numerical vectors."
|
||||
(reduce #'+ (mapcar #'* v1 v2)))
|
||||
|
||||
(defun magnitude (v)
|
||||
"Calculates the Euclidean magnitude of a numerical vector."
|
||||
(sqrt (reduce #'+ (mapcar (lambda (x) (* x x)) v))))
|
||||
#+end_src
|
||||
|
||||
** Cosine Similarity (cosine-similarity)
|
||||
Calculates the semantic distance (normalized dot product) between two vectors.
|
||||
|
||||
#+begin_src lisp :tangle ../src/embedding.lisp
|
||||
(defun cosine-similarity (v1 v2)
|
||||
"Calculates the semantic distance between two vectors."
|
||||
(let ((m1 (magnitude v1)) (m2 (magnitude v2))) (if (or (zerop m1) (zerop m2)) 0 (/ (dot-product v1 v2) (* m1 m2)))))
|
||||
#+end_src
|
||||
|
||||
** Semantic Discovery (find-most-similar)
|
||||
Identifies the top-k most semantically related objects in the entire store by comparing their cached vectors against a query vector.
|
||||
|
||||
#+begin_src lisp :tangle ../src/embedding.lisp
|
||||
(defun find-most-similar (query-vector top-k)
|
||||
"Identifies the top-k most semantically related objects in the store."
|
||||
(let ((similarities nil))
|
||||
(maphash (lambda (id obj) (let ((vec (org-object-vector obj))) (when vec (push (cons (cosine-similarity query-vector vec) obj) similarities)))) *object-store*)
|
||||
(let ((sorted (sort similarities #'> :key #'car))) (subseq sorted 0 (min top-k (length sorted))))))
|
||||
#+end_src
|
||||
|
||||
* Phase E: Chaos (Verification)
|
||||
Verification of the peripheral vision extraction and rendering logic.
|
||||
|
||||
Verification of the peripheral vision extraction and rendering logic.
|
||||
|
||||
#+begin_src lisp :tangle ../tests/peripheral-vision-tests.lisp
|
||||
(defpackage :org-agent-peripheral-vision-tests
|
||||
(:use :cl :fiveam :org-agent)
|
||||
|
||||
Reference in New Issue
Block a user