mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Improve code comments. Do not import unused modules in asymmetric search
This commit is contained in:
parent
8cf2465e8e
commit
f3fd5ae978
1 changed files with 4 additions and 7 deletions
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
# Standard Packages
|
# Standard Packages
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
import gzip
|
import gzip
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
|
@ -80,7 +77,7 @@ def query(raw_query: str, model: TextSearchModel):
|
||||||
hits = util.semantic_search(question_embedding, model.corpus_embeddings, top_k=model.top_k)
|
hits = util.semantic_search(question_embedding, model.corpus_embeddings, top_k=model.top_k)
|
||||||
hits = hits[0] # Get the hits for the first query
|
hits = hits[0] # Get the hits for the first query
|
||||||
|
|
||||||
# Filter results using explicit filters
|
# Filter out entries that contain required words and do not contain blocked words
|
||||||
hits = explicit_filter(hits,
|
hits = explicit_filter(hits,
|
||||||
[entry[0] for entry in model.entries],
|
[entry[0] for entry in model.entries],
|
||||||
required_words,blocked_words)
|
required_words,blocked_words)
|
||||||
|
@ -95,9 +92,9 @@ def query(raw_query: str, model: TextSearchModel):
|
||||||
for idx in range(len(cross_scores)):
|
for idx in range(len(cross_scores)):
|
||||||
hits[idx]['cross-score'] = cross_scores[idx]
|
hits[idx]['cross-score'] = cross_scores[idx]
|
||||||
|
|
||||||
# Order results by cross encoder score followed by biencoder score
|
# Order results by cross-encoder score followed by bi-encoder score
|
||||||
hits.sort(key=lambda x: x['score'], reverse=True) # sort by biencoder score
|
hits.sort(key=lambda x: x['score'], reverse=True) # sort by bi-encoder score
|
||||||
hits.sort(key=lambda x: x['cross-score'], reverse=True) # sort by cross encoder score
|
hits.sort(key=lambda x: x['cross-score'], reverse=True) # sort by cross-encoder score
|
||||||
|
|
||||||
return hits
|
return hits
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue