manu commited on
Commit
e0694d7
·
verified ·
1 Parent(s): 384ff8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -154,15 +154,7 @@ def search(query: str, k: int = 5) -> List[int]:
154
  top_k_indices = scores[0].topk(k).indices.tolist()
155
  print("[search]", query, top_k_indices)
156
 
157
- # Neighbor expansion for context
158
- base = set(top_k_indices)
159
- expanded = set(base)
160
- for i in base:
161
- expanded.add(i - 1)
162
- expanded.add(i + 1)
163
- expanded = {i for i in expanded if 0 <= i < len(images)}
164
-
165
- return sorted(expanded)
166
 
167
 
168
  def _build_image_parts_from_indices(indices: List[int]) -> List[Dict[str, Any]]:
@@ -189,7 +181,7 @@ Act iteratively:
189
  1) Split the user question into 1–4 focused sub-queries. Subqueries should be asked as natural language questions in the english language, not just keywords.
190
  2) For each sub-query, call mcp_test_search (k=5 by default; increase to up to 10 if you need to go deep).
191
  3) You will receive the output of mcp_test_search as a list of indices corresponding to page numbers. Print them out and stop generating. You will be fed the corresponding pages as images in a follow-up message.
192
- 3) Stop early when confident; otherwise refine and repeat, running new searches. Up to 4 iterations and 20 searches in total. If info is missing, try to continue searching using new keywords and queries.
193
 
194
  Workflow:
195
  • Use ONLY the provided images for grounding and cite as (p.<page>).
@@ -369,7 +361,7 @@ def stream_agent(question: str,
369
  return
370
 
371
  # Controller: iterate rounds; if the model searched, attach those pages next
372
- max_rounds = 3
373
  round_idx = 1
374
  pending_indices = list(seed_indices)
375
 
@@ -381,7 +373,14 @@ def stream_agent(question: str,
381
  # If the model returned indices via the tool, use them in a fresh call
382
  next_indices = round_state.get("last_search_indices") or []
383
  if next_indices:
384
- pending_indices = next_indices
 
 
 
 
 
 
 
385
  round_idx += 1
386
  continue
387
 
 
154
  top_k_indices = scores[0].topk(k).indices.tolist()
155
  print("[search]", query, top_k_indices)
156
 
157
+ return top_k_indices
 
 
 
 
 
 
 
 
158
 
159
 
160
  def _build_image_parts_from_indices(indices: List[int]) -> List[Dict[str, Any]]:
 
181
  1) Split the user question into 1–4 focused sub-queries. Subqueries should be asked as natural language questions in the english language, not just keywords.
182
  2) For each sub-query, call mcp_test_search (k=5 by default; increase to up to 10 if you need to go deep).
183
  3) You will receive the output of mcp_test_search as a list of indices corresponding to page numbers. Print them out and stop generating. You will be fed the corresponding pages as images in a follow-up message.
184
+ 3) Stop early when confident; otherwise refine and repeat, running new searches. Up to 5 iterations and 20 searches in total. If info is missing, try to continue searching using new keywords and queries.
185
 
186
  Workflow:
187
  • Use ONLY the provided images for grounding and cite as (p.<page>).
 
361
  return
362
 
363
  # Controller: iterate rounds; if the model searched, attach those pages next
364
+ max_rounds = 5
365
  round_idx = 1
366
  pending_indices = list(seed_indices)
367
 
 
373
  # If the model returned indices via the tool, use them in a fresh call
374
  next_indices = round_state.get("last_search_indices") or []
375
  if next_indices:
376
+ # Neighbor expansion for context
377
+ base = set(next_indices)
378
+ expanded = set(base)
379
+ for i in base:
380
+ expanded.add(i - 1)
381
+ expanded.add(i + 1)
382
+ expanded = {i for i in expanded if 0 <= i < len(images)}
383
+ pending_indices = sorted(expanded)
384
  round_idx += 1
385
  continue
386