create text embeds on create and updsate
This commit is contained in:
parent
aeefd4a157
commit
c7bca62df4
3 changed files with 14 additions and 5 deletions
|
|
@ -54,11 +54,18 @@
|
||||||
"Save an embedding to Qdrant"
|
"Save an embedding to Qdrant"
|
||||||
[snippet embed]
|
[snippet embed]
|
||||||
(let [api-key (:qdrant-api-key (config))
|
(let [api-key (:qdrant-api-key (config))
|
||||||
id (db/slug-to-db-id (:slug snippet))]
|
id (db/slug-to-db-id (:slug snippet))
|
||||||
(t/log! {:level :info :data {:slug (:slug snippet) :api-key api-key :id id}} "Saving embedding for snippet")
|
host (str (:qdrant-host (config)) "/collections/snippets-dev/points")]
|
||||||
(http/put (str (:qdrant-host (config)) "/collections/snippets-dev/points")
|
(t/log! {:level :info :data {:slug (:slug snippet) :id id :host host}} "Saving embedding for snippet")
|
||||||
|
(http/put host
|
||||||
{:headers {"api-key" api-key}
|
{:headers {"api-key" api-key}
|
||||||
:content-type :json
|
:content-type :json
|
||||||
:form-params {:points [{:id id :vector embed :payload {:slug (:slug snippet)}}]}
|
:form-params {:points [{:id id :vector embed :payload {:slug (:slug snippet)}}]}
|
||||||
;; :cookie-store false
|
;; :cookie-store false
|
||||||
:as :json})))
|
:as :json})))
|
||||||
|
|
||||||
|
(defn get-and-save-embed
|
||||||
|
"Get an embedding for a snippet and save it to Qdrant"
|
||||||
|
[snippet]
|
||||||
|
(let [embed (get-embed snippet)]
|
||||||
|
(save-embed snippet embed)))
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
(ns snippets.use-cases.create
|
(ns snippets.use-cases.create
|
||||||
(:require
|
(:require
|
||||||
[taoensso.telemere :as t]
|
[taoensso.telemere :as t]
|
||||||
|
[snippets.infra.text-embed :as embed]
|
||||||
[snippets.infra.db :as db]))
|
[snippets.infra.db :as db]))
|
||||||
|
|
||||||
(defn create-snippet [{:keys [title slug markdown tags]}]
|
(defn create-snippet [{:keys [title slug markdown tags]}]
|
||||||
(let [pub-date (java.util.Date.)]
|
(let [pub-date (java.util.Date.)]
|
||||||
(t/log! {:level :info, :data {:title title :slug slug}} "Creating snippet")
|
(t/log! {:level :info, :data {:title title :slug slug}} "Creating snippet")
|
||||||
(db/create-snippets [{:title title :slug slug :markdown markdown :tags tags :pub-date pub-date}])
|
(db/create-snippets [{:title title :slug slug :markdown markdown :tags tags :pub-date pub-date}])
|
||||||
;; TODO: caculate text embed vector
|
(embed/get-and-save-embed (db/get-snippet-by-slug slug))))
|
||||||
))
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns snippets.use-cases.edit
|
(ns snippets.use-cases.edit
|
||||||
(:require
|
(:require
|
||||||
[taoensso.telemere :as t]
|
[taoensso.telemere :as t]
|
||||||
|
[snippets.infra.text-embed :as embed]
|
||||||
[malli.core :as m]
|
[malli.core :as m]
|
||||||
[snippets.infra.db :as db]))
|
[snippets.infra.db :as db]))
|
||||||
|
|
||||||
|
|
@ -18,5 +19,6 @@
|
||||||
(do
|
(do
|
||||||
(t/log! {:level :info, :data {:patch patch :slug slug}} "Valid changes editing snippet")
|
(t/log! {:level :info, :data {:patch patch :slug slug}} "Valid changes editing snippet")
|
||||||
(db/update-snippet slug patch)
|
(db/update-snippet slug patch)
|
||||||
|
(embed/get-and-save-embed (db/get-snippet-by-slug slug))
|
||||||
{:success true})
|
{:success true})
|
||||||
{:success false :reason :invalid-patch}))
|
{:success false :reason :invalid-patch}))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue