Skip to content

Commit

Permalink
Optimize the actual query count for combined search
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Dec 25, 2023
1 parent 1c024cb commit 89895ca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/Controllers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async def combinedSearch(
logger.info("Combined search request received: {}", model)
result = await process_advanced_and_combined_search_query(model, basis, filter_param, paging)
calculate_and_sort_by_combined_scores(model, basis, result)
result = result[:paging.count] if len(result) > paging.count else result
return SearchApiResponse(result=result, message=f"Successfully get {len(result)} results.", query_id=uuid4())


Expand Down Expand Up @@ -147,14 +148,15 @@ async def process_advanced_and_combined_search_query(model: Union[AdvancedSearch
else:
positive_vectors = [transformers_service.get_text_vector(t) for t in model.criteria]
negative_vectors = [transformers_service.get_text_vector(t) for t in model.negative_criteria]

# In order to ensure the query effect of the combined query, modify the actual top_k
_query_top_k = min(max(30, paging.count*3), 100) if isinstance(model, CombinedSearchModel) else paging.count
result = await db_context.querySimilar(query_vector_name=db_context.getVectorByBasis(basis.basis),
positive_vectors=positive_vectors,
negative_vectors=negative_vectors,
mode=model.mode,
filter_param=filter_param,
with_vectors=True if isinstance(basis, SearchCombinedParams) else False,
top_k=paging.count,
top_k=_query_top_k,
skip=paging.skip)
return result

Expand Down

0 comments on commit 89895ca

Please sign in to comment.