Handle filter only queries. Short-circuit and return filtered results

- For queries with only filters in them short-circuit and return
  filtered results. No need to run semantic search, re-ranking.
- Add client test for filter only query and quote query in client tests
This commit is contained in:
Debanjum Singh Solanky
2022-09-12 16:42:41 +03:00
parent afc84de234
commit 1bfe9c4ef2
2 changed files with 29 additions and 5 deletions

View File

@@ -112,6 +112,11 @@ def query(raw_query: str, model: TextSearchModel, rank_results=False):
if entries is None or len(entries) == 0:
return [], []
# If query only had filters it'll be empty now. So short-circuit and return results.
if query.strip() == "":
hits = [{"corpus_id": id, "score": 1.0} for id, _ in enumerate(entries)]
return hits, entries
# Encode the query using the bi-encoder
start = time.time()
question_embedding = model.bi_encoder.encode([query], convert_to_tensor=True, device=state.device)