Consistently use "entry", "score" in json response for all search types

- Had already made some progress on this earlier by updating the image
  search responses. But needed to update the text search responses to
  use lowercase entry and score

- Update khoj.el to consume the updated json response keys for text
  search
This commit is contained in:
Debanjum Singh Solanky 2022-07-20 20:33:27 +04:00
parent d68a9dc445
commit c1369233db
6 changed files with 11 additions and 11 deletions

View file

@ -55,7 +55,7 @@
(format "* %s\n%s"
query
(mapcar
(lambda (args) (format "%s" (cdr (assoc 'Entry args))))
(lambda (args) (format "%s" (cdr (assoc 'entry args))))
json-response))))
(defun khoj--extract-entries-as-images (json-response query)
@ -94,7 +94,7 @@
query
(mapcar
(lambda (args)
(format "%s\n\n" (cdr (assoc 'Entry args))))
(format "%s\n\n" (cdr (assoc 'entry args))))
json-response)))))
(defun khoj--buffer-name-to-search-type (buffer-name)

View file

@ -145,7 +145,7 @@ def chat(q: str):
if get_from_dict(metadata, "intent", "memory-type") == "notes":
query = get_from_dict(metadata, "intent", "query")
result_list = search(query, n=1, t=SearchType.Notes)
collated_result = "\n".join([item["Entry"] for item in result_list])
collated_result = "\n".join([item["entry"] for item in result_list])
if verbose > 1:
print(f'Semantically Similar Notes:\n{collated_result}')
gpt_response = summarize(collated_result, summary_type="notes", user_query=q, api_key=processor_config.conversation.openai_api_key)

View file

@ -151,8 +151,8 @@ def render_results(hits, entries, count=5, display_biencoder_results=False):
def collate_results(hits, entries, count=5):
return [
{
"Entry": entries[hit['corpus_id']]['raw'],
"Score": f"{hit['cross-score']:.3f}"
"entry": entries[hit['corpus_id']]['raw'],
"score": f"{hit['cross-score']:.3f}"
}
for hit
in hits[0:count]]

View file

@ -115,8 +115,8 @@ def render_results(hits, entries, count=5, display_biencoder_results=False):
def collate_results(hits, entries, count=5):
return [
{
"Entry": entries[hit['corpus_id']]['raw'],
"Score": f"{hit['cross-score']:.3f}"
"entry": entries[hit['corpus_id']]['raw'],
"score": f"{hit['cross-score']:.3f}"
}
for hit
in hits[0:count]]

View file

@ -37,7 +37,7 @@ def test_asymmetric_search(content_config: ContentConfig, search_config: SearchC
# Assert
# Actual_data should contain "Khoj via Emacs" entry
search_result = results[0]["Entry"]
search_result = results[0]["entry"]
assert "git clone" in search_result

View file

@ -124,7 +124,7 @@ def test_notes_search(content_config: ContentConfig, search_config: SearchConfig
# Assert
assert response.status_code == 200
# assert actual_data contains "Khoj via Emacs" entry
search_result = response.json()[0]["Entry"]
search_result = response.json()[0]["entry"]
assert "git clone" in search_result
@ -140,7 +140,7 @@ def test_notes_search_with_include_filter(content_config: ContentConfig, search_
# Assert
assert response.status_code == 200
# assert actual_data contains explicitly included word "Emacs"
search_result = response.json()[0]["Entry"]
search_result = response.json()[0]["entry"]
assert "Emacs" in search_result
@ -156,5 +156,5 @@ def test_notes_search_with_exclude_filter(content_config: ContentConfig, search_
# Assert
assert response.status_code == 200
# assert actual_data does not contains explicitly excluded word "Emacs"
search_result = response.json()[0]["Entry"]
search_result = response.json()[0]["entry"]
assert "clone" not in search_result