Spaces:
Sleeping
Sleeping
Update services/search.py
Browse files- services/search.py +151 -76
services/search.py
CHANGED
|
@@ -25,7 +25,7 @@ from qdrant_client.models import (
|
|
| 25 |
Modifier
|
| 26 |
)
|
| 27 |
from sentence_transformers import SentenceTransformer
|
| 28 |
-
from fastembed import SparseTextEmbedding
|
| 29 |
import uuid
|
| 30 |
|
| 31 |
load_dotenv()
|
|
@@ -38,7 +38,8 @@ TRUSTED_DOMAINS = [
|
|
| 38 |
|
| 39 |
class LiveWebSearcher:
|
| 40 |
def __init__(self):
|
| 41 |
-
self.
|
|
|
|
| 42 |
|
| 43 |
# Production Remote Qdrant configuration with local fallback
|
| 44 |
qdrant_url = os.getenv("QDRANT_URL")
|
|
@@ -51,11 +52,14 @@ class LiveWebSearcher:
|
|
| 51 |
print("π¦ Warning: QDRANT_URL or QDRANT_API_KEY missing. Booting Dual-Core Memory Engine...")
|
| 52 |
self.qdrant = QdrantClient(":memory:")
|
| 53 |
|
| 54 |
-
# Initialize Dense and
|
| 55 |
self.encoder = SentenceTransformer("all-MiniLM-L6-v2")
|
| 56 |
self.sparse_encoder = SparseTextEmbedding(model_name="Qdrant/bm25")
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
self.cache_collection = "web_cache_hybrid"
|
| 60 |
self.files_collection = "personal_files_hybrid"
|
| 61 |
|
|
@@ -71,11 +75,9 @@ class LiveWebSearcher:
|
|
| 71 |
print(f"π οΈ Creating Named Multi-Vector Collection for Hybrid Search: {collection_name}...")
|
| 72 |
self.qdrant.create_collection(
|
| 73 |
collection_name=collection_name,
|
| 74 |
-
# Dense configuration matching all-MiniLM-L6-v2 (384 dims)
|
| 75 |
vectors_config={
|
| 76 |
"dense": VectorParams(size=384, distance=Distance.COSINE)
|
| 77 |
},
|
| 78 |
-
# Sparse keyword configuration matching industrial architectures
|
| 79 |
sparse_vectors_config={
|
| 80 |
"sparse": SparseVectorParams(modifier=Modifier.IDF)
|
| 81 |
}
|
|
@@ -95,10 +97,7 @@ class LiveWebSearcher:
|
|
| 95 |
chunks = self.chunk_text(content)
|
| 96 |
points = []
|
| 97 |
for chunk in chunks:
|
| 98 |
-
# Generate Semantic Dense Vector
|
| 99 |
vector_dense = self.encoder.encode(chunk).tolist()
|
| 100 |
-
|
| 101 |
-
# Generate Lexical Sparse Vector
|
| 102 |
sparse_output = list(self.sparse_encoder.embed([chunk]))[0]
|
| 103 |
vector_sparse = SparseVector(
|
| 104 |
indices=sparse_output.indices.tolist(),
|
|
@@ -123,10 +122,9 @@ class LiveWebSearcher:
|
|
| 123 |
print(f"β
Indexed {len(points)} hybrid vectors for {filename}")
|
| 124 |
|
| 125 |
def search_personal_files(self, query: str, limit: int = 5) -> list:
|
| 126 |
-
"""
|
| 127 |
print(f"π Searching Personal Cloud (Hybrid Search) for: '{query}'")
|
| 128 |
try:
|
| 129 |
-
# Encode Query
|
| 130 |
query_dense = self.encoder.encode(query).tolist()
|
| 131 |
sparse_output = list(self.sparse_encoder.embed([query]))[0]
|
| 132 |
query_sparse = SparseVector(
|
|
@@ -134,41 +132,47 @@ class LiveWebSearcher:
|
|
| 134 |
values=sparse_output.values.tolist()
|
| 135 |
)
|
| 136 |
|
| 137 |
-
# Simultaneous keyword + semantic prefetch query fused via RRF
|
| 138 |
search_results = self.qdrant.query_points(
|
| 139 |
collection_name=self.files_collection,
|
| 140 |
prefetch=[
|
| 141 |
-
Prefetch(query=query_dense, using="dense", limit=limit *
|
| 142 |
-
Prefetch(query=query_sparse, using="sparse", limit=limit *
|
| 143 |
],
|
| 144 |
query=FusionQuery(fusion=Fusion.RRF),
|
| 145 |
-
limit=limit,
|
| 146 |
with_payload=True
|
| 147 |
).points
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
})
|
| 158 |
|
| 159 |
-
if
|
| 160 |
-
print(f"π― Personal File Hit! Retrieved {len(
|
| 161 |
-
return
|
| 162 |
|
| 163 |
except Exception as e:
|
| 164 |
print(f"β Personal search failed: {str(e)}")
|
| 165 |
return []
|
| 166 |
|
| 167 |
# --- WEB SEARCH & CACHE METHODS ---
|
| 168 |
-
def check_cache(self, query: str, limit: int = 3, threshold: float =
|
| 169 |
-
|
| 170 |
-
if not is_news: threshold = 0.75 # Adjusted for RRF score distributions
|
| 171 |
-
|
| 172 |
try:
|
| 173 |
query_dense = self.encoder.encode(query).tolist()
|
| 174 |
sparse_output = list(self.sparse_encoder.embed([query]))[0]
|
|
@@ -180,24 +184,31 @@ class LiveWebSearcher:
|
|
| 180 |
search_results = self.qdrant.query_points(
|
| 181 |
collection_name=self.cache_collection,
|
| 182 |
prefetch=[
|
| 183 |
-
Prefetch(query=query_dense, using="dense", limit=limit *
|
| 184 |
-
Prefetch(query=query_sparse, using="sparse", limit=limit *
|
| 185 |
],
|
| 186 |
query=FusionQuery(fusion=Fusion.RRF),
|
| 187 |
-
limit=limit,
|
| 188 |
with_payload=True
|
| 189 |
).points
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
cached_contexts = []
|
| 192 |
-
for
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
| 201 |
return cached_contexts
|
| 202 |
except Exception:
|
| 203 |
return []
|
|
@@ -209,7 +220,6 @@ class LiveWebSearcher:
|
|
| 209 |
for r in results:
|
| 210 |
text_to_embed = f"Query: {query} | Content: {r.get('snippet', '')}"
|
| 211 |
|
| 212 |
-
# Generate Hybrid Vectors for Cache Storage
|
| 213 |
vector_dense = self.encoder.encode(text_to_embed).tolist()
|
| 214 |
sparse_output = list(self.sparse_encoder.embed([text_to_embed]))[0]
|
| 215 |
vector_sparse = SparseVector(
|
|
@@ -236,19 +246,54 @@ class LiveWebSearcher:
|
|
| 236 |
pass
|
| 237 |
|
| 238 |
def search_web(self, query: str, limit: int = 4) -> list:
|
| 239 |
-
|
| 240 |
processed_urls = set()
|
|
|
|
| 241 |
is_news = any(k in query.lower() for k in ["news", "today", "latest", "breaking", "headlines"])
|
| 242 |
current_date_str = datetime.now().strftime("%B %d %Y")
|
| 243 |
expanded_query = f"{query} {current_date_str}" if is_news else query
|
| 244 |
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
try:
|
| 247 |
-
print(f"π [TAVILY] Executing
|
| 248 |
payload = {
|
| 249 |
-
"api_key": self.
|
|
|
|
| 250 |
"search_depth": "advanced" if is_news else "basic",
|
| 251 |
-
"max_results": limit
|
|
|
|
| 252 |
}
|
| 253 |
if is_news:
|
| 254 |
payload["days"] = 1
|
|
@@ -260,35 +305,65 @@ class LiveWebSearcher:
|
|
| 260 |
results = response.json().get("results", [])
|
| 261 |
for r in results:
|
| 262 |
res_url = r.get("url", "")
|
| 263 |
-
if res_url in processed_urls:
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
})
|
| 268 |
processed_urls.add(res_url)
|
| 269 |
-
if extracted_contexts:
|
| 270 |
-
self.save_to_cache(query, extracted_contexts)
|
| 271 |
-
return extracted_contexts
|
| 272 |
except Exception as e:
|
| 273 |
-
print(f"
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
Modifier
|
| 26 |
)
|
| 27 |
from sentence_transformers import SentenceTransformer
|
| 28 |
+
from fastembed import SparseTextEmbedding, TextReranker
|
| 29 |
import uuid
|
| 30 |
|
| 31 |
load_dotenv()
|
|
|
|
| 38 |
|
| 39 |
class LiveWebSearcher:
|
| 40 |
def __init__(self):
|
| 41 |
+
self.tavily_key = os.getenv("TAVILY_API_KEY")
|
| 42 |
+
self.serp_key = os.getenv("SERP_API_KEY")
|
| 43 |
|
| 44 |
# Production Remote Qdrant configuration with local fallback
|
| 45 |
qdrant_url = os.getenv("QDRANT_URL")
|
|
|
|
| 52 |
print("π¦ Warning: QDRANT_URL or QDRANT_API_KEY missing. Booting Dual-Core Memory Engine...")
|
| 53 |
self.qdrant = QdrantClient(":memory:")
|
| 54 |
|
| 55 |
+
# Initialize Dense, Sparse, and Reranker Models
|
| 56 |
self.encoder = SentenceTransformer("all-MiniLM-L6-v2")
|
| 57 |
self.sparse_encoder = SparseTextEmbedding(model_name="Qdrant/bm25")
|
| 58 |
|
| 59 |
+
print("π§ Loading Cross-Encoder Reranking Engine...")
|
| 60 |
+
self.reranker = TextReranker(model_name="Xenova/ms-marco-MiniLM-L-6-v2")
|
| 61 |
+
|
| 62 |
+
# Collection names
|
| 63 |
self.cache_collection = "web_cache_hybrid"
|
| 64 |
self.files_collection = "personal_files_hybrid"
|
| 65 |
|
|
|
|
| 75 |
print(f"π οΈ Creating Named Multi-Vector Collection for Hybrid Search: {collection_name}...")
|
| 76 |
self.qdrant.create_collection(
|
| 77 |
collection_name=collection_name,
|
|
|
|
| 78 |
vectors_config={
|
| 79 |
"dense": VectorParams(size=384, distance=Distance.COSINE)
|
| 80 |
},
|
|
|
|
| 81 |
sparse_vectors_config={
|
| 82 |
"sparse": SparseVectorParams(modifier=Modifier.IDF)
|
| 83 |
}
|
|
|
|
| 97 |
chunks = self.chunk_text(content)
|
| 98 |
points = []
|
| 99 |
for chunk in chunks:
|
|
|
|
| 100 |
vector_dense = self.encoder.encode(chunk).tolist()
|
|
|
|
|
|
|
| 101 |
sparse_output = list(self.sparse_encoder.embed([chunk]))[0]
|
| 102 |
vector_sparse = SparseVector(
|
| 103 |
indices=sparse_output.indices.tolist(),
|
|
|
|
| 122 |
print(f"β
Indexed {len(points)} hybrid vectors for {filename}")
|
| 123 |
|
| 124 |
def search_personal_files(self, query: str, limit: int = 5) -> list:
|
| 125 |
+
"""Retrieves candidates via Hybrid Search, then applies a deep Cross-Encoder Rerank."""
|
| 126 |
print(f"π Searching Personal Cloud (Hybrid Search) for: '{query}'")
|
| 127 |
try:
|
|
|
|
| 128 |
query_dense = self.encoder.encode(query).tolist()
|
| 129 |
sparse_output = list(self.sparse_encoder.embed([query]))[0]
|
| 130 |
query_sparse = SparseVector(
|
|
|
|
| 132 |
values=sparse_output.values.tolist()
|
| 133 |
)
|
| 134 |
|
|
|
|
| 135 |
search_results = self.qdrant.query_points(
|
| 136 |
collection_name=self.files_collection,
|
| 137 |
prefetch=[
|
| 138 |
+
Prefetch(query=query_dense, using="dense", limit=limit * 3),
|
| 139 |
+
Prefetch(query=query_sparse, using="sparse", limit=limit * 3),
|
| 140 |
],
|
| 141 |
query=FusionQuery(fusion=Fusion.RRF),
|
| 142 |
+
limit=limit * 3,
|
| 143 |
with_payload=True
|
| 144 |
).points
|
| 145 |
|
| 146 |
+
if not search_results:
|
| 147 |
+
return []
|
| 148 |
+
|
| 149 |
+
documents = [res.payload.get("snippet", "") for res in search_results]
|
| 150 |
+
|
| 151 |
+
print(f"βοΈ Reranking {len(documents)} candidates via Cross-Encoder...")
|
| 152 |
+
rerank_results = list(self.reranker.rerank(query, documents))
|
| 153 |
+
|
| 154 |
+
final_contexts = []
|
| 155 |
+
for reranked in rerank_results[:limit]:
|
| 156 |
+
original_match = search_results[reranked.result_index]
|
| 157 |
+
final_contexts.append({
|
| 158 |
+
"title": original_match.payload.get("title"),
|
| 159 |
+
"url": original_match.payload.get("url"),
|
| 160 |
+
"snippet": reranked.text,
|
| 161 |
+
"score": round(float(reranked.score), 4),
|
| 162 |
+
"source": "Personal File (Reranked)"
|
| 163 |
})
|
| 164 |
|
| 165 |
+
if final_contexts:
|
| 166 |
+
print(f"π― Personal File Hit! Retrieved {len(final_contexts)} highly relevant chunks.")
|
| 167 |
+
return final_contexts
|
| 168 |
|
| 169 |
except Exception as e:
|
| 170 |
print(f"β Personal search failed: {str(e)}")
|
| 171 |
return []
|
| 172 |
|
| 173 |
# --- WEB SEARCH & CACHE METHODS ---
|
| 174 |
+
def check_cache(self, query: str, limit: int = 3, threshold: float = -2.0) -> list:
|
| 175 |
+
"""Scans local cache with hybrid retrieval and cross-encoder sorting."""
|
|
|
|
|
|
|
| 176 |
try:
|
| 177 |
query_dense = self.encoder.encode(query).tolist()
|
| 178 |
sparse_output = list(self.sparse_encoder.embed([query]))[0]
|
|
|
|
| 184 |
search_results = self.qdrant.query_points(
|
| 185 |
collection_name=self.cache_collection,
|
| 186 |
prefetch=[
|
| 187 |
+
Prefetch(query=query_dense, using="dense", limit=limit * 3),
|
| 188 |
+
Prefetch(query=query_sparse, using="sparse", limit=limit * 3),
|
| 189 |
],
|
| 190 |
query=FusionQuery(fusion=Fusion.RRF),
|
| 191 |
+
limit=limit * 3,
|
| 192 |
with_payload=True
|
| 193 |
).points
|
| 194 |
|
| 195 |
+
if not search_results:
|
| 196 |
+
return []
|
| 197 |
+
|
| 198 |
+
documents = [res.payload.get("snippet", "") for res in search_results]
|
| 199 |
+
rerank_results = list(self.reranker.rerank(query, documents))
|
| 200 |
+
|
| 201 |
cached_contexts = []
|
| 202 |
+
for reranked in rerank_results[:limit]:
|
| 203 |
+
if reranked.score >= threshold:
|
| 204 |
+
original_match = search_results[reranked.result_index]
|
| 205 |
+
cached_contexts.append({
|
| 206 |
+
"title": original_match.payload.get("title"),
|
| 207 |
+
"url": original_match.payload.get("url"),
|
| 208 |
+
"snippet": reranked.text,
|
| 209 |
+
"score": round(float(reranked.score), 4),
|
| 210 |
+
"source": f"Cache Reranked ({original_match.payload.get('source', 'Unknown')})"
|
| 211 |
+
})
|
| 212 |
return cached_contexts
|
| 213 |
except Exception:
|
| 214 |
return []
|
|
|
|
| 220 |
for r in results:
|
| 221 |
text_to_embed = f"Query: {query} | Content: {r.get('snippet', '')}"
|
| 222 |
|
|
|
|
| 223 |
vector_dense = self.encoder.encode(text_to_embed).tolist()
|
| 224 |
sparse_output = list(self.sparse_encoder.embed([text_to_embed]))[0]
|
| 225 |
vector_sparse = SparseVector(
|
|
|
|
| 246 |
pass
|
| 247 |
|
| 248 |
def search_web(self, query: str, limit: int = 4) -> list:
|
| 249 |
+
raw_candidates = []
|
| 250 |
processed_urls = set()
|
| 251 |
+
|
| 252 |
is_news = any(k in query.lower() for k in ["news", "today", "latest", "breaking", "headlines"])
|
| 253 |
current_date_str = datetime.now().strftime("%B %d %Y")
|
| 254 |
expanded_query = f"{query} {current_date_str}" if is_news else query
|
| 255 |
|
| 256 |
+
# 1. --- SERP API ROUTE (Google Search Engine Engine) ---
|
| 257 |
+
if self.serp_key:
|
| 258 |
+
try:
|
| 259 |
+
print("π [SERP API] Querying premium Google Index engine...")
|
| 260 |
+
serp_url = "https://serpapi.com/search"
|
| 261 |
+
params = {
|
| 262 |
+
"engine": "google",
|
| 263 |
+
"q": expanded_query,
|
| 264 |
+
"api_key": self.serp_key,
|
| 265 |
+
"num": limit * 2,
|
| 266 |
+
"gl": "in",
|
| 267 |
+
"hl": "en"
|
| 268 |
+
}
|
| 269 |
+
response = requests.get(serp_url, params=params, timeout=7)
|
| 270 |
+
if response.status_code == 200:
|
| 271 |
+
results = response.json().get("organic_results", [])
|
| 272 |
+
for r in results:
|
| 273 |
+
res_url = r.get("link", "")
|
| 274 |
+
if res_url and res_url not in processed_urls:
|
| 275 |
+
if is_news and not any(dom in res_url for dom in TRUSTED_DOMAINS):
|
| 276 |
+
continue
|
| 277 |
+
raw_candidates.append({
|
| 278 |
+
"title": r.get("title", "Google Sourced Context"),
|
| 279 |
+
"url": res_url,
|
| 280 |
+
"snippet": r.get("snippet", ""),
|
| 281 |
+
"source": "SerpApi (Google)"
|
| 282 |
+
})
|
| 283 |
+
processed_urls.add(res_url)
|
| 284 |
+
except Exception as e:
|
| 285 |
+
print(f"β οΈ SerpApi retrieval encountered an issue: {str(e)}")
|
| 286 |
+
|
| 287 |
+
# 2. --- TAVILY ENGINE ROUTE ---
|
| 288 |
+
if self.tavily_key:
|
| 289 |
try:
|
| 290 |
+
print(f"π [TAVILY] Executing concurrent context pull...")
|
| 291 |
payload = {
|
| 292 |
+
"api_key": self.tavily_key,
|
| 293 |
+
"query": expanded_query,
|
| 294 |
"search_depth": "advanced" if is_news else "basic",
|
| 295 |
+
"max_results": limit * 2,
|
| 296 |
+
"topic": "news" if is_news else "general",
|
| 297 |
}
|
| 298 |
if is_news:
|
| 299 |
payload["days"] = 1
|
|
|
|
| 305 |
results = response.json().get("results", [])
|
| 306 |
for r in results:
|
| 307 |
res_url = r.get("url", "")
|
| 308 |
+
if res_url and res_url not in processed_urls:
|
| 309 |
+
raw_candidates.append({
|
| 310 |
+
"title": r.get("title", "Verified News Output"),
|
| 311 |
+
"url": res_url,
|
| 312 |
+
"snippet": r.get("content", ""),
|
| 313 |
+
"source": "Tavily"
|
| 314 |
+
})
|
| 315 |
+
processed_urls.add(res_url)
|
| 316 |
+
except Exception as e:
|
| 317 |
+
print(f"β οΈ Tavily failed: {str(e)}")
|
| 318 |
+
|
| 319 |
+
# 3. --- DUCKDUCKGO BACKEND FALLBACK (Triggered if active routes yielded insufficient content) ---
|
| 320 |
+
if len(raw_candidates) < limit:
|
| 321 |
+
print(f"π [DDG FALLBACK] Augmenting search pool...")
|
| 322 |
+
try:
|
| 323 |
+
ddgs = DDGS()
|
| 324 |
+
timelimit = "d" if is_news else None
|
| 325 |
+
ddg_results = list(ddgs.text(expanded_query, max_results=limit * 2, backend="lite", timelimit=timelimit))
|
| 326 |
+
for r in ddg_results:
|
| 327 |
+
res_url = r.get("href", "")
|
| 328 |
+
if res_url and res_url not in processed_urls:
|
| 329 |
+
if is_news and not any(dom in res_url for dom in TRUSTED_DOMAINS):
|
| 330 |
+
continue
|
| 331 |
+
raw_candidates.append({
|
| 332 |
+
"title": r.get("title", "DDG Verified Source"),
|
| 333 |
+
"url": res_url,
|
| 334 |
+
"snippet": r.get("body", ""),
|
| 335 |
+
"source": "DDG"
|
| 336 |
})
|
| 337 |
processed_urls.add(res_url)
|
|
|
|
|
|
|
|
|
|
| 338 |
except Exception as e:
|
| 339 |
+
print(f"β DuckDuckGo fallback failed: {str(e)}")
|
| 340 |
|
| 341 |
+
# 4. --- CROSS-ENCODER DEEP RERANKING & FILTERING SYSTEM ---
|
| 342 |
+
if raw_candidates:
|
| 343 |
+
try:
|
| 344 |
+
documents = [c["snippet"] for c in raw_candidates if c["snippet"].strip()]
|
| 345 |
+
if not documents:
|
| 346 |
+
return raw_candidates[:limit]
|
| 347 |
+
|
| 348 |
+
print(f"βοΈ Reranking {len(documents)} pooled Web candidates via Cross-Encoder...")
|
| 349 |
+
rerank_results = list(self.reranker.rerank(query, documents))
|
| 350 |
+
|
| 351 |
+
final_web_results = []
|
| 352 |
+
for reranked in rerank_results[:limit]:
|
| 353 |
+
original_match = raw_candidates[reranked.result_index]
|
| 354 |
+
final_web_results.append({
|
| 355 |
+
"title": original_match["title"],
|
| 356 |
+
"url": original_match["url"],
|
| 357 |
+
"snippet": reranked.text,
|
| 358 |
+
"score": round(float(reranked.score), 4),
|
| 359 |
+
"source": f"{original_match['source']} (Reranked)"
|
| 360 |
+
})
|
| 361 |
+
|
| 362 |
+
self.save_to_cache(query, final_web_results)
|
| 363 |
+
return final_web_results
|
| 364 |
+
except Exception as e:
|
| 365 |
+
print(f"β οΈ Web Reranking failed, returning top raw results: {e}")
|
| 366 |
+
self.save_to_cache(query, raw_candidates[:limit])
|
| 367 |
+
return raw_candidates[:limit]
|
| 368 |
+
|
| 369 |
+
return raw_candidates[:limit]
|