1 commited on
Commit
f4e7319
·
1 Parent(s): 4f4c325

Add duplicate file detection; show skip message in UI

Browse files
Files changed (2) hide show
  1. app.py +4 -1
  2. rag_system.py +9 -0
app.py CHANGED
@@ -57,7 +57,10 @@ def index_pdf(files, provider: str, openai_key: str) -> str:
57
  # Gradio 5 возвращает строку-путь, Gradio 4 — объект с .name
58
  tmp_path = Path(file if isinstance(file, str) else file.name)
59
  added = rag.add_documents(str(tmp_path))
60
- log_lines.append(f"✅ {tmp_path.name} — добавлено {added} чанков")
 
 
 
61
  stats = rag.get_stats()
62
  log_lines.append(f"\nВсего в базе: {stats['total_chunks']} чанков")
63
  return "\n".join(log_lines)
 
57
  # Gradio 5 возвращает строку-путь, Gradio 4 — объект с .name
58
  tmp_path = Path(file if isinstance(file, str) else file.name)
59
  added = rag.add_documents(str(tmp_path))
60
+ if added == 0:
61
+ log_lines.append(f"⏭️ {tmp_path.name} — уже в базе, пропущен")
62
+ else:
63
+ log_lines.append(f"✅ {tmp_path.name} — добавлено {added} чанков")
64
  stats = rag.get_stats()
65
  log_lines.append(f"\nВсего в базе: {stats['total_chunks']} чанков")
66
  return "\n".join(log_lines)
rag_system.py CHANGED
@@ -272,6 +272,15 @@ class RAGSystem:
272
  all_chunks: list[Document] = []
273
 
274
  for file_path in file_paths:
 
 
 
 
 
 
 
 
 
275
  print(f"[RAG] Загрузка файла: {file_path}")
276
  try:
277
  ext = Path(file_path).suffix.lower()
 
272
  all_chunks: list[Document] = []
273
 
274
  for file_path in file_paths:
275
+ fname = Path(file_path).name
276
+ # Проверка на дубликат: пропускаем, если файл уже в базе
277
+ existing = self.vectorstore._collection.get(
278
+ where={"source_file": fname}, limit=1, include=[]
279
+ )
280
+ if existing["ids"]:
281
+ print(f"[RAG] Пропуск {fname} — уже в базе.")
282
+ continue
283
+
284
  print(f"[RAG] Загрузка файла: {file_path}")
285
  try:
286
  ext = Path(file_path).suffix.lower()