diff --git a/deps/outliner/src/logseq/outliner/core.cljs b/deps/outliner/src/logseq/outliner/core.cljs index 7c63af3ed1..e60d2665f5 100644 --- a/deps/outliner/src/logseq/outliner/core.cljs +++ b/deps/outliner/src/logseq/outliner/core.cljs @@ -251,7 +251,7 @@ collapse-or-expand? (= outliner-op :collapse-expand-blocks) m* (cond-> (-> data' - (dissoc :block/children :block/meta :block/unordered + (dissoc :block/children :block/meta :block/unordered :block/path-refs :block.temp/ast-title :block.temp/ast-body :block/level :block.temp/load-status :block.temp/has-children?) common-util/remove-nils diff --git a/deps/outliner/src/logseq/outliner/pipeline.cljs b/deps/outliner/src/logseq/outliner/pipeline.cljs index 9dbb1f80ee..a232d245e2 100644 --- a/deps/outliner/src/logseq/outliner/pipeline.cljs +++ b/deps/outliner/src/logseq/outliner/pipeline.cljs @@ -50,7 +50,7 @@ (recur (into parent-refs (:block-ref-ids parent)) (:parent-id parent)) ;; exits when top-level parent is reached - parent-refs)))}) + (remove nil? parent-refs))))}) children-maps)] children-refs)) @@ -87,10 +87,13 @@ old-refs (if db-before (set (map :db/id (:block/path-refs (d/entity db-before (:db/id block))))) #{}) - new-refs (set (concat - (some-> (:db/id (:block/page block)) vector) - (map :db/id (:block/refs block)) - parents-refs)) + new-refs (->> + (concat + (some-> (:db/id (:block/page block)) vector) + (map :db/id (:block/refs block)) + parents-refs) + (remove nil?) + set) refs-changed? (not= old-refs new-refs) children (when refs-changed? (when-not page? diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index bd819bb470..17d19b7dd4 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -1258,7 +1258,7 @@ (for [model-name (:available-model-names model-info)] (shui/select-item {:value model-name} model-name))))) - (when status + (when (and status current-model) [:div.text-muted-foreground.text-sm (let [{:keys [file progress loaded total]} load-model-progress] (case status diff --git a/src/main/frontend/worker/embedding.cljs b/src/main/frontend/worker/embedding.cljs index 0caf41d26b..1ab93da469 100644 --- a/src/main/frontend/worker/embedding.cljs +++ b/src/main/frontend/worker/embedding.cljs @@ -79,14 +79,16 @@ (filter (stale-block-filter-preds reset?)) (map (fn [b] (assoc b :block.temp/text-to-embedding - (str (db-content/recur-replace-uuid-in-block-title b) - (let [tags (->> (:block/tags b) - (map :block/title))] - (when (seq tags) - (str " tags: " (string/join ", " tags)))) - (when-let [desc (:block/title (:logseq.property/description b))] - (str " description: " desc)))))))))) - + (db-content/recur-replace-uuid-in-block-title b) + ;; FIXME: tags and properties can affect sorting + ;; (str (db-content/recur-replace-uuid-in-block-title b) + ;; (let [tags (->> (:block/tags b) + ;; (map :block/title))] + ;; (when (seq tags) + ;; (str " " (string/join ", " (map (fn [t] (str "#" t)) tags))))) + ;; (when-let [desc (:block/title (:logseq.property/description b))] + ;; (str "\nDescription: " desc))) + ))))))) (defn- partition-by-text-size [text-size] (let [*current-size (volatile! 0) diff --git a/src/main/frontend/worker/search.cljs b/src/main/frontend/worker/search.cljs index 4952229cd1..41017b9c33 100644 --- a/src/main/frontend/worker/search.cljs +++ b/src/main/frontend/worker/search.cljs @@ -299,37 +299,39 @@ DROP TRIGGER IF EXISTS blocks_au; (exact-matched? q title))))))))) ;; Combine and re-rank results -(defn combine-results [keyword-results semantic-results] +(defn combine-results + [db keyword-results semantic-results] (let [;; Extract score ranges for normalization keyword-scores (map :keyword-score keyword-results) - semantic-scores (map :semantic-score semantic-results) k-min (if (seq keyword-scores) (apply min keyword-scores) 0.0) k-max (if (seq keyword-scores) (apply max keyword-scores) 1.0) - s-min (if (seq semantic-scores) (apply min semantic-scores) 0.0) - s-max (if (seq semantic-scores) (apply max semantic-scores) 1.0) - ;; Merge results by ID all-ids (set/union (set (map :id keyword-results)) (set (map :id semantic-results))) merged (map (fn [id] - (let [k-result (first (filter #(= (:id %) id) keyword-results)) + (let [block (when id (d/entity db [:block/uuid (uuid id)])) + k-result (first (filter #(= (:id %) id) keyword-results)) s-result (first (filter #(= (:id %) id) semantic-results)) + result (merge s-result k-result) k-score (or (:keyword-score k-result) 0.0) s-score (or (:semantic-score s-result) 0.0) norm-k-score (normalize-score k-score k-min k-max) - norm-s-score (normalize-score s-score s-min s-max) ;; Weighted combination combined-score (+ (* (:keyword-weight config) norm-k-score) - (* (:semantic-weight config) norm-s-score))] - (merge k-result - s-result - {:id id - :combined-score combined-score + (* (:semantic-weight config) s-score) + (cond + (ldb/page? block) + 1 + (:block/tags block) + 0.02 + :else + 0))] + (merge result + {:combined-score combined-score :keyword-score k-score :semantic-score s-score}))) - all-ids)] - ;; Sort by combined score - (prn :debug :merged (sort-by :combined-score #(compare %2 %1) merged)) - (sort-by :combined-score #(compare %2 %1) merged))) + all-ids) + sorted-result (sort-by :combined-score #(compare %2 %1) merged)] + sorted-result)) (defn search-blocks "Options: @@ -365,7 +367,7 @@ DROP TRIGGER IF EXISTS blocks_au; (search-blocks-aux search-db match-sql q match-input page limit enable-snippet?)) non-match-result (when (and (not page-only?) non-match-input) (search-blocks-aux search-db non-match-sql q non-match-input page limit enable-snippet?)) - ;; fuzzy is too slow for large graphs + ;; fuzzy is too slow for large graphs fuzzy-result (when-not (or page large-graph?) (fuzzy-search repo @conn q option)) semantic-search-result* (m/? (embedding/task--search repo q 10)) semantic-search-result (->> semantic-search-result* @@ -377,7 +379,7 @@ DROP TRIGGER IF EXISTS blocks_au; :semantic-score (/ 1.0 (+ 1.0 distance))} page-id (assoc :page page-id)))))) - combined-result (combine-results (concat fuzzy-result matched-result) semantic-search-result) + combined-result (combine-results @conn (concat fuzzy-result matched-result) semantic-search-result) result (->> (concat combined-result non-match-result) (common-util/distinct-by :id) diff --git a/src/resources/dicts/en.edn b/src/resources/dicts/en.edn index f89424ca4a..65a8c53387 100644 --- a/src/resources/dicts/en.edn +++ b/src/resources/dicts/en.edn @@ -214,6 +214,7 @@ :context-menu/template-include-parent-block "Including the parent block in the template?" :context-menu/template-exists-warning "Template already exists!" :settings-page/ai "AI" + :settings-page/tab-ai "AI" :settings-page/git-tip "If you have Logseq Sync enabled, you can view a page's edit history directly. This section is for tech-savvy only." :settings-page/git-desc-1 "To view page's edit history, click the three horizontal dots in the top-right corner and select \"View page history\"." :settings-page/git-desc-2 "For professional users, Logseq also supports using "