mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 21:29:11 +00:00
Make filters to apply before semantic search configurable
Details -- - The filters to apply are configured for each type in the search controller - Muliple filters can be applied on the query, entries etc before search - The asymmetric query method now just applies the passed filters to the query, entries and embeddings before semantic search is performed Reason -- This abstraction will simplify adding other pre-search filters. E.g datetime filter
This commit is contained in:
@@ -94,7 +94,7 @@ def compute_embeddings(entries, bi_encoder, embeddings_file, regenerate=False, d
|
||||
return corpus_embeddings
|
||||
|
||||
|
||||
def query(raw_query: str, model: TextSearchModel, device=torch.device('cpu')):
|
||||
def query(raw_query: str, model: TextSearchModel, device=torch.device('cpu'), filters: list = []):
|
||||
"Search all notes for entries that answer the query"
|
||||
|
||||
# Copy original embeddings, entries to filter them for query
|
||||
@@ -102,8 +102,9 @@ def query(raw_query: str, model: TextSearchModel, device=torch.device('cpu')):
|
||||
corpus_embeddings = deepcopy(model.corpus_embeddings)
|
||||
entries = deepcopy(model.entries)
|
||||
|
||||
# Filter to entries that contain all required_words and no blocked_words
|
||||
query, entries, corpus_embeddings = explicit_filter(query, entries, corpus_embeddings)
|
||||
# Filter query, entries and embeddings before semantic search
|
||||
for filter in filters:
|
||||
query, entries, corpus_embeddings = filter(query, entries, corpus_embeddings)
|
||||
if entries is None or len(entries) == 0:
|
||||
return {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user