Fix query extraction in reranker integration

This commit is contained in:
Steve White 2025-02-27 17:00:59 -06:00
parent 16720d04c7
commit c40483f593
2 changed files with 15 additions and 4 deletions

View File

@ -178,13 +178,21 @@ class ResultCollector:
if not results: if not results:
return [] return []
# Get the original query from the first result (all should have the same query) # Extract the original query
query = results[0].get("query", "") # First try to get it from the first result
query = ""
for result in results:
if "query" in result:
query = result.get("query", "")
break
if not query: if not query:
# If no query is found, use a fallback approach # If no query is found, use a fallback approach
print("Warning: No query found in results. Using basic scoring instead.") print("Warning: No query found in results. Using basic scoring instead.")
return self._score_and_sort_results(results) return self._score_and_sort_results(results)
print(f"Reranking with query: {query}")
# Extract snippets for reranking # Extract snippets for reranking
snippets = [] snippets = []
for result in results: for result in results:
@ -202,7 +210,7 @@ class ResultCollector:
# Get the original result and add the new score # Get the original result and add the new score
original_result = results[item['index']] original_result = results[item['index']]
new_result = original_result.copy() new_result = original_result.copy()
new_result['relevance_score'] = item['score'] new_result['relevance_score'] = item['score'] * 10 # Scale up the score for consistency
reranked_results.append(new_result) reranked_results.append(new_result)
return reranked_results return reranked_results

View File

@ -54,9 +54,12 @@ def test_reranker():
print(f"Engine {engine} returned {len(results)} results") print(f"Engine {engine} returned {len(results)} results")
# Add the query to each result for reranking # Add the query to each result for reranking
enhanced_query = processed_query.get("enhanced_query", processed_query.get("original_query", query))
print(f"Enhanced query for reranking: {enhanced_query}")
for engine, results in search_results.items(): for engine, results in search_results.items():
for result in results: for result in results:
result["query"] = processed_query.get("enhanced_query", processed_query.get("original_query", query)) result["query"] = enhanced_query
# Process results without reranking # Process results without reranking
print("\nProcessing results without reranking...") print("\nProcessing results without reranking...")