mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Merge branch 'improve-usage-of-user-customizable-variables-in-emacs-interface'
This commit is contained in:
@@ -36,22 +36,27 @@
|
|||||||
(require 'url)
|
(require 'url)
|
||||||
(require 'json)
|
(require 'json)
|
||||||
|
|
||||||
(defcustom khoj--server-url "http://localhost:8000"
|
(defcustom khoj-server-url "http://localhost:8000"
|
||||||
"Location of Khoj API server."
|
"Location of Khoj API server."
|
||||||
:group 'khoj
|
:group 'khoj
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
(defcustom khoj--image-width 156
|
(defcustom khoj-image-width 156
|
||||||
"Width of rendered images returned by Khoj."
|
"Width of rendered images returned by Khoj."
|
||||||
:group 'khoj
|
:group 'khoj
|
||||||
:type 'integer)
|
:type 'integer)
|
||||||
|
|
||||||
(defcustom khoj--rerank-after-idle-time 1.0
|
(defcustom khoj-image-height 156
|
||||||
|
"Height of rendered images returned by Khoj."
|
||||||
|
:group 'khoj
|
||||||
|
:type 'integer)
|
||||||
|
|
||||||
|
(defcustom khoj-rerank-after-idle-time 2.0
|
||||||
"Idle time (in seconds) to trigger cross-encoder to rerank incremental search results."
|
"Idle time (in seconds) to trigger cross-encoder to rerank incremental search results."
|
||||||
:group 'khoj
|
:group 'khoj
|
||||||
:type 'float)
|
:type 'float)
|
||||||
|
|
||||||
(defcustom khoj--results-count 5
|
(defcustom khoj-results-count 5
|
||||||
"Number of results to get from Khoj API for each query."
|
"Number of results to get from Khoj API for each query."
|
||||||
:group 'khoj
|
:group 'khoj
|
||||||
:type 'integer)
|
:type 'integer)
|
||||||
@@ -169,15 +174,17 @@ Use `which-key` if available, else display simple message in echo area"
|
|||||||
query
|
query
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (args) (format
|
(lambda (args) (format
|
||||||
"\n\n<h2>Score: %s Meta: %s Image: %s</h2>\n\n<a href=\"%s%s\">\n<img src=\"%s%s?%s\" width=100 height=100>\n</a>"
|
"\n\n<h2>Score: %s Meta: %s Image: %s</h2>\n\n<a href=\"%s%s\">\n<img src=\"%s%s?%s\" width=%s height=%s>\n</a>"
|
||||||
(cdr (assoc 'score args))
|
(cdr (assoc 'score args))
|
||||||
(cdr (assoc 'metadata_score args))
|
(cdr (assoc 'metadata_score args))
|
||||||
(cdr (assoc 'image_score args))
|
(cdr (assoc 'image_score args))
|
||||||
khoj--server-url
|
khoj-server-url
|
||||||
(cdr (assoc 'entry args))
|
(cdr (assoc 'entry args))
|
||||||
khoj--server-url
|
khoj-server-url
|
||||||
(cdr (assoc 'entry args))
|
(cdr (assoc 'entry args))
|
||||||
(random 10000)))
|
(random 10000)
|
||||||
|
khoj-image-width
|
||||||
|
khoj-image-height))
|
||||||
json-response)))))
|
json-response)))))
|
||||||
|
|
||||||
(defun khoj--extract-entries-as-ledger (json-response query)
|
(defun khoj--extract-entries-as-ledger (json-response query)
|
||||||
@@ -207,7 +214,7 @@ Use `which-key` if available, else display simple message in echo area"
|
|||||||
|
|
||||||
(defun khoj--get-enabled-content-types ()
|
(defun khoj--get-enabled-content-types ()
|
||||||
"Get content types enabled for search from API"
|
"Get content types enabled for search from API"
|
||||||
(let ((config-url (format "%s/config/data" khoj--server-url)))
|
(let ((config-url (format "%s/config/data" khoj-server-url)))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(url-insert-file-contents config-url)
|
(url-insert-file-contents config-url)
|
||||||
@@ -222,9 +229,8 @@ Use `which-key` if available, else display simple message in echo area"
|
|||||||
|
|
||||||
(defun khoj--construct-api-query (query search-type &optional rerank)
|
(defun khoj--construct-api-query (query search-type &optional rerank)
|
||||||
(let ((rerank (or rerank "false"))
|
(let ((rerank (or rerank "false"))
|
||||||
(results-count (or khoj--results-count 5))
|
|
||||||
(encoded-query (url-hexify-string query)))
|
(encoded-query (url-hexify-string query)))
|
||||||
(format "%s/search?q=%s&t=%s&r=%s&n=%s" khoj--server-url encoded-query search-type rerank results-count)))
|
(format "%s/search?q=%s&t=%s&r=%s&n=%s" khoj-server-url encoded-query search-type rerank khoj-results-count)))
|
||||||
|
|
||||||
(defun khoj--query-api-and-render-results (query search-type query-url buffer-name)
|
(defun khoj--query-api-and-render-results (query search-type query-url buffer-name)
|
||||||
;; get json response from api
|
;; get json response from api
|
||||||
@@ -279,7 +285,7 @@ Use `which-key` if available, else display simple message in echo area"
|
|||||||
"Delete all network connections to khoj server"
|
"Delete all network connections to khoj server"
|
||||||
(dolist (proc (process-list))
|
(dolist (proc (process-list))
|
||||||
(let ((proc-buf (buffer-name (process-buffer proc)))
|
(let ((proc-buf (buffer-name (process-buffer proc)))
|
||||||
(khoj-network-proc-buf (string-join (split-string khoj--server-url "://") " ")))
|
(khoj-network-proc-buf (string-join (split-string khoj-server-url "://") " ")))
|
||||||
(when (string-match (format "%s" khoj-network-proc-buf) proc-buf)
|
(when (string-match (format "%s" khoj-network-proc-buf) proc-buf)
|
||||||
(delete-process proc)))))
|
(delete-process proc)))))
|
||||||
|
|
||||||
@@ -309,8 +315,8 @@ Use `which-key` if available, else display simple message in echo area"
|
|||||||
(let* ((khoj-buffer-name (get-buffer-create khoj--buffer-name)))
|
(let* ((khoj-buffer-name (get-buffer-create khoj--buffer-name)))
|
||||||
;; set khoj search type to last used or based on current buffer
|
;; set khoj search type to last used or based on current buffer
|
||||||
(setq khoj--search-type (or khoj--search-type (khoj--buffer-name-to-search-type (buffer-name))))
|
(setq khoj--search-type (or khoj--search-type (khoj--buffer-name-to-search-type (buffer-name))))
|
||||||
;; setup rerank to improve results once user idle for KHOJ--RERANK-AFTER-IDLE-TIME seconds
|
;; setup rerank to improve results once user idle for KHOJ-RERANK-AFTER-IDLE-TIME seconds
|
||||||
(setq khoj--rerank-timer (run-with-idle-timer khoj--rerank-after-idle-time t 'khoj--incremental-search t))
|
(setq khoj--rerank-timer (run-with-idle-timer khoj-rerank-after-idle-time t 'khoj--incremental-search t))
|
||||||
;; switch to khoj results buffer
|
;; switch to khoj results buffer
|
||||||
(switch-to-buffer khoj-buffer-name)
|
(switch-to-buffer khoj-buffer-name)
|
||||||
;; open and setup minibuffer for incremental search
|
;; open and setup minibuffer for incremental search
|
||||||
|
|||||||
@@ -69,10 +69,12 @@ def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None, r: Opti
|
|||||||
print(f'No query param (q) passed in API call to initiate search')
|
print(f'No query param (q) passed in API call to initiate search')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
# initialize variables
|
||||||
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
||||||
user_query = q
|
user_query = q
|
||||||
results_count = n
|
results_count = n
|
||||||
results = {}
|
results = {}
|
||||||
|
query_start, query_end, collate_start, collate_end = None, None, None, None
|
||||||
|
|
||||||
if (t == SearchType.Org or t == None) and model.orgmode_search:
|
if (t == SearchType.Org or t == None) and model.orgmode_search:
|
||||||
# query org-mode notes
|
# query org-mode notes
|
||||||
@@ -136,8 +138,10 @@ def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None, r: Opti
|
|||||||
collate_end = time.time()
|
collate_end = time.time()
|
||||||
|
|
||||||
if verbose > 1:
|
if verbose > 1:
|
||||||
print(f"Query took {query_end - query_start:.3f} seconds")
|
if query_start and query_end:
|
||||||
print(f"Collating results took {collate_end - collate_start:.3f} seconds")
|
print(f"Query took {query_end - query_start:.3f} seconds")
|
||||||
|
if collate_start and collate_end:
|
||||||
|
print(f"Collating results took {collate_end - collate_start:.3f} seconds")
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user