Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the actual query count for combined search #5

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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