summaryrefslogtreecommitdiff
path: root/backend/app/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/app/main.py')
-rw-r--r--backend/app/main.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/backend/app/main.py b/backend/app/main.py
index be30333..a5f16af 100644
--- a/backend/app/main.py
+++ b/backend/app/main.py
@@ -715,28 +715,33 @@ async def prepare_openai_vector_search(
Returns (vector_store_ids, openai_file_refs_for_debug, filters).
Filtering logic:
- - If scopes provided: find files whose scopes intersect with requested scopes
- - If only attached_ids: use those specific files
+ - Include files whose scopes intersect with requested scopes
+ - ALSO include explicitly attached files (attached_ids)
+ - Deduplicate to avoid double-processing
- Filters are constructed using file_id attribute in vector store
"""
items = load_files_index(user)
items_map = {item.id: item for item in items}
- # Determine which files to include based on scopes or attached_ids
- relevant_files: List[FileMeta] = []
+ # Determine which files to include - combine scopes AND attached_ids
+ relevant_files_map: dict[str, FileMeta] = {}
+ # First: add files matching scopes
if scopes:
- # Find files whose scopes intersect with requested scopes
for item in items:
if item.scopes and any(s in scopes for s in item.scopes):
- relevant_files.append(item)
- print(f"[file_search] scopes={scopes} matched_files={[f.name for f in relevant_files]}")
- elif attached_ids:
- # Fallback: use explicitly attached files
+ relevant_files_map[item.id] = item
+ print(f"[file_search] scopes={scopes} matched_files={[f.name for f in relevant_files_map.values()]}")
+
+ # Second: also add explicitly attached files (they should always be searchable)
+ if attached_ids:
for fid in attached_ids:
meta = items_map.get(fid)
- if meta:
- relevant_files.append(meta)
+ if meta and fid not in relevant_files_map:
+ relevant_files_map[fid] = meta
+ print(f"[file_search] adding explicitly attached file: {meta.name}")
+
+ relevant_files = list(relevant_files_map.values())
if not relevant_files:
return [], [], None