[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elisa 4cad3085fd 57/98: Use more async calls to prevent
From: |
ELPA Syncer |
Subject: |
[elpa] externals/elisa 4cad3085fd 57/98: Use more async calls to prevent emacs from blocking |
Date: |
Wed, 17 Jul 2024 18:58:04 -0400 (EDT) |
branch: externals/elisa
commit 4cad3085fd869262843eac3c4464f2b879e2e84f
Author: Sergey Kostyaev <kostyaev.sergey2@wb.ru>
Commit: Sergey Kostyaev <kostyaev.sergey2@wb.ru>
Use more async calls to prevent emacs from blocking
---
elisa.el | 109 +++++++++++++++++++++++++++++----------------------------------
1 file changed, 50 insertions(+), 59 deletions(-)
diff --git a/elisa.el b/elisa.el
index 668b6cf67b..52691dbca3 100644
--- a/elisa.el
+++ b/elisa.el
@@ -404,17 +404,17 @@ FOREIGN KEY(collection_id) REFERENCES collections(rowid)
(error
(setq continue nil))))))))
-(defun elisa-find-similar (text collections)
- "Find similar to TEXT results in COLLECTIONS."
- (message "searching in collected data")
- (let* ((rowids (mapcar
- #'car
+(defun elisa--find-similar (text collections)
+ "Find similar to TEXT results in COLLECTIONS.
+Return sqlite query. For asyncronous execution."
+ (let* ((rowids (flatten-tree
(sqlite-select
elisa-db
(format "select rowid from data where collection_id in
(
SELECT rowid FROM collections WHERE name IN %s
-);" (elisa-sqlite-format-string-list collections)))))
+);"
+ (elisa-sqlite-format-string-list collections)))))
(query (format "WITH
vector_search AS (
SELECT rowid, distance
@@ -457,31 +457,16 @@ FROM hybrid_search
(elisa-sqlite-format-int-list rowids)
(elisa-sqlite-format-int-list rowids)
(elisa-fts-query text)
- (elisa-get-limit)))
- (raw-ids (mapcar #'car (sqlite-select elisa-db query)))
- (ids (if elisa-reranker-enabled
- (elisa-rerank text raw-ids)
- (take elisa-limit raw-ids))))
- (mapc
- (lambda (row)
- (when-let ((kind (cl-first row))
- (path (cl-second row))
- (text (cl-third row)))
- (pcase kind
- ("web"
- (ellama-context-add-webpage-quote-noninteractive path path text))
- ("file"
- (ellama-context-add-file-quote-noninteractive path text))
- ("info"
- (ellama-context-add-info-node-quote-noninteractive path text)))))
- (sqlite-select
- elisa-db
- (format
- "SELECT k.name, d.path, d.data
-FROM data AS d
-LEFT JOIN kinds k ON k.rowid = d.kind_id
-WHERE d.rowid in %s;"
- (elisa-sqlite-format-int-list ids))))))
+ (elisa-get-limit))))
+ query))
+
+(defun elisa-find-similar (text collections on-done)
+ "Find similar to TEXT results in COLLECTIONS.
+Evaluate ON-DONE with result."
+ (message "searching in collected data")
+ (elisa--async-do
+ (lambda () (elisa--find-similar text collections))
+ on-done))
(defun elisa--split-by (func)
"Split buffer content to list by FUNC."
@@ -779,38 +764,43 @@ Return sqlite query that extract data for adding to
context."
"Search the web for PROMPT."
(interactive "sAsk elisa with web search: ")
(message "searching the web")
- (elisa--async-do (lambda () (elisa--web-search prompt))
- (lambda (_)
- (elisa-find-similar prompt (list prompt))
- (ellama-chat prompt nil :provider elisa-chat-provider))))
+ (elisa--async-do
+ (lambda () (elisa--web-search prompt))
+ (lambda (_)
+ (elisa-find-similar
+ prompt (list prompt)
+ (lambda (query) (elisa-retrieve-ask query prompt))))))
(defun elisa-retrieve-ask (query prompt)
"Retrieve data with QUERY and ask elisa for PROMPT."
- (let* ((raw-ids (mapcar #'car (sqlite-select elisa-db query)))
- (ids (if elisa-reranker-enabled
- (elisa-rerank prompt raw-ids)
- (take elisa-limit raw-ids))))
- (mapc
- (lambda (row)
- (when-let ((kind (cl-first row))
- (path (cl-second row))
- (text (cl-third row)))
- (pcase kind
- ("web"
- (ellama-context-add-webpage-quote-noninteractive path path text))
- ("file"
- (ellama-context-add-file-quote-noninteractive path text))
- ("info"
- (ellama-context-add-info-node-quote-noninteractive path text)))))
- (sqlite-select
- elisa-db
- (format
- "SELECT k.name, d.path, d.data
+ (elisa--async-do
+ (lambda () (let* ((raw-ids (flatten-tree (sqlite-select elisa-db query)))
+ (ids (if elisa-reranker-enabled
+ (elisa-rerank prompt raw-ids)
+ (take elisa-limit raw-ids))))
+ (sqlite-select
+ elisa-db
+ (format
+ "SELECT k.name, d.path, d.data
FROM data AS d
LEFT JOIN kinds k ON k.rowid = d.kind_id
WHERE d.rowid in %s;"
- (elisa-sqlite-format-int-list ids))))
- (ellama-chat prompt nil :provider elisa-chat-provider)))
+ (elisa-sqlite-format-int-list ids)))))
+ (lambda (result)
+ (mapc
+ (lambda (row)
+ (when-let ((kind (cl-first row))
+ (path (cl-second row))
+ (text (cl-third row)))
+ (pcase kind
+ ("web"
+ (ellama-context-add-webpage-quote-noninteractive path path text))
+ ("file"
+ (ellama-context-add-file-quote-noninteractive path text))
+ ("info"
+ (ellama-context-add-info-node-quote-noninteractive path text)))))
+ result)
+ (ellama-chat prompt nil :provider elisa-chat-provider))))
(defun elisa-get-builtin-manuals ()
"Get builtin manual names list."
@@ -925,8 +915,9 @@ Call ON-DONE callback with result as an argument after FUNC
evaluation done."
Find similar quotes in COLLECTIONS and add it to context."
(interactive "sAsk elisa: ")
(let ((cols (or collections '("builtin manuals" "external manuals"))))
- (elisa-find-similar prompt cols)
- (ellama-chat prompt nil :provider elisa-chat-provider)))
+ (elisa-find-similar
+ prompt cols
+ (lambda (query) (elisa-retrieve-ask query prompt)))))
(provide 'elisa)
;;; elisa.el ends here.
- [elpa] externals/elisa a99ed0b234 33/98: Add semantic splitting, (continued)
- [elpa] externals/elisa a99ed0b234 33/98: Add semantic splitting, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 90a76fc7c2 37/98: Add webpage semantic chunks extraction function, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa d90df5889d 38/98: Add function that return buffer with url content, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 0f94c23a5d 40/98: Add more sqlite tables, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa e877f8f5c7 44/98: First implementation for web search, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 5ca66e9f0d 47/98: Fix custom variables, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 273a1d492d 50/98: Add reranker to RAG pipeline, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa ade7ac0af9 52/98: Update info manual parsing, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 8a2c92dc34 54/98: Fix parsing info manuals, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa cecc5cb13f 55/98: Make sync parsing interactive, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 4cad3085fd 57/98: Use more async calls to prevent emacs from blocking,
ELPA Syncer <=
- [elpa] externals/elisa ad130b564f 60/98: Add parse file function, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa b419fb2cf2 61/98: Add code for parsing directory as an elisa collection, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa ef06534f46 62/98: Implement incremental parsing, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 0e32d7bb5c 63/98: Add async directory parsing, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa f744ce305a 67/98: Add reparse current collection command, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 9ad7827337 70/98: Fix semantic split with single chunk, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 439ed1d4f8 76/98: Make executable customization simpler, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa e5691f59c5 80/98: Make syncronous functions non-interactive, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa e92628390b 82/98: Update example configuration, ELPA Syncer, 2024/07/17
- [elpa] externals/elisa 39915439a4 84/98: Update installation instructions, ELPA Syncer, 2024/07/17